This post was written during my trip through Iceland and published much latern than it was written.
While we heavily focused on the code-surrounding things in the last parts, we will return to focus on code-related things from here on.
This article discusses code verbosity and how it can improve your open source code and also your contributors experience a lot.
What is code verbosity
Code verbosity is mainly explicitness of code. For example, in Java you have to be more explicit when declaring a variable than in (recent) C++ or even Ruby:
String s = someFunctionCall(param); // Java auto s = someFunctionCall(param); // C++ s = someFunctionCall param # Ruby
So code verbosity is how explicit you have to state certain things so that the compiler or interpreter understands your intention.
Because we do not always tell the compiler or interpreter what we want to do exactly and because we want to re-use functionality, we introduced abstractions. So abstractions are a way to make code less verbose, in some ways.
How to make code less verbose
Abstraction. It is as simple as this. You introduce abstraction to
minimize repetition which leads to less verbose code. Of course, you
cannot always make the code less verbose if the language does not allow
it: in the above example we used the
auto keyword for specifying the
type in C++, which is nice, but not possible in Java. So in the borders
of your languages abilities, you can make code less verbose.
If you do that right and the abstractions results in nice code, you know that you’ve done fine.
How much is too much
But there can also be too much abstraction which then yields unreadable code. Not unreadable as in clustered with stuff but just too abstract to grasp at first sight.
Abstraction can get too much. So make sure you introduce sensible abstractions, abstractions that can be combined nicely and of course one can step around the abstractions and use the core functionality, the not-abstracted things beneath.
As a sidenote: sometimes it makes sense to hide certain things completely or even introducing several layers of abstractions.
This was a rather short one, I guess. The next article will be longer I hope, as it will be about typing.