So I now work in
Python shop.
I'm a Perl weenie from way back, and I've been meaning to learn Python for a
while now, mainly because all the cool people were writing all the cool
back-end stuff in Debian in it, and so I wasn't cool just writing Perl and
PHP (just had to get that third P under my belt).
So I bought Learning Python a
couple of years ago, and got through maybe a quarter of it before I got
distracted with Uni or something and put it down again.
Now a large part of my job involves the care and feeding of a behemoth
in-house developed system written in Python, so I have had to bite the
bullet a little more and just learn it. The entire time, I've tried my level
best to maintain an open mind about Python.
I'm starting to realise that the code-base I'm working on isn't necessarily
the best introduction to Python. It's been through two iterations, and some
of the first version has been pretty much cut and pasted into the second
version, and was originally written for a much older version of Python than
it now runs with. For example, I was always told that everything
was an object in Python, so I was little surprised to see string
being imported, and some methods being called from this module directly (I
would have expected to see this as a method of the string object instance
itself), but after reading up on things a bit more, it seems this is a
throwback to the Python 1.6 days, so is a bit of legacy code.
I can't get used to the way slices work. I find the subscripting to be
difficult to read. I've seen some code that removes the first and last
character off a string if it's a period, and the way that did it still does
my head in if I try to think about it too fast. I'm used to Java, as that's
the only really object-oriented language I've learned, and so I'm used to
the substring() method of string objects. I remember once I spent
ages trying to figure out how to get a substring out of a string in Python.
I've read Dive Into
Python
twice, and the first time I read it, I learned just enough to get myself
into trouble, and I spent forever doing dir() on string variables in an
interactive interpreter trying to find what Python called its substring
method...
I can definitely agree with the argument that Python is more maintainable
than say Perl. Perl's "more than one way to do it" mantra can lead to some
horrible horrible code that not even the author can make sense of after six
months. I bought Perl
Best Practises a little while ago because the Jacinta and Paul from
Perl Training Australia were giving it a good wrap, but I haven't actually
had time to open it yet. Python's more single-tracked one of doing things
tends to mean that the code is going to make more sense.
That said, the indentation thing is the pits. I miss curly brackets. I miss
being about hit % in vi and jump between the start and end of a block. It's
very easy to not realise when you've dropped off the end of a function
definition, and of course if you move a block of code, you have to reindent.
I don't doubt there's some funky vim stuff to deal with this, but until I
figure out what it is, relocating chunks of code is going to be a bit
tedious...
Other than that, it's not too bad. I did some serious hacking today, and got
some results, so it wasn't all bad.