String Equivalence – C vs. JavaScript [1/2] – The Philosophy

At first glance – especially as a novice programmer – one would say it’s self-evident, that the following expression is always true:

"a" == "a"

In fact, as we have learnt in school – this principle is the very basis of algebra:

Certain identities, such as {\displaystyle a+0=a} and {\displaystyle a+(-a)=0} form the basis of algebra

Identity (mathematics) – Wikipedia

Or going even deeper (or higher), the Law / Principle of Identity is the first one of the three fundamental laws that the classical and medieval philosophy was built upon:

In logic, the law of identity states that each thing is identical with itself. It is the first of the historical three laws of thought, along with the law of noncontradiction, and the law of excluded middle.

Law of identity – Wikipedia

[the] history of the three traditional laws that begins with Plato, proceeds through Aristotle, and ends with the schoolmen of the Middle Ages.

The law of identity: ‘Whatever is, is.’[2]

For all a: a = a.

Law of thought – Wikipedia

So how can the same code produce different results in different languages?

JavaScript and C are – as far as this case is concerned:

Lexically Identical, but Formally Distinct

The lesson is that it’s the opposite of mathematics or philosophy. There, the objective reality precedes the language. Language and syntax are tools to express already known facts, laws of nature.

My teenage mistake was to take this assumption into the world of programming languages. In fact the causal relationship, the order in which things proceed is reversed. Here the authors of the language propose concepts, and pair it with some syntax. To have the language actualize into reality, into programs – the language has to be implemented. Here humans actually create the laws of nature, the rules of the game if you will – for something that will only exist in the future. Implementation means to make the hardware do what the language set out to do.

And this important difference gives peace of mind. When learning a programming language, we are not tasked to solve puzzles that no-one knows the answers to (unlike in mathematics or physics – not that solving those couldn’t be fun per se). In fact we have to reverse the thinking alltogether. To create things in a certain language, we have to learn the language basics first. It is not magic – all the complexity was achieved gradually, built up from the most simple operations.

It is also a very humbling process. We have to conform. We have to be patient and persistent. We have to be willing to keep learning. The computer won’t move an inch, unless we put in the right combination of syntax. Bargaining, threats, flattery won’t get us anywhere. We must constantly face the painful truth – that it is us who are unable to express ourselves in the language. The machine knows it perfectly. It cannot do otherwise. It was programmed to do exactly that. To obey the rules of the language.

I was very immature in high school. Unaware of my own emotions I projected and ridiculed C for being so dumb and wrong. How could “a” not equal “a”? I thought perhaps believing such insanity was the gateway to becoming a socially awkward weirdo with bad hygiene and no girlfriend. Oh how wrong I was.

To be continued…

Leave a comment