Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are there tutorials on how to name variables?

as you can probably tell from my previous posts i have horrific naming conventions. do you know of any tutorials dealing with how to name stuff?

like image 813
Alex Gordon Avatar asked Nov 27 '22 22:11

Alex Gordon


2 Answers

i will recommend to check this book alt text http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/ref=sr_1_1?s=books&ie=UTF8&qid=1281129036&sr=1-1

like image 183
Amr Elgarhy Avatar answered Nov 29 '22 13:11

Amr Elgarhy


I don't think there will be any good tutorials, because there aren't any hard-and-fast rules. Here are some tips:

  • Conform to convention: Loop variables are i, j, and k; variable numbers of arguments go in *args and **kwargs; use camelCase or underscored_names.

  • Be consistent.

  • Be concise. list_of_drugs_used_in_this_program is much less clear than drugs. Similarly, you don't need to include the datatype of the variable in the name: drugs_list is redundant.

  • Don't go overboard with the underscores. I've never needed more than one. 2+ is pushing it.

  • Never ever ever use metasyntactic variables (foo, spam...) in anything but quick-and-dirty examples. method1 is also out.

But you could summarise all of that with:

Don't be silly.


Tee hee.

Variable naming conventions can often turn into a religious war, but I’m entirely confident when I declare The World’s Worst Variable Name to be:

$data

Of course it’s data! That’s what variables contain! That’s all they ever can contain. It’s like you’re packing up your belongings to move to a new house, and on the side of the box you write, in big black marker, “matter.”

http://www.oreillynet.com/onlamp/blog/2004/03/the_worlds_two_worst_variable.html

like image 36
2 revs Avatar answered Nov 29 '22 12:11

2 revs