Note for people just getting into programming of any kind.
by jmgibson1981 from LinuxQuestions.org on (#6J00T)
Specific variable names! Make it clear what they are. Not just something random!
I'm working on a Python course now. One of the tasks was to write something that can tell if a year is a leap or not. I had the code. The math was exactly matching the algorithm I found. Kept being wrong. Over and over. I was about to put my hand through the wall.
Turned out I was using the same variable to store my True/False as I was collecting my input statement. Why?
I used a for my input statement. Without thinking I just used it again for my bool. I had a all over the place without realizing it. Had I named the bool something like yesno or some such. and the input as year_input or something... I wouldn't have spent the last 30 minutes raising my blood pressure beyond acceptable limits. It would have been obvious from the start.
I'm working on a Python course now. One of the tasks was to write something that can tell if a year is a leap or not. I had the code. The math was exactly matching the algorithm I found. Kept being wrong. Over and over. I was about to put my hand through the wall.
Turned out I was using the same variable to store my True/False as I was collecting my input statement. Why?
I used a for my input statement. Without thinking I just used it again for my bool. I had a all over the place without realizing it. Had I named the bool something like yesno or some such. and the input as year_input or something... I wouldn't have spent the last 30 minutes raising my blood pressure beyond acceptable limits. It would have been obvious from the start.