Syntax, Semantics And Power Of Expression

00026-1158177497.png

"Der Junge im Bild ist traurig"

"写真の中の男の子は悲しいです"

image->boy.happiness < 0

Music Piece

These languages could not be any more different, yet they all convey the same meaning.
Languages are tools for expressing meaning. They are implemented by a vocabulary and follow rules called the syntax. Transferring the semantic content to another language is a matter of translating one syntax to another. A picture can express a sad situation using visual language, and so can music express the same situation using musical language, so can the German language and the Japanese language, etc. The more refined the thought to express, the more complex the underlying structure needs to be to support it and help the recipient to follow.

However some concepts are easier expressed in certain languages than others. In Japanese we can express things in a very precise way, often by interpreting compound meaning of kanji (chinese characters that have iconographic value). In music we might be able to convey the concept of sadness in the context of childhood by mixing a playful theme with a sad one, but the clarity or precision of a boy or photograph would be unachievable. And in the programming example we focus more on the process of sadness, describing how we can express it in terms of an operation (operational semantics), and the relationship between the parameters defining it. And finally the german language enables to express some concepts very precisely using Compound words.

The best example are words like the German word "Fernweh", which has hardly any translation to other languages. This expression can however be paraphrased requiring longer expressions like "the craving for traveling to distant places". When a language enables you to express a concept concisely it enables a stronger power of expression. These phenomena are ever-present in our culture like the saying "A picture says more than 1000 words", which just refers to the fact that the abstraction level of visual language enables at once to express very specific ideas and emotions which would require many words to paraphrase.

When a language defines an abstraction, like a word, it also creates a link to the associated concept and expands our mental repertoire. And as we have seen before certain syntactic constructs influence the meaning quite drastically. Languages do not simply help us express meaning, they shape the way we reason about that very meaning.

This applies to programming languages as well. Theoretically any operation or computation could be implemented with any language, as long as they are Turing complete. However certain languages implement features by design. Then, not only is it easier to express these patterns with these languages, but within their scope we start thinking about programs differently, in terms of different abstractions, notions and concepts. This also defines how these languages are applied and for what kind of problems they are used.

As we have seen before, syntax refers to the rules and elements to write or form a valid expression in a language, while the semantics refer to the meaningful content encoded by the syntax. So the semantics of a language define the context and concepts to be expressed by a language, the syntax is the format by which the semantics are encoded. To translate the meaning from one language to another, we try to decode the syntax of one language, extract its semantics and reimplement or encode them in the other language.

And yet some meaning gets lost on the way as we have seen with our example above. That is the real reason the boy is sad, by the way.

There is some syntactical structures that are closely tied to their semantic implications. These kind of idioms are often what make the language unique and distinct from other languages. Programming can be understood as the creation of levels of abstraction to implement increasingly complex tasks. When programming in a level of abstraction, you think inside of the domain of that abstraction, ignoring simpler concepts that form the level or other details irrelevant to that task. Translation however does not create a new level of abstraction, it takes something from one syntax and encodes it in terms of another syntax, the concepts and the context stay the same. So to raise in levels of abstraction you need to create new semantics!

But to what level you can raise the semantics often is tied to the syntactic abilities of languages. Usually languages are selected and promoted because of their ecosystem: the systems they are integrated with, the community and therefore their popularity in the industry and the collection of existing technologies such as frameworks and libraries available for the language.

I propose instead to select and use languages not based on their popularity, but instead their semantical notions powered by the design of idioms. Since idioms are a good middle ground between syntax and semantics, we also have the added bonus effect that we learn new concepts with every new programming language, similarly of how art helps us reflect differently about similar things. It helps us to change our perception of the same topic: programming. Every language becomes a dictionary of new syntactic and semantic contexts also enabling us to reflect in new ways about programming. I think this is underestimated and invaluable!

Takeaway

Every programming language encodes in its syntax unique concepts which have a different notion about programming and the systems they interact with. Often learning new programming languages is worth to expand our own repertoire of such concepts. And if we think in terms of human communication and the ability to express ideas, often some languages can provide underestimated benefits, that could outweigh their smaller popularity or immature toolset.

If you would like to know more about this way of thinking and would like to see concrete examples, check out my personal diary in how I explore elm for its idiomatic ideas, by following some of the Advent of Code 2023