On Syntax and Semantics, or what Python didn’t get right

C vs Python or how Python really adds nothing revolutionary to the field

Some time ago, per­haps even as far as a year ago, I was just start­ing to watch con­fer­ences and lec­tures in my extens­ively use­ful you­tube account, on top­ics like λ‑Calculus or Category Theory, when on a con­fer­ence by Bartosz Milewski on Categories, he threw a bril­liant sen­tence, that speaks some­thing like this: «Humans should­n’t down­grade them­selves to speak like the machine, we should make the machine speak like humans!»

And very little time after that, while Leon was vis­it­ing me, I remem­ber men­tion­ing such aph­or­ism. His response is some­thing I still think about it today: «Yeah, that is what Python tries to do!». I think I nev­er gave him a good explan­a­tion for why he was miss­ing the point, and more or less a year later, maybe I can try to give him one.

First things first: I made a mis­take in my storytelling that day, so no won­der he got the mes­sage out of con­text. Milewski’s sen­tence needs some con­text before it can be judged. It would­n’t sur­prise even the young­est and most inno­cent aver­age stu­dent: Computers are much bet­ter than us at per­form­ing algorithms! We all know it, we all admit­ted it every time we asked our maths teach­er if we were allowed to use a cal­cu­lat­or in class. It’s quite coun­ter­pro­duct­ive to try to com­pete with a com­puter at this when we are able to keep around sev­en things in our work­ing memory, and a human neur­al syn­apse is just around 100m/s fast, while com­puters have arbit­rar­ily large memor­ies and light­ning fast chips. Instead, we humans are good at ideas and reas­on­ing. So the point of mak­ing com­puters think like us, is about mak­ing them under­stand – or I should rather say, simply execute – our reasoning.

Where Python slips is in some­thing essen­tial, simple, and tra­di­tion­ally missed: the dis­tinc­tion between Syntax and Semantics. An over-sim­pli­fic­a­tion that Leon and I are famil­i­ar with, is when we say that the Cyrillic alpha­bet is totally not the worst part of the Russian Language: it is very pop­u­lar to over-emphas­ise the dif­fi­culty that a dif­fer­ent alpha­bet implies, when in real­ity that car­ries very little sig­ni­fic­ance in how the lan­guage pro­duces mean­ing: it is still essen­tially sym­bol­ising human sounds by graph­emes. That is not a great depar­ture in any rel­ev­ant sense, from say Latin, for example.

What Python cri­ti­cised from lan­guages like C was the clunky syn­tax: those inhu­man-like curly braces all over the place, the semi­colon to denote the end of a sen­tence, or the indent­a­tion being irrel­ev­ant for the com­piler and the inter­pret­a­tion of the lan­guage. Humans don’t throw in their text so many non-alpha­bet­ic glyphs, and indent­a­tion mat­ters to us, it gives us a lot of intu­ition about the struc­ture of the text.

But the semantics did­n’t change basic­ally at all: it is still an imper­at­ive lan­guage with glor­i­fic­a­tions, like wheth­er it is Object-Oriented or Garbage-Collected and what not. Parallelism is still done by manu­al vec­tor­isa­tion, con­cur­rency still requires mutexes and threads, objects still block on their requests (or in more tech­nic­al ter­min­o­logy, mes­sage passing is still entirely syn­chron­ous). Data is still named and aliased, func­tions are mut­able, vari­ables are mut­able memory cells boxed on the heap. Python is still, essen­tially, like any oth­er glor­i­fied imper­at­ive lan­guage, merely describ­ing algorithms. The descrip­tion of its semantics is strictly oper­a­tion­al, and no oth­er body is encoded in its exe­cu­tion. To under­stand a Python pro­gram, just like a C pro­gram or a Java pro­gram or any oth­er of a large set of pop­u­lar lan­guages, you just execute it in your mind. Python is still talk­ing like a com­puter, or as I called it some time ago, it is still a glor­i­fied Von Neumann language.

The dis­tinc­tion is subtle and deep. Syntax is how the lan­guage pro­duces sen­tences. Semantics is how the lan­guage pro­duces mean­ing. And just like with the alpha­bet in the Russian case, the alpha­bet is just twenty-to-thirty-some­thing rules to learn, a fixed, pre­dict­able and lim­ited set of rules, while the gram­mar of the lan­guage is pain­fully com­plic­ated, with all the declin­a­tions and how end­ings build mean­ing for example. Whether decisions are taken, made, met or lif­ted 1, or wheth­er data is anonym­ous or immut­able and mes­sages are syn­chron­ous or asyn­chron­ous, changes the way the lan­guage pro­duces mean­ing in deep­er ways.

So when we say we should make the com­puter speak like us, we mean, we should make the com­puter under­stand our semantics. But then a last ques­tion arises: what are “our semantics”? While I pre­pare myself for answer­ing such an endeav­our, let me leave you, at last, with Milewski’s actu­al talk, he might as well make a much bet­ter job than me. Please enjoy:

  1. In Spanish or Portuguese, decisions are “taken”, like trains that lead you some­where; in English, they’re are “made”, like little pieces of your own cre­ation; in German, they’re “met”, like friends; in Polish they’re “lif­ted”, like boxes from the ground.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.