Playing with Python

A couple of days ago I got Python in a nutshell. I’ve been playing with Python a bit (trying to write a threaded server).

What I like:

  • Everything is an object, even functions and classes
  • Object oriented in nature, the API is a huge set of modules containing functions and classes
  • Code feels natural. If I want to print all the numbers in a certain range I can simply do that using:
  • for n in range(0,10):
     print n
  • Indenting has a purpose, in Python indenting is no longer a convention. The level of indentation determines what block you’re in, there’s no need for braces. For example, this will work:
  • for i in range(10):
     for j in range(10):
     print i, j
  • And this won’t:
  • for i in range(10):
    for j in range(10):
    print i, j
  • Extensive API, you have an amazingly large API to your disposal when using Python. There are full frameworks for easily building a threaded server and even an API that makes it very easy to make a console text-input oriented application (cmd).

What I don’t like:

  • Naming is inconsistency, always important to me. Some module names are all lowercase, some use CamelCasing. Same goes for classes and functions. Is it o.set_property(), o.SetProperty() or o.setProperty()? It differs from class to class
  • No layered IO, in Java when you want to introduce a new kind of IO class all you have implement is a read() and write() method which read and write a byte. Over those you lay an abstraction layer which can also write lines and read lines (using the read() and write() methods you supplied). No such concept is available in Python. There are ‘file-like’ objects for most streams (files, sockets) but if you want to add your own IO source, you have to code all of the file-like methods yourself.
  • Dynamically, weakly typed. You have to run the program to see if it runs without method not found errors, unknown variable errors and the such. When I compile my code with a Java/C# compiler I know no such errors exist. Another drawback of dynamically and weak typing is that IDE’s can’t supply code completion all the time, some IDE’s can do that is some cases, but never always. This decreases your productivity enormously.