[Tutor] results not quite 100 percent yet
bhaaluu at gmail.com
Thu Feb 21 15:02:56 CET 2008
On Thu, Feb 21, 2008 at 8:49 AM, Tyler Smith <tyler.smith at mail.mcgill.ca> wrote:
> Not shorter, but definitely clearer would be to replace your magic
> numbers with variables:
> entrance = 6
> exit = 11
> death_room = 13
> Replacing each occurrence of those numbers in your code with the
> variables means you only have to make one change that propagates
> through the entire program if you change the map layout. It also
> means that if you're reading your code in a year you won't have to
> remember that '6' means something special in this context.
> I'm just a novice python programmer, but it's a good rule of thumb to
> avoid magic numbers in any language.
Your suggestion is clear and to the point. Noted.
I'm also aware of this 'rule of thumb', but simply forgot
to implement it due to being so familiar with what the
'magic numbers' mean, that I just didn't remember
to do it. But will I remember what it is six months from
now? Probably not. This is, indeed, a good rule of thumb!
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]
More information about the Tutor