Date Tags Python

Hello! Well, this is my first techy blog. I've been in IT for more years than I care to remember, and I've never felt the need to write blog about it. A couple of decades covering C, C++, FoxPro (remember that??) and then Java. I've dabbled in a few small open-source contributions, but I've never felt the urge to blog about this.

So what changed?

Well, I discovered Python.

Actually that's not strictly true; I've been aware of Python for about four or five years, but as soon as I discovered that block structures were defined by indentation, I ran, leaving a me-shaped hole in the wall.

And so me and Python and kept apart, eyeing each other over the fence. A few more years, a few more languages (Ruby and Scala), and few more frameworks (Spring, Rails, Grails, Play).

I'm not saying that all of this soft tech wasn't great, but I was getting jaded. I longed for simplicity and clarity. And when you hear of simplicity and clarity, then in the next sentence you usually hear Python.

So I gave it another go; a real project this time, not just a bit of dabbling; I had a go at a real project: an Alfred workflow written in Python. After about an hour of reading and three hours programming, I realised something:

Indentations aren't weird

They actually make a lot of sense. Superfluous elements such as {} and IF . . . ENDIF are removed from your code, revealing just the structure. After working with Python for just a few minutes, semantic indents became a lot more familiar and much easier to read.

if output.startswith("Invalid"):
    wf.add_item(title=". . .", subtitle=output, valid=False, arg=args[0], icon=ICON_ERROR)
else:
    wf.add_item(title=output, subtitle="Copy to clipboard", valid=True, arg=output)

The indentation has to be consistent; if you indent by 4 spaces then all your indentation has to be based on 4 spaces (which kind of makes sense. Why would you suddenly start indenting with 3 spaces halfway through the file?). I'll admit it was a pain at first, but as I said, this was only for the first few minutes. Afterwards, I became obessessed with neatness. If the code made the indentation sink to the right side of the page, I thought 'Python! Pffft!', and then I thought '. . . or maybe I should break this down into functions to make it neater.'

Python is a better teaching language than Java

There, I said it. And look, the sky hasn't fallen. Sorry, but it's true. Java is great for teaching object-oriented fundamentals, but before a programming student reaches that, he has to understand good practices in structure and abstraction. This is where Python excels because the semantic indentation forces good structure. Why? Simply because your code will look damn ugly otherwise.

The free stuff is amazing

Yes, more libraries than you can shake a stick at, and all the free. As many as Java? I dunno, maybe. I'm just going to call out one or two of my favourites:

  • pyPeg – The best way to parse complex stuff coming in from a file or the command line

  • DateUtil – Python's standard date-handling framework is awesome enough. Adding the DateUtil framework handling any kind of date problem ridiculously easy. I mean, how many frameworks bother to tell when Easter's coming around.

And so is the online community

To be honest, I've never come across a geek pool I didn't like, but the folk who know Python really know Python, and the they're always ready to help with the dumbest questions (of which I had plenty!)


Comments

comments powered by Disqus