You lucky swine… Much (possibly most) code I have had to deal with was that ugly.
I'm talking about horrors such as (this was real, production code):
bool flag = true;
if (var1 == const1)
{
if (var2 == const2)
{
// quite a lot of code
flag = false;
}
}
if (flag == true)
{
// a little piece of code.
}
Clearly, someone forgot to clean up their code. It doesn't take a Master of Succinctness to realize that if (var1 != const1 ||
var2 != const2)
{
// a little piece of code
}
else
{
// quite a lot of code
}
is much better (the code represented by the comments didn't touch the flag). Plus, such simplifications tend to compound. After a first pass, I often see more possible reductions that can be used for a second, sometimes a third pass.I'm not disagreeing on the notion that there is some shit code in the world. Of course there is. But if anyone thinks that all or most code is shit, it often says more about the speaker. And I don't mean this as a personal attack on anyone, as it is possible that someone is in particularly dire code straights, but by and large the people who I've known who think all code is shit tend to be of questionable talent.
I have a friend who is constantly regaling the horrors they meet on the roadways because, in their opinion, everyone is a shit driver. Only it's my friend who is the shit driver, and their reactionary, panicked driving technique puts them in such constant peril that they can only imagine that everyone else is to blame.
Bad driver stereotypes piss me off because they often work under the assumption that cautious drivers are bad drivers and aggressive drivers are good drivers. Hell I bet Asian women are really the safest drivers.
So, while there are ways to make code so short that it becomes incomprehensible (code golf?), most of the time, less code is almost always a good thing. A case in point would be the factorial in Haskell:
fac i = product [1..i]