I start seeing a lot of code lately, and I was in the position that I had to judge it. This experience triggered me in writing this article because it seems that not so many people are applying a set of rules when coding. This set of rules in some cases is not related to the language in wich we are working but there are also specific “rules” for specific languages.
I will start just to point out some guidelines (these are not
the only ones or the most important)
- I always try to write methods that are not exceeding 60 lines of code
- Name the variables/methods/classes as meaningful as possible
- Try to use as much as possible STL instead of custom containers
- Allocate on stack as much as possible
- When in need of a pointer try to use a smart one (preferably unique_ptr)
- When creating an interface, the usability is my primary target.
- Try to respect SOLID
- Focus on readability, if a commentary is needed is not the best option
- Do not use interleaved conditions or loops
- A method should not have more than one loop/condition
It is not hard to write clean code, is always time and pressure that makes us forget about quality and focus on results. Of course, everything should be delivered in a reasonable time, but this is not an excuse to write hard to read, hard to maintain code. If you work somewhere where quality is not important, maybe you are not in the right place.
What are your guidelines? What you consider to be important when writing code?