Archive for the ‘Best Coding Practices’ Category
Applying the Pareto Principle in Coding
The Pareto principle (also known as the 80-20 rule, Haddad’s Theorem, the law of the vital few and the principle of factor sparsity) states that, for many events, 80% of the effects come from 20% of the causes. (http://en.wikipedia.org/wiki/Pareto_principle)
In programming this translates to, avoiding 20% of the bugs when writing code will reduce the effects of horrible bugs by 80%.
Less code = less bugs, no code = no bugs ? LOL
Best Coding Practices List
These are some of the things that I learned from the talks made by our lead programmer Travis Low.
- If you find it too cumbersome to use very long variables, it’s ok to use shorthands or abbreviations but remember to refactor them later.
- Don’t use variables for multiple purposes.
- Avoid ifs.
- Use existing code .
- Publish code up into API/superclass. Generalize to allow future changes. E.g. wrappers, etc.
- Less code, less bugs.
- Think ahead. Provide blank method definitions for very common methods or procedures. E.g. checkForm() Similarly, if you expect to use a parameter in the future, include it beforehand.
- If you’re as smart as you can be, how can you debug it? Don’t try to put very fancy/technical codes because if something goes wrong in that code, you won’t be able to debug it.
- Be forgiving in your code, do not try to fix some data which will cause the system to break… instead try to correct the problem as you go or when instantiating
- Make someone want to use your code
- Don’t use double negatives when naming booleans.