Wednesday, February 4, 2009

A Space In The Right Place Saves Nine

Experienced programmers please set down any hot liquids before proceeding. The following comments are from a beginning programmer, and as such, will likely promote laughter among those who know better. That's why I'm writing this - you guys just can't regress all the way back to this level of ignorance easily :-)

The one thing everybody knows about Python is that whitespace is significant, and it's really a pain. OK, so now that I can do 'Hello World' in three - count 'em three! - different scripting languages, what do I think about Python syntax?

I just don't see why everybody thinks it's hard. To me, it's a breath of fresh air! So far, the only time I've seen that white space matters is leading whitespace to set off a block of statements.
There's no 'end' to that block except the ending of the indentation. OK, so it's something to keep in mind. On the other hand, bash's use the $ when you assign the value and not when you use it is a lot more confusing. And don't get me started on Perl. When to use a ( vs a { vs a [ is a lot harder to figure out, and $ or % or @ for variables ain't exactly simple either. Yes, Perl logically hangs together, and I get the fact that you should know which symbol to use when based on what you are trying to do, and what kind of data you are storing. I even appreciate the fact that it's a form of error checking - because if you use the wrong symbol because of a logical error it'll catch it for you.

On the other hand, in Python a variable is a variable regardless of the contents. The programmer has to keep it straight in his head rather than the syntax enforcing it. It might make things more error prone, but it sure makes it easier to read. The lack of end of line characters in particular is refreshing, unlike bash's 'you might want to use a semi-colon here - or not...

So, if you were thinking that counting spaces was a necessary evil in Python, forget it, and just try it out and see what you think!

No comments:

Post a Comment