This weekend I was helping out a friend when he pasted me some of the code from his latest project that happens to be written in C#:
(the only change I’ve made was to rename the identifying feature to XYZ)
namespace XYZ.Core
{
static class Entry
{
static void Main(string[] args)
{
using (Game game = new Game())
{
game.Run();
}
}
}
}
I know that monitors are getting bigger and bigger, but vertical space is still a precious commodity, so let’s try turning the above code into something that looks more like
namespace XYZ.Core
static class Entry:
static void Main(string[] args):
using (Game game = new Game())
game.Run();
This code is shorter and easier on the eyes, and I’m even ignoring the whole issue of having a class that simply has a static void main, as the authors of the cool Boo language point out, the people who came up with “public static void main” were kidding, it’s just that a few million Java/C# programmers didn’t get the joke.
For those of you that didn’t know where this was going, the above is just a few steps away from being valid Python (or for you .NET junkies perhaps Boo). Other people have addressed the myth of significant whitespace and I won’t go into great detail here, but I will say that Python essentially injects INDENT/DEDENT tokens that function in the exact same way as { and }.
What is often used as an argument against Python and other indentation-scoped languages is therefore really an advantage. {} are no more useful than the human appendix or other vestigial structures, the only reason that modern programming languages have them is that they inherited them.
If languages like Java/C# thought it was a good idea to free themselves of explicit memory management why not also free themselves of useless syntax that does nothing but clutter up code?
This divergence seems to only be growing wider, with languages like Python already free of these vestigial quirks, whereas languages like C++, Java, and C# continue to make their syntax more and more obfuscated. (eg. the tortured C++ lambda syntax)
This discussion on what syntax could be thought of as vestigial sparked some debate, some other potential candidates others suggested include the ++/– operators and PHP’s use of ->. I’d love to read comments with examples of other developers favorite vestigial syntax.
edit: A commenter over on reddit points out that the Lisp community had this right years ago. It does say something that one of the oldest languages is so free of the cruft that the traditionally more dominant curly-brace family has adopted. The idea that those who forget lisp are doomed to reinvent it is surely at work here.
Popularity: 9%


3 comments ↓
Why have any syntax at all, then? Why not just use Lisp? Or Lisp with significant white space (a “trivial” addition to the reader of almost any major Lisp).
After undertaking a medium sized project in Scheme I’ve just come to feel that syntax is higher overrated and I sort of want languages to just stop having it, or have it be optional.
The one thing that {} haters forget about is that most editors these days have intelligence built-in to help you find the closing } for a given {, or vice-versa - whereas I’ve yet to find an editor that will find the “closing dedent” for a given “indent”.
Given that whitespace is more-or-less “invisible” (I often find myself reading other people’s python and realize that I cannot consistently answer “is this code indented one level with tabs or two levels with spaces?”) - I prefer the explicit and visible syntax granted by {}’s.
The issue of matching indent/dedent would be one of code folding, which most editors have, and any serious editor supports in python. The reason for this feature however is typically that braces are a lot harder to pick out visually than indentation levels.
As far as checking how far code is indented there are two issues: 1) you seem to suggest the mixing of tabs and spaces which is a terrible idea and easy to protect against 2) it is possible to have semi-visible whitespace in most editors, or even indentation guides in editors. Such visual cues are useful even for languages like C++ or java.
Leave a Comment