Skip to content

Instantly share code, notes, and snippets.

@hrj
Last active January 6, 2019 07:12
Show Gist options
  • Save hrj/6864fe28cda172f865bb715c594fddaa to your computer and use it in GitHub Desktop.
Save hrj/6864fe28cda172f865bb715c594fddaa to your computer and use it in GitHub Desktop.
Good Practices in Programming

Here's a distilled set of programming guidelines which I have learnt myself and suggested to others, over the course of 20 years.

Meta guideline : Readability

The main focus of these guidelines is to enhance readability. Sometimes, better readability might affect performance of the code for better / worse. In such cases, my suggestion is to compromise readibility only in the critical sections of the code.

Move specific state to the smallest scope possible

The evils of globally scoped state (variables) have been well documented. This is an inductive extension of the same argument.

By limiting the scope of state we make it easier to read / analyse the system.

It might seem simple or even obvious, but I believe that this guideline lies at the heart of programming paradigms, including OOP and Functional programming.

Modern languages allow easy definitions of nested scopes, making it even more convenient to follow this guideline.

Naming matters

  • Use descriptive names wherever possible
  • It is okay to use short names for some common and small-scope labels, but it is important to maintain consistency. Most of the conventions carry over from maths. For example, counters in loops can be named i, j, k, co-ordinates can be named x, y, z, sizes of collections can be N, M, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment