[Tutor] results not quite 100 percent yet

Tyler Smith tyler.smith at mail.mcgill.ca
Thu Feb 21 14:49:12 CET 2008


On 2008-02-21, bhaaluu <bhaaluu at gmail.com> wrote:
> On Thu, Feb 21, 2008 at 7:32 AM, Kent Johnson <kent37 at tds.net> wrote:
>>
>>  > Other beginning programers shouldn't have any problems using
>>  > these routines.
>>
>>  As long as they use the same number of rooms and entrance and exit
>>  rooms, or they know the places to make the magic edits...
>>
>>  Kent
>>
>
>
> What? You show me what you're talking about, and I'll run it through my
> test script. Your 'clarity' solution should be easily dropped in to replace
> the two routines that already work 100% of the time already.
> Python please.
> The reorganization should be for 'clarity' (a Noob should be able to understand
> it, and port it easily to other games that have more or less rooms
> [will they have
> to make any magic edits anywhere]. Oh, and these clarity routines should be
> shorter (in length?).

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. 

Tyler




More information about the Tutor mailing list