The 10 commandments for a programmer
There are some basic coding etiquettes which we have to follow every time we write code. The first metrics I use to distinguish a good code from a bad one. In the core engineering bootcamp, we were done rm -rf whenever we missed any etiquettes.
- No tabs, only spaces A tab is different amount of spaces depending on the environment but spaces are always one
- Indentation and spacing between code constructs Classes, methods, specs should be consistent. Indentation be based on the accepted convention for the language. Eg: 4 for Java, 2 for ruby.
- New line at EOF Git wants new line at end of each file. It gives you a warning if you don’t do so.
- Accepted naming convention for the language snake_case for variables in ruby, camelCase for variables in Java, etc
- Accepted file/directory naming for the language Different languages have different conventions. In Java, class file name should start with capital while it should be snake_case in ruby
- Use namespaces
- No comments / Unused code Why do we need comments? Make the code explain itself using specs.
- Runtime environment should be consistent with IDE We should be able to run specs and application from both IDE and command line.
- Use
.gitignore - Always do BDD One spec per commit
They just look easy to follow but following a simple checklist like this is very hard all the time and will come only by practice.
You may contact the author at me@abhinavrai.com