Code style
In this section some recommendations are given in order to make a clear and easy readable code. Try to write beautiful code! You can take a look to all of our examples as a reference. We try to keep some programming rules.
However, each programmer has his own way to write code and could not like some of the given recommendations. The purpose of this section is just to give a guideline to keep things tidy.
Comment your code.
This will help your colleagues to understand what you try to do. Also, it will help the Libelium Technical Service if they needed to analyze the code. It could even help you if you read your own code months after you created it. The recommended styles are:
or
You can even add long comments; they will clear things up:
Use English for comments.. it is the most common language! If you need to share your codes with other developers or clients in foreign countries, it is better to start in English.
Number the parts of your code.
This is basic to keep code organized and improve the legibility. The recommended style is:
Variables and constants
Variables should be lower case (upper case for 2nd, 3rd word). Use meaningful words and try to give a default value:
Constants should be upper case. Use meaningful words:
Indentation
Default indentation is 2 whitespaces (or use the key Tab). Use indentation to make code flow more visual, readable.
'if', 'while' and 'for' loops
"Sparse is better than dense". (A) is probably more readable than (B) or (C):
(A)
(B)
(C)
Always prefer explicit and sparse ways of code writing.
Last updated