Please Criticize My Code

Michael Hoffman cam.ac.uk at mh391.invalid
Sat Aug 20 06:23:20 EDT 2005


Ray wrote:

> Well... I'm always paranoid that I'm, you know, writing Java in Python
> :)

The biggest mistakes I see are wrapping everything in a class 
unnecessarily, or using accessor methods instead of properties (ugh, 
ugh, ugh!). CamelCasingYourVariableNames is annoyingToMe but that's 
really a stylistic choice.

> Thanks for the examples! That last one took me a while to understand. I
> like the way you approach it though (e.g.: going after clarity first
> instead of shortness).

I think that is the Pythonic way. <wink> In general, I find conciseness 
in code is not worth all that much in its own right. Although sometimes 
it can make things easier to understand, which is good. There is a 
common belief that concise code = fast code, and it is easy to 
demonstrate that this is false. See, for example, this essay: 
<http://www.python.org/doc/essays/list2str.html>

Also, if you haven't done so already, start up an interactive prompt and 
type "import this." Key to consider:

Simple is better than complex.
Complex is better than complicated.
Sparse is better than dense.
Readability counts.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.

Best regards,
-- 
Michael Hoffman



More information about the Python-list mailing list