There were a couple of posts from Ruby folks around the Web picking up on the lost formatting for python code in my monkey-patching post, pointing out that the lost whitespace renders the program invalid, and drawing the conclusion that whitespace is evil.
Fair enough. Whitespace gone, program no longer works, bad. Agreed. Dion Almaer points out that “At least if curly-code is misformatted (which is frequent too) you can paste it into your IDE of choice and autoformat.” Also true.
The whole mandatory whitespace thing was such a turn-off for me initially that it actually prevented me from trying Python for a whole year. If they’re this fascist about whitespace, just imagine what the rest of the language must look like!
Now that I’ve used it for a little while, I must say I’m converted. Whitespace is the way to go. Here are two reasons why:
Legibility:
Programs must be written for people to read, and only incidentally for machines to execute.
– Harold Abelson and Gerald Jay Sussman.
I’m wading through a horribly badly formatted Perl program right now, and it is tremendously painful. Sure, I can auto-format, but I’ll effectively lose diff – the new version will differ from the old in every line, preventing me from cvs/svn diffing.
The better way is to force proper coding style from day one. In my old company we had a strict style guide that we forced everybody to follow, with good results. We used a variety of techniques for ensuring it was followed, starting with social pressure and ending in torture.
As an aside, the Tcl Style Guide and the Tcl C Style Guide remain the best written style guides I’ve seen to date, and the core Tcl code some of the best written code out there. Highly legible.
Python moves enforcement from a manual activity to one that’s automated in the interpreter/compiler, ensuring everybody follows the same style, making Python code universally easier to read.
If this sounds like nonsense to you, let me ask you this: do you write or allow your people to write badly formatted code?
If you don’t, then Python will not hurt or bother you. In fact, it’ll make your life easier by automatically enforcing what you manually enforce today.
If you do, stop it immediately! If your code is worth anything somebody will have to read it some day.
Brevity and Beauty:
It’s wonderful that Ruby on Rails folks are bringing the concept of beauty and elegance back in style. Beauty in code actually is important.
I contend that curly brackets, begin/end blocks, and their ilk are ugly and unnecessary. If you accept that proper style is necessary you’ll soon see that you don’t need being/end. If you don’t accept that proper style is necessary, then you don’t care about beauty. Worst, you’re making your programs unreadable.
In any case, we can all agree that a program that omits begin/end is shorter than one that doesn’t. Brevity.
…
So what about the lost spacing in that earlier post? Well, that’s a real problem. The lost spacing doesn’t just make the program unreadable – it makes it invalid, unable to be executed.
What’s the solution? I’m still looking for one. Is there a wordpress plugin that’ll allow me to maintain spacing, or better yet, highlight code? I tried every single one I could find, but none of them worked as advertised.