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?
PingBack from http://feeds.maxblog.eu/item_623557.html
I can only recognize from my experience of VS that entering the same amount of code while typing only half as much is a good thing.
But it is the answer to too much indulgent a question.
To be more accurate, the initial sentence should be "There is so much you have to read which does not have value".
Typing is just the way you enter the code: it is important, of course, all UI issues are. But, when talking about the language, the verbosity is an issue when you try to read the code, not write it.
Verbose is bad. Verbose is garbage filling up my brain's limited capacity.
PingBack from http://besteyecreamsite.info/story.php?id=1550
Yes I agree that readability of code is important, but come on! look at this PHP example
$socket = fsockopen("22.214.171.124","12345",$errno,$errstring,30); //this is readable and easy to comprehend
One line and I have a socket and can do whatever the hell I please with it. Can you do the same in one line in C#? No! You would first need to plug both ip and port elements of above fsockopen in their own classes and in case of ip you need to plug it into a class and then into yet another class before that information is usable in socket class. The hell? example from xamarin:
Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //make socket
IPAddress ipAddress = Dns.Resolve( Dns.GetHostName("126.96.36.199") ).AddressList; //find IP addres
IPEndPoint ipEndpoint = new IPEndPoint(ipAddress, 12345); //add port to IP address
listenSocket.Bind(ipEndpoint); //make usable socket
I'm not saying here that PHP is better I'm just saying that the same information can be coded as much more readable form using fewer keystrokes, and as an argument against what was presented in the article.
Again I'm all for Readability but there is a difference between Readability and Clutter. And think about it this way "The more elements you have the more elements are there to fail"