declaration of variables?
Mark Charsley
mark.charsley at REMOVE_THIS.radioscape.com
Wed Feb 19 06:51:00 EST 2003
More information about the Python-list mailing list
Wed Feb 19 06:51:00 EST 2003
- Previous message (by thread): declaration of variables?
- Next message (by thread): declaration of variables?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <b2r14h02bfp at enews1.newsguy.com>, aleaxit at yahoo.com (Alex Martelli) wrote: > Rather, consider a hypothetical language where I have to declare ALL > variables AND constants I'll be using later on: > > variables x, y, z, y > constants 23, 34, 45, 56 > ... > x = 23 According to _all_ coding standards I've ever seen, that's exactly what one should do. Instead of littering ones code with magic numbers, one should create manifest constants in one (and only one) location, and then use the constants in one's code. What is that 23? What happens if the errorcode/structure-size/ flag-combination/colour-code/whatever changes? How do you know if you've corrected it in all the right places, and not changed a 23 somewhere else in the code that signifies something different. and most importantly, how is a reader of the code meant to know why you've chosen 23 (and the comment I once saw "used -1 and 7 because they work better than 1 and 9" is not a good enough answer). Having once had to debug a curses based system which consisted of hundreds of lines of about half of which were along the lines of val = GetField(35); or SetField(18, val); I'm firmly of the opinion that the only magic numbers that should appear in one's code are 0, and, at a push, 1. Mark
- Previous message (by thread): declaration of variables?
- Next message (by thread): declaration of variables?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list