Good Programming Practices

Kendro VillaruelKendro Villaruel wrote on 06 Mar 2013 14:19

From now on I'll be following a consistent way of coding…

Here's a brief list of everything!

Camel Notation: Will be naming variables all starting with lowercase then followed by uppercase for every next word.

Ex.
int myInt = 0;
unsigned char countdownTimer = 0;
unsigned long prevFunctionTime = 0;

Hungarian Notation: grouping variables if they refer to an LED, button, sensor, etc.

Ex.
ledRed
ledBlue
bttnPlayPause
bttnIncrement
sensePIR
 
(array index)
int idxBuffer = 0;
int indexArray = 0;

Base Type Variables: Placing has, is, been, etc. if variable is boolean (answerable by YES or NO).

Ex.
boolean hasNumber = true;
boolean isStatusEnabled = true;
boolean beenChanged = false;
boolean isPressed = true;

Constants: All letters on uppercase. Space for underscore.

Ex.
const double PI = 3.1416;
const string AUTHOR_NAME = "CAPTAIN DUANE"

Comments: Put comments on lines that needs explanation.

When in doubt on writing a comment..
Always ask yourself:
1. Will a programmer be able to understand it by skimming over.
2. Will I be able to understand it at 8AM in the morning.

If function is hard to understand, i'll write the full summary of what the function does above its header.

Have fun programming!!

Ref: http://www.youtube.com/watch?v=w-ttEG2rrDM


Start a new sub-thread

Comments: 1

Add a New Comment