Go Down

Topic: On naming variables, functions and constants (Read 1 time) previous topic - next topic

hfp777

Interesting.
Do you have a naming system as far as variables go? I often find myself struggling to find logical and organised variable names when several functions need values that are similar in purpose but should be kept as separate registers (most notably lastTimeEventOccured or table index counters)
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.

Please factor this in

majenko

How I work:

All constants that are #define'd are in capitals.

Everything else is camel case.  Don't be afraid to use long names for functions and variables.

If you don't know camel case, it's multiple words joined together where the first word is all lower case and the subsequent words have an uppercase initial letter.  That is how most Arduino functions are done.  pinMode(), digitalWrite(), convertMySignalIntoCheese() etc.

Oh, and don't be afraid to overload your functions if you have two functions that do the same job on two different variable types.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

hfp777

Hi all,

I find myself struggling naming variables, constants and functions I use.
It seems there is something like there is something going on with case depending on the type of object (variable, constant or function) but I can't quite figure it out...

I'm trying to write more readable and understandable code. Any advice?

Thanks,
I am a total amateur at electronics and all things related. I have no education in the matter other than self taught.

Please factor this in

Go Up