Emptiness — don’t rely on it

Looking through my old notes how I should design Skila and what pitfalls to avoid I found out a piece about whitespaces. Probably the most famous language designed to rely on whitespaces is Python. But other languages follow the trend as well — like Scala or Ruby. They seem elegant, clean, but there is a dark side when you have to read the code or worse — fix it.

For me it is surprising, because time already proved that such design leads to frustrating errors — you see something, but compiler sees something else, for example:


What do you see? Word “hello” prefixed with seven spaces, right? No, wait — eight spaces. No, wait, there is tab character in the middle — can’t you see it?

And here exactly is the problem because I cannot, yet computer can, and it will precisely wreck me just because I am not a whitespace sharpshooter.

Writing programs is demanding craft, the code is information, blueprint, whitespaces are merely a background for that blueprint — and I cannot get it how someone could rely code on something that really does not exist. Only this feature and experience with writing Python code when later I see a flood of whitespace related errors rendered this language for me as dead option.

I was kidding, there is no-breaking space in the middle, not tab.

But other languages are no better, consider this simplified Scala piece:

if (cond1())
else (cond2())

Pretty typical “if-else-if” case, the code is so trivial that I spent embarrassing part of the evening fixing it. Don’t get me wrong — it is not about finding a bug in entire program, I already pin-pointed it and I knew the bug was right here, in front of my eyes, but I looked and for me the code was flawless and compiler concurred. How can it be flawless and erroneous at the same time?

What went wrong with Scala here? When computing boundary of expressions it relies on end of the line — if EOL can end expression, compiler assumes it is the end of expression. Without this fancy feature compiler could save my time in a split of the second by demanding semicolon. Freaking single character.

And I thought that computers are made to save our, human, time. That’s why Skila comes with reliability — if it can set a safe guard, good. If the safe guard can be doubled, even better. If it can be tripled — perfect. I don’t want to hear the story about comma misplaced with dot in the 21th century.

The presented code in Skila would give you errors because of the following reasons — missing semicolon, ignored result of a function and misplaced “then” keyword which serves as condition terminator. Those guards do not limit your expressiveness, yet even drunk or dead you still couldn’t ignore compiler error.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: