Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.7 KB

variables.md

File metadata and controls

39 lines (26 loc) · 1.7 KB

Use explicit variable names

Setting up variable names like 'i' or 'temp' is bad code. It hampers readability for other members of your programming team.

Programming languages support long variable names. activeCustomerName will always be better than custName

This also applies to lists and iterators. It's easy to setup a loop like so:

//javascript code
for (var i=0; i<myList.length; i++){
    //Actions to take here
}

But it's better to write it like this:

//javascript code
for (var myListIterator=0; i<myList.length; i++){
    //Actions to take here
}

Why?

  • If you want to search your code, you will have many i results
  • In languages like javascript, that don't handle variable scoping this can also lead to errors
  • If you find yourself trying to write many loops, you will lookup a better way to declare them. Languages like ruby provide many iterator functions that read better than for and while loops.

References