Verbose code is one that needs more words, or longer words, than necessary to properly express the intent of the code.
In verbose codes there are many very long symbols or symbols.
There is a current that says that if the code is as close to natural language as possible to human it will be readable. If this were true the languages today would tend to this more and more and COBOL would still be very successful for new projects.
There’s another current that says the code is more readable if it’s shorter, if you can put more understandable code in the same field of view. I can’t locate it, but there are studies that indicate it, and it goes for something, not just programming.
It should be obvious that if you have distractions along the code, if you have too much information, or if the code gets mnemonic (encrypted) too much by trying to shorten it as much as it gives, it is not readable. You have to have the right commitment that gives the most appropriate expression to whatever you do.
In some cases writing too much can even pass the initial impression of ambiguity. There are cases that encourage writing a code one way when there would fit another style.
Programming languages should always encourage the writing of the shortest possible code that is easily understandable, especially in situations where concepts end up merging.
Example of the question
Why write function() { return 42; }
when you can only write () => 42
?
This is especially useful in cases where the function is passed as an argument from another function. It gets confusing to have a function within an argument, it gets too long to read and there is no gain.
We use conventions to indicate more compact and possibly concise the same thing. So delete: the word function
which is not necessary in this context; and return
because the idea is that this form is very simple, that it has only one line and is already a return always, and that because it has only one line, it does not need the ;
, and also keys are not required for the same reason. But we added =>
to make unambiguous and show that the intention is this.
Shortcode
Do not confuse concise (non-verbose) code with the shortest possible code. It will not abuse variables of a letter, to join everything in one line, cut spaces, etc. just to seem shorter, that is to cut the meat and not the fat of the code. The ideal is to write Internet code, that is, clean. If you stack everything up, it is not clean.
It is understood that a mathematical notation is as expressive as a natural language notation if it is to express a concept that will be widely used, and because it is shorter, succinct, which goes straight to the point, it is easier to read. Of course first one has to learn that notation, but that’s the easy part of learning to program.
What does not work is to force the programmer to learn a new notation for each code base he will move. In each language it does. Even the majority copies the others, so it is rare someone invents something very new, and in general brings what is already used in mathematics.
Less verbose code should always be clearer and readable, not the other way around.
Example to see how easy it is to read:
var array = [1, 2, 3];
var quadrados = array.map(x => x * x);
var quadrados2 = array.map(function(x) { return x * x });
I put in the Github for future reference.
Clear-cut that those who do not know the notation of the former may not understand, but it is a temporary deficiency of it, learnt, it is easier to read the code.
Verbose languages
Some languages are more verbose than others. They prefer words to symbols. They prefer to be more explicit than implicit (and there is a case that is better). They prefer commonly used names that are long because it sounds more natural. Some adopt a style or paradigm that preaches more ceremony and requires things that are of little use in most cases to benefit the rare cases.
Javascript was never very verbose, but it was a bit, now it’s modernizing to be even less. Coffeescript is a language that runs on top of JS that has as its main feature to be rather verbose. Some find it exaggerated. When exaggeration begins to give room for mistakes or illegibility. There is something that seems exaggerated, but has a function to be there.
Related: What is Boilerplate code?
– rray