bhaaluu wrote:
>>  Those two block of code above are SO similar that sure they can be combined
>>  into one, or at least the first parts of them.
>>
> 
> Optimization is the LEAST of my worries at this point.

The suggested change is not an optimization for speed, it is a 
reorganization for clarity.

You should be worried about readability and maintainability at the start 
of your project, because this is code you will be living with for a while.

> What these routines DO, and DO 100% of the time
> 100% of the time!
> That's what I was looking for, and these routines do the job.

OK, so it works. Congratulations! That doesn't mean there is no room for 
improvement.

> First: get the routine to do exactly what you want it to do.

A good place to start.

> Second: Readability. I can read and understand these routines.

Good. However they are longer than necessary.

> Third: Maintainabilty: They are easy to maintain! See Second.

Duplicated code is actually a major impediment to maintainability.

> The new game has 43 rooms, not 19. These routines have already
> been ported to the new game, easily and quickly.

With a few changes I suspect - changing 19 to 43 in two places (don't 
miss one!) and probably changing 6, 11 and 13 to other numbers in two 
places as well. And what is so magic about those numbers, anyway? Will 
you remember when you come back to the code in two months?

Plus the random selection and the use of the random numbers is mixed 
together.

You could write a reusable function that selects from a range, skipping 
certain values. That function could be used as-is in multiple games, 
rather than cutting, pasting and editing a short code block for each 
game. I gave some suggestions in an earlier email that could be the 
start of such a function.

> 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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to