|
In Unit 2, after there is adviced to use meaningful names for parameters, it goes on assigning a parameter the name s. We programmers know we usually just call s any general string parameter, but for the sake of teaching good programming practices, you shouldn't use that. |
The question has been closed for the following reason "The question is answered, right answer was accepted" by Micro-BIOS 21 Mar '12, 14:07
|
It's nice to be able to know immediately what exactly a variable represents. Even years later! I tell my math students to name the variable after the thing it represents; even in solving math problems this is useful. |
|
In 20 years of programming, I never called a string variable s. It is not meaningful and makes it hard to maintain the code in the future. That means that a variable holding a customer name would always be called cust_name or customer_name. Both approaches work though consistency is important. Single character variable names work for loop control because experienced programmers will quickly recognise that this is the intended purpose. ALways use descriptive variable names with that one exception. Be consistent in naming variables too. Both will make your code more maintainable in the long run |
|
There is a mutually-agreed-upon Python programing standard, Python Enhancement Proposals, that's been floating around the community. In particular, I think PEP8 is gaining ground. It suggests several programing standards, including variable naming, commenting, etc. If you install a program called pylint, it will go through your code and flag any thing that's not consistent with the PEP8 standard. |
|
Well... I like meaningful names, but sometimes they can get in the way. I have had to work with C code that was full of variables like IndexToTheDataItemTested, and WhereTheDataWasFound and longer. After a few minutes I felt I was going crazy. So, for a simple loop, the loop counter using "i" would make it easier to understand than a longer name, in my opinion, and has become an accepted pattern for the outermost iterator. "s" is very common for a generic string. So some balance and reason should be applied, I think. |
|
its a matter of need i think, if you've got a variable that can't be easily recognized by someone looking the code (like 'i' for the loop) its good practice to put a note at where i is initialized or assigned a value for the first time. i = 0 #this variable is to keep track of the loop to make it more easily identifiable. It cant to do that with all variables being created. It seems kind of silly with something small but its a good habit to develop because as you right code, you have to go back and look at it months or years later, or even worse, someone else has to edit it down the road) it makes reviewing the code alot easier |
|
Although there is a bit of sarcasm and hyperbole, I enjoy this classic rant on variable naming conventions. |