31 Jan 2005 lgs   » (Master)

Improving my Python skils

After reading PythonIs Not Java, a great article by the way, I realized that when I write Python code I do some things just because I have a big inertia from other languages and from what some teachers teached me and don't really think in a Python way. Here are two things I should change:

  • Don't write setters or getters until you really need to do so because they involve more logic that just setting or getting an attribute. When the time comes to do so, you have the great property() builtin to allow you to do the changes without modifying any client code

  • Write functions than return functions so a lot of code can be reused. The inner function is a template for your common problem and the outer function is just used to give some parameters to the inner one

I specially like this sentence of the article:

Essentially, if you've been using Java for a while and are new to Python, do not trust your instincts. Your instincts are tuned to Java, not Python. Take a step back, and above all, stop writing so much code.

Thanks to Phillip J. Eby for this clear explanation

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!