S0C13TY

S0C13TY

Variable Names in Computing

Who cares?

As with all computer science names, your future self will be grateful if you name your variables with informatively, and without spaces and crazy characters.

Numbers, letters, FINE - everything else... at your risk!

Good practice for Variable Names

No crazy characters

Spaces are a no-no, and most languages do not even allow spaces as they are used to separate one bit of code from another. It'll just error

Similarly, arithmetic operators are deeply unhelpful as most languages will think your hospital appropriate variable "a+e" is actually you asking for "a" to be added to "e". This is why using minus signs (e.g. nice-variable-name is ill advised)

In fact, most punctuation is used in weird ways by coding languages, or worse - part of an escape sequence - so DON'T BOTHER. Letters, numbers = Yay

Camel Case

Some folk separate multi-word variable names with _ e.g. num_camels_ridden

However, it's less characters, avoids the non-alpha-numeric underscore character, (and is generally less 90s) to simply capitalise each separate word e.g. numCamelsRidden

Note, the first letter however is always lowercase (thus it looking a bit like a camel) because initially upper case variable names are saved for OO Classes and other "important" things.

A good name

Descriptive yet as concise as possible. Too long, and you'll hate coding it. Too short and you'll hate debugging it.

theNumberOfPeopleWhoWorkHere is descriptive but probably unnecessary, especially if you know you are inside a module about working people.

numPeople is better. It makes sense within context - you know what it's storing and you won't hate yourself.