[Tutor] Some questions about my yen-USD.py

Andrei project5 at redrival.net
Fri Sep 8 14:46:15 CEST 2006


Dick Moores <rdm <at> rcblue.com> writes:

> Version 3 is now at http://www.rcblue.com/Python/yen-USD-v3.txt . Am 
> I done? Or will a v4 be necessary/advisable?

The original program worked fine from the user's POV and the code had lots of
good features (functions instead of monolithic code, docstrings). IMO the most
important problem of the code was the "if again" thing in the loop, which, as
you point out, is not a problem for the user (who won't hit the recursion
limit), but it is a very big conceptual issue that's prone to bite you every
time you write a function.

Beyond that, any program above 10 lines (and even many smaller ones) offers
infinite opportunities at fiddling - at some point opinions will start to differ
about the 'perfect' approach and further micro-optimizations. It's best to let
programs that are "good enough" alone and focus on new things that will give new
learning opportunities: you could write something different, or choose to extend
the program in radical new ways (e.g. automatic downloading of conversion rates,
a GUI/web interface).

> >4) Function names are important and should be chosen in such a way 
> >that they are
> >not confusing. Most of them are OK, but commas() is non-descripting
> 
> I've renamed commas() to numberCommas(). Is that descriptive enough? 
> I'm reluctant to go with even a longer name. I'll be using it a lot elsewhere.

A guideline for function names is that they should contain a (well chosen) verb
and an object. As always it ends up being a matter of personal taste. I for
example might call that function insertSeparators or formatNumber, but other
people might prefer longer names like insertSeparatorsInNumber or
prettyPrintNumber or something completely different.

Yours,

Andrei



More information about the Tutor mailing list