What does “good taste of code” mean by Linus

In this TED interview of Linus, Linus himself has talked about something he values the best: good taste of code, which as I guess, at least half of audience are confused on what he is really talking about.

I can not say that I am fully understand what he really means, but below is my interpetation.

First let us look at what he cited to be "bad taste of code", as below (let us ref it as "bad code")

bad taste of code cited Linus

and he also gave us "good taste of code", as below ("good code")

good taste of code cited Linus

If we are not programmers, the confusion is obvious: not understanding at all. So nothing needs to be explained further.

If we are not experienced programmers, the confusion is also obvious: not understanding which one works and which one not work. The cruel fact is that both code work. So if we only care about which code works, nothing needs to be explained further too. (In reality, unfortunately 99% of us will stop here.)

If we are even beyond that, as someone enjoy writing good programs, we may start to reach the confusion. Note that here I say "someone enjoy writting good programs", which should be defined as "enjoy both the program code and the program output". Or in other way, is "enjoy the good code" and "enjoy the good result of code". And again unfortunately, at least half of us only "enjoy the good result of code". Let us try to be on both side and proceed.

Now finally let us assume ourself to be "someone enjoy writting good programs". Where the confusion comes from? Both "bad code" and "good code" work, but why "bad code" is bad, and why "good code" is good?

The difference as said by Linus is that "bad code" does not have a good taste, assumes the "bad code" is ugly, not beautiful.

  • The ugly part is in the final "if-else" part. Yes, overall it works, but the final "if-else" is like a patch, saying "oops, there is something unexpected, so here is our fast fix".
  • The "good code" is good because of there is no final "if-else" part, which proves that the algorithm we used is the united theory covering all cases.

So "united theory" is the line between beauty and ugly. It reminds me that as physicians persuing the "unified theory" of all theories, mathematicians persuing the "theories" connecting different fields of math, not because the current theories/codes not working, but because the non-unified status is not beautiful.

Comparing writting code to research of physicians/mathematicians may be unfair, but I hope it helps to deliver that message from Linus: beyond making things work, we should have our values — prefer beauty to ugly. In the end, beautiful things stimulate us while ugly things prevents us, so we must keep our standards and make the whole thing enjoyable. Just like he said in his biography book: (we should code) just for fun.

That is my interpretention of his words, and I fully agree with it.