Here's a distilled set of programming guidelines which I have learnt myself and suggested to others, over the course of 20 years.
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.
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.
- 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 namedx
,y
,z
, sizes of collections can beN
,M
, etc.