My First Day with Python - Initial Thoughts

While I’ve always been a bit of a perl guy I don’t want this post to be “perl has x and python doesn’t” in tone. Which is lucky really as Python has exceptions and threading as first class features where as perl has… ahem.

So after spending a chunk of today reading a python book and spending some time writing code here’s my initial short list of gripes -

  • except IOError
  • print adding newlines
  • Significance of whitespace in blocks. But not like that.
  • The lack of ++

Considering how picky I can be that’s a very short list so Python must sit well with me so far. Now, in order, I can’t help but read except IOError as ‘catch everything apart from IOError’. This one bugs me more than it should but considering how happy native exceptions in the language made me this just felt mean.

Secondly, print adding newlines. While this might seem trivial every other language I use on a daily basis has a print function that doesn’t print a newline so this feels weird. At least it’s not called say ;)

Now to the one that I’ll get no sympathy on - whitespace in blocks. First up let me say I don’t mind about the enforced indentation. I indent anyway so it’s not a big deal. I guess I’ll hit the odd case when it annoys me (probably involving heredocs) but I’ve got nothing against it. What does irk me is the lack of block delimiters - whitespace just doesn’t cut it for me.

I like my { and } delimited blocks, a nasty voice in my head is telling me to add them but just comment them out ( if x == y: # { ) but that seems very wrong. I’ve always looked at those examples in C programming books that say…

# incorrect
if ( something )
  print("All's well");
  wellness++;

# this is wrong because wellness is a separate statement
# and not part of the if

… and thought - “just add the damn braces, you’ll be back to add more code later anyway.” Now I’m learning a language that seems to want me to slip up like this. I’ll either get used to this or move to ruby.

Lastly we have the lack of ++ and –. I know the arguments, I’ve read them before. I disagree. I’ve never done anything insane with ++ and where I have used it it’s saved me typing. Can we have ++ and remove nested ternary ( ? : ) instead please?

I like Python and I think I’ll be investing more time in to learning it.