In 2020, in my country (Poland, Europe), there were about 120’000 (one hundred twenty thousands) new regulatory acts. This count do include all local bills, EU directives and regulations and all country wide legal acts.
Above one hundred thousands of new documents.
This is far, far beyond human ability to read, understand and connect all of them.
In the result there is no single person in Poland who can honestly tell: “I do know The LAW”.
Hey, shouldn’t You talk about code?
And am I not doing that? What is a law anyway? Can’t we say it is a kind of program which is run on a machine called “the society”?
For a single average Joe the law is exactly as the:
assert(!kill)
Joe can run any program, but when he hits the assertion the
throw new EGoToPrisonException("Joe")
is thrown.
On the other hand for government and official bureaucrats law is the program they had to “run” according to the fiction: “Citizens must not act against the law, government must act by the law“.
Obey law by “letter” or by “intent”
In the March 2020 when Covid did spread in Poland our government produced a regulation which was stating: “You can’t enter the forest“.
Yes, You read it right. Entering a large, green, vast space filled with trees was prohibited due to prevent the Covid spread.
The wording was clear. You can’t. Except that what You would have to do, if You were living in a village which is inside the forest? Starve to death? Abandon Your job?
This single sentence only looks clear. In fact it is not clear. What is a “forest”? A place with trees? Then is a fruit plantation is the forest? Or is a “forest” a piece of land which has a status “forest” on an official land map? If it would be so, the how anyone could quickly check it?
And “entering”. By foot? By bicycle? By car? Is driving the car over a road passing through forestation is “entering the forest” or is it not?
Nobody knew any of that, nobody understood that and nobody got any idea why this law was created.
Nobody, except a few thousands of Warsaw citizens who when first lock-down was initiated figured out that since they were prohibited from entertainment in cities they can legally and fine go and rest in a forests surrounding the city. This rapid motion created crowds of people and since the law was already written in an un-clear and stupid language they did not feel any need to keep distance.
That was a reason behind: “You can’t enter the forest“.
Later, about the November 2020, the government did produce a law which prohibited organizing the mass protests. This is important to notice the wording: “organizing”. Not “taking a part in protests”.
Due to some political reasons which are beyond the scope of this text it was a time when protests were spreading rapidly.
And Police did stop and punished anyone who took a part in such protests, even tough the law clearly stated “organizing”.
In first case (“You can’t enter the forest”) citizens were punished because they broke the “letter of the law”. Police and institutions did not care about the idea behind this law (“keep distance, avoid making crowds”), probably because there was no way they could figure it out, and followed the somewhat clearer direct meaning of a law.
But in the second case the direct meaning was ignored and the “intent” or the idea (the same again) was what was followed by the Police.
Clear communication of “intent”
How does this apply to the code?
Consider following pseudo-code below:
boolean validateAge(Person person)
{
if (person.age < 18 ) return false; else return true;
}
This code is a kind of “self commenting” code. It is clear was does it do. It checks if age is below 18 and decides something.
You may say, that compared to the “law” it is a “letter of a law”.
Does it need any comments?
Observing a vast amount of code which can be found on a web many of programmers will say: “No. High level programming language is self commenting”.
And the would be right. I do agree with that.
They would be right in saying that program exactly specifies what does it do.
But what about what it should do?
Now let me extend this piece of code with a declaration comment:
/** A method which validates if person is in an age which
allows one to consume an alcohol in taverns or similar places. */
boolean validateAge(Person person)
{
if (person.age < 18 ) return false; else return true;
}
The code does exactly the same thing but now it is clear for us what is ought to do. The code says what does it do, but the comment says what it was meant to do.
In this simple case You will momentarily notice that 18 is an incorrect value in many regions of the world!
Would You be able to detect it without a comment? I do not think so.
Note: I do still find this comment to be bad and incomplete, but I think we should ignore it now.
The cast of “wise men”
Now let us again take a glance at the legal system and those two regulations I mentioned earlier. In both cases the government (mister M.Morawiecki) wrote the “code” but never clearly communicated an intent behind those program lines.
Now ask Yourself a question: who on the entire Earth did now what the “You can’t enter the forest” was meant to achieve?
Maybe one or two persons in the government who wrote that.
Now take a look at You software project. That big one. How many lines of code are there? 10’000? No.. that’s small. My first big one person project at high school had 30’000 lines. So I suppose it will be near 10’000 files and about 10’000’000 lines of code.
This is the limit, from my personal experience, when a single person starts loosing a sight of it. The: “Hey, I already wrote it?! Really? When then hell I did that?!” is something You may start to hear. Yet still a person who wrote that code will quite quickly get a grip on what it was expected to do and can fix a broken implementation or even a broken concept.
This way You do have your own hand made “wise man”.
“Wise man” is a person in a software project who was in it from the same beginning, who knows or at least remembers the ideas behind all the internal workings and can be used as “quick access” database to point out which part of code is responsible for what and which part of concept may be responsible for such and such behavior.
The important observation to make is that for such a “wise man” the code is indeed self commenting. Mainly because of the content of his or her brain.
Kill the “wise man” and see what would happen.
Short contract employees
So You have Your big project, You had Your team of “wise men”. Now they all are gone.
You hire new person on a short contract. You ask him/her to fix something.
How the hell can that person guess that 18 in that example is the age for alcohol drinking and not for car driving? He can’t, but he knows it is there so he will do something like that:
boolean canDriveCar(Person p){ return validateAge(p); }
because he knows that 18 is the right age for it and validateAge() uses 18, right?
Then You hire somebody else when law changes and now the law tells that 16 is valid for driving a car. This person will then fix:
boolean validateAge(Person person)
{
if (person.age < 18 16 ) return false; else return true;
}
and will break the alcohol test.
Of course those examples are oversimplified and exaggerated. But in a real life alike things may happen. If there are no clear specification what was the intent of a certain code then people will start using it by what they see it does do. In this example Your API did not specify clearly that it was about an age which let people to legally drink alcohol, so You will end up with code full of calls to this method at any place where age of 18 was to be tested.
Open source projects
Open source, community based projects are full of short term employees. Those projects do base on them. The entire idea was: “You spot the bug, You can fix it”.
I’m a programmer. I do it for living. I can pin-point a bug in my own code within 0.5 to 24 working hours. In well commented code wrote by somebody else I need double of that time.
Without comments I need ten times or more time.
If You are running an open source project whom You like to attract to it most? Inexperienced green-horns who make thousands of mistakes or old lions with years of experience?
If You think about quality You should, I think, focus on gathering the small herd of “lions” surrounded by youngsters playing around and trying to catch some butterflies.
Most of the “lions” do however work for living. They code all day long and the last thing they like to do in a free time is to bite through next piece of code. They probably won’t be making a mass of Your team mates. Yet sometimes they may get so annoyed by bugs that they will make an attempt to fix it.
In their free time.
What do You think, will they love to spent 100 hours digging through non-commented code totally without any information what were main ideas and algorithms in a program, or would they love to spent 2 hours on doing the fix in a well described environment?
If You like to kill Your open source project follow the route with a big yellow sign: “High level code is self commenting”