Words and Programming

A single word succinctly conveys a complex subject. For example, the description “the fleshy usually rounded red, yellow, or green edible pome fruit of a usually cultivated tree (genus Malus) of the rose family” – (Merriam-Webster) – which has 21 words – can be shorted to a single word: “apple”. The succinctness of words are particularly useful for repeating a subject multiple times. How much easier it is to say “apple” five times than its 21-word definition five times! Similarly, in programming, functions also succinctly convey complex subjects. Instead of writing twenty lines of code every time to update the screen, we can place the code in a function called update() and type update() instead, which is much easier to read and change. In both natural and programming languages, we increase clarity by replacing the verbose with the succinct.

 The word “apple” was defined in terms of more words, so we say that its definition is almost recursive. (yes I know, the other words aren’t also “apple” but it still makes for a nice analogy). In programming, we too can use recursion to define algorithmic solutions, such as for solving the Tower of Hanoi or traversing a tree, because it is easy to understand and concise to write. Nevertheless, recursion isn’t the only way to define terms. We could also define words with pictures and algorithmic solutions with loops. The choice of how to define a term depends upon context.

 Even if you and I might have different definitions of the word “apple”, we would both recognize it upon seeing it. Despite our different definitions, we still fundamentally agree on what an apple is, and so we say that the word “apple” is an abstraction. Our internal definition of an “apple” is the implementation, such as if you were to define it as a red fruit and I were to define it as a green fruit. The abstraction is a general idea whereas its implementation is the detail. We use abstractions in our daily conversations when conveying precise information isn’t necessary, such as saying “I like that car”, and we use implementations to specify specific examples, such as “I like that Volkswagen Golf Mk6”. We also use abstractions and their implementations in programming for those same reasons. Suppose we define an abstraction called “employee” and let both “intern” and “manager” be implementations of “employee” because they share similar properties, then every time we refer to “intern” and “manager”, we can actually refer to “employee”. The advantage is this increases the code’s modularity and clearly demonstrates that “intern” and “manager” have similarities. The net effect becomes that the program becomes easier to understand and debug than if we referred to “intern” and “manager” as themselves without using the abstraction of “employee”.

 Perhaps the greatest similarity between words and programs is that they are both tools of communication; they both form languages. Humans use natural languages to represent emotions, facts, opinions, and ideas; machines use programming languages to communicate with humans and other machines. We often use natural languages more vaguely than programming languages because humans can deduce context and understand implied meanings better. For instance, if someone said, “Please count to 10”, you would automatically deduce that they mean to count like this: 1, 2, 3, … 10. However, a computer would require more clarifications to carry out this simple request because they don’t understand context: what’s the starting number? Are the numbers consecutive or do they skip? Shall the numbers be counted rhythmically or at a steady pace? They are both languages that use different amounts of instructions to enable meaningful communication.

 Why are there so many similarities between natural and programming languages? I think the reason is that programming languages are designed by humans who have used natural languages all their life. They are already aware of the intricacies and benefits of natural languages and extend them to programming languages, leading to their shared properties. Another reason is that it is much easier to build a programming language similar to natural language because so many have already been built than it is to build a new paradigm of communication. The similarities between natural and programming languages help ease beginner programmers’ learning curves and provides us more context of our programming languages.

Sharing is caring!

Leave a Reply

Your email address will not be published.