[Baypiggies] Code/Idea Review (WARNING: SPOILER)

Glen Jarvis glen at glenjarvis.com
Sun Dec 16 01:20:14 CET 2007

The code reviews responses that I have received thus far have been  
good. I like choosing such a small program because we can talk ad- 
infinitum about certain decisions and why we made them. In a group  
like this, I'm certain we'll have plenty of  opinions. So, I'd like  
to open the thread to discuss each of those opinions.

Let's also organize our discussion by thread.

-- Issue #1 --
Importing sys was not necessary. This was left over chaff from when I  
was using sys.exit() while debugging early on. This was something  
that I forgot to clean-up and was a no-no - even in such a small  
program. So, the suggestion to start using pychecker or pylint will  
solve this problem. I really *should* have done this first. Thanks  
for the suggestion!

-- Issue #2 --
The best way to create a translate table (without hardcoding the  
strings). I tried using range, but wasn't using it properly. Neal's  
suggestion was very helpful:

alphabet = ''.join(chr(c) for c in range(ord('a'), ord('z') + 1))

But, what was even MORE helpful was that I have string.lowercase  
built in. Doh! This is why I asked for a review of something so  
simple. Excellent suggestion (and why I sent this email):

     re_map = string.lowercase[2:] + string.lowercase[:2]
     trans_table = string.maketrans(string.lowercase, re_map)

-- Issue #3 -- 
Whether to use a hard-coded string or not. That is, the following  
lines of code are very clear (and a good argument why they should be  

     trans_table = string.maketrans (

I intentionally avoided the above because I wanted to avoid hard- 
coded literal strings. But, once I saw how easy Dennis' suggestion  
was to read I thought.. Hmmmmmm  I like Dennis' better for code  
readability. And, the alphabet clearly fits within column 79 (even  
with spacing).

So, This issue is probably one that will start discussion. When would  
we use this style and when would we not? This would have been simpler  
for this particular task. But, what over-all 'rule' can one follow?

-- Issue #4 --
Style issues. Aaz. I personally LOVE using white-spaces. In fact, I  
naturally would have added a space before and after parenthesis.  
HOWEVER, PEP-8 is very clear about not doing this. For example:

alpha_list = [ chr(c) for c in range(ord('a'), ord('z')+1) ]
alphabet = ''.join(alpha_list)

Above, I would have included the space between the open bracket ('[')  
and the chr(c). I would also have enclose a space for before the  
closing brace.

HOWEVER, this is what PEP-8 (http://www.python.org/dev/peps/ 
pep-0008/) says about such matters though:

     Avoid extraneous whitespace in the following situations:

     - Immediately inside parentheses, brackets or braces.

       Yes: spam(ham[1], {eggs: 2})
       No:  spam( ham[ 1 ], { eggs: 2 } )

These comments are great. I've been programming for twenty-five years  
(if my Commodore-64 basic counts when I was a young waif)? Most of my  
experience is in C and C++. But, I've only been programming in Python  
for three months. And, the first is not a substitute for the second.  
I love learning and have a lot to do!

I'd like to see more discussion on issue #3 "Hardcoded string or  
not?." The rest are either obvious mistakes of mine or are clearly  

Warmest Regards,

Glen Jarvis

glen at glenjarvis.com

"You must be the change you wish to see in the world." -M. Gandhi

On Dec 15, 2007, at 12:16 PM, Aahz wrote:

> On Sat, Dec 15, 2007, Dennis Reinhardt wrote:
>> Seems correct but hard to read and understand what you are doing.   
>> How about
>> trans_table = string.maketrans (
>>     "abcdefghijklmnopqrstuvwxyz",
>>     "cdefghijklmnopqrstuvwxyzab",
>>     )
>> Ooops ... ignore the trailing ","
> Actually, *don't* ignore the trailing comma; I highly recommend  
> using one
> with multi-line value lists.  It's not particularly useful here,  
> but it
> saves a lot of work IME in other cases, and it's simply a good  
> habit to
> get into.
> -- 
> Aahz (aahz at pythoncraft.com)           <*>         http:// 
> www.pythoncraft.com/
> "Typing is cheap.  Thinking is expensive."  --Roy Smith
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies

More information about the Baypiggies mailing list