On ScottWil’s blog recently, Thomas Eyde commented on C#, saying “Basically I think C# is too static, complex and verbose. There [is] so much you have to type which does not add value.” I am admittedly biased, but I think that C#’s verboseness is a good thing.
On the face of it, being able to express the same idea in fewer lines or characters of code sounds like a useful trait in a language. But there are a couple of reasons why I don’t think this is as good of a goal as it sounds like.
The first is that far more time is spent reading code than writing it. If writing code in a particular language takes twice as many lines or characters, but this causes the reader to spend half as much time trying to understand it, the tradeoff is very likely worthwhile (since the code will be read more times than it was written). This is the same argument that is made to explain why it’s important to use descriptive variable names. Using variable names that don’t carry any connotations forces the reader to follow the entire flow of the variable through the code to understand what it represents. On the other hand, variable names that carry connotations about their meaning can help a programmer convey information about the variable, so that the reader can just read a snippet of code and have a good idea what it is doing.
The second is that tools, like intellisense, can help make the number of characters typed far less than the number of characters of code that are generated. As a simple example of this, take the following block of code:
foreach (Item<T> item in state.Items)
if (item.Index >= item.Production.Right.Count)
foreach (Terminal<T> follow in Follow(item.Production.Left))
ActionTable.Add(state, follow, new Reduce<T>(item.Production));
} (233 keystrokes)
This can be written in the Visual Studio C# editor with approximately half as many keystrokes as produced characters, by typing the following sequence of characters.
fore(It<T> item in sta.I)
f(Te<T> follow in Fol(it.P.L))
} (122 keystrokes)
Or even better, you could take advantage of code snippets, and write the same code in even fewer keystrokes (“→” represents a tab):
ActionT.A(s,follow,new Re<T>(i.P)); (107 keystrokes)
Of course, the characters typed in above are clearly unreadable, and so the presentation (and persistence) of these as the original C# program helps readability and maintenance of the code for future readers. But the end result is that in relatively few keystrokes, a programmer can create code that is verbose enough to be easy to read by the next programmer who needs to modify it. This gives a sort of “best of both worlds”, which feels like a good thing to me. What do you think?
I don’t think it’s that I haven’t had anything interesting to say for the last 7 months, but somehow I haven’t gotten around to blogging about any of it. So I’m going to try to get back on the horse and put a post up tonight. Hopefully you’ll see posts more regularly than once every 7 months going forward, but for now, here goes…