Emanuela Avagyan (she/her) has been working as a data analyst since 2020. She has a background in psycho-, neuro-, and clinical linguistics.
We've all learned a language at some point in our lives. Specifically, I'm talking about natural languages, which is the term to describe the languages used for human communication.
While not all of us have learned programming languages, it turns out that learning a programming language is a lot like learning a natural language. This may not come as a surprise to you, but as a neurolinguist and programmer, I can see these connections clearly.
If you've just begun learning to code or are simply curious, contextualizing coding by relating it to languages might help code feel more relatable. It'll also help you understand what aspects to prioritize to gain fluency.
… And if you already know how to code, knowing about these connections can help you become more proficient and communicate concepts to others as well.
If you get excited about learning languages, I believe you can capitalize on that passion to grow an affinity for programming as well. Perhaps, like me, you might enjoy coding for its differences as well.
Today, I'll share how learning to code compares to learning a natural language:
7 ways learning to code is like learning a language
1. You need to know the building blocks of the language
In a natural language, there are many building blocks that come together to construct a sentence. Each component plays a different role, and you need to understand how they differ in order to correctly use them.
Similarly, programming languages also have building blocks that form to combine the analogous sentences for code: expressions or statements. These components all play different roles as well.
For instance, here are the components that exist in English and Python (they are, of course, shared among other languages as well):
English:
- A phoneme is the basic building block of language, the smallest unit of sound.
- A morpheme is the smallest meaningful unit of language, it is a combination of phonemes.
- A word is a combination of morphemes that conveys some meaning and can stand on its own.
- A sentence is a combination of words that conveys a more complex meaning. Sentences can be combined to form a text.
Python:
- A literal is the most basic building block of a programming language.
- An expression is a combination of literals. Expressions can be combined to form larger chunks of code.
2. You've got to follow the syntax rules
Once you know the building blocks in a language, you have to follow a set of rules called syntax. The syntax tells you how to correctly structure the building blocks to create a valid expression, statement, or sentence.
In English, one syntax rule is that adjectives go before nouns. (e.g., "Purple hat")
A syntax rule in Python is that statements end in a colon and subsequent expressions get indented:
if 1 > 2:
print(“hello world!”)
Just like in a natural language, following the proper syntax when coding is important to ensuring your sentences are correct and make logical sense. If you do not use the proper syntax in Python, you will most likely get an error message such as SyntaxError: invalid syntax
which is essentially the computer trying to tell you, “I do not understand what you are saying.”
3. You need to master semantics
While syntax concerns structure, semantics concerns meaning.
In both natural and programming languages, the meaning of your sentence is affected by the building blocks you use and how they relate to one another. For instance, if you use the wrong components or pieces of code, the meaning of your sentence will change.
You can have proper syntax but yield incorrect semantics, which means you've communicated something you hadn't intended.
Let's consider an example in English:
“This is a square circle.”
This is a syntactically correct sentence, but semantically it sounds rather strange. While in a different universe, there might be such a thing as a square circle, in our own universe, this sentence doesn’t quite make sense and therefore contains a semantic error.
To consider an example in Python:
number1 = input('Please enter a number:')
number2 = input('Please enter another number:')
sum = number1 + number2
print('The sum of', number1, 'and', number2, 'is', sum)
With this code, we may expect to get the sum of the two numbers that we enter as input values. However, if you're familiar with Python, you probably know that the input function returns a string (in other words, textual values). Unless we convert the strings into integers (in other words, numbers), our result will be two numbers concatenated to each other rather than added. For example, in the case of ‘1’ and ‘3’, we would get ‘13’ instead of 4.
So, while our code is syntactically correct, the result is not what we had in mind and therefore is semantically incorrect.
Just as with any language, code itself forms a bigger story. To understand the meaning, you need to understand the semantics and relations between all the smaller bits of code that comprise the story.
This leads to our next point!
4. It's important to study your vocabulary
In order to become fluent in a language, you need to build an internal dictionary of the words you use in the language. It's the only way you can ensure you're able to express what you mean to say.
Vocabulary is the range of words that compose a language.
Vocabulary can consist of words within various subcategories in a language. For instance, in English, it'd include nouns, adjectives, and adverbs, ranging from "building" to "happily". When learning English, we would probably memorize that a ‘building’ is a noun that has the meaning ‘a structure’, while ‘happily’ is an adverb that means ‘with joy’.
Likewise, studying your vocabulary in Python would need to span many categories, including:
- Loops such as
for
loops andwhile
loops. - Data structures such as sets, tuples, dictionaries and lists.
- Operators such as
+
,**
,AND
,OR
etc. - Functions and methods such as
print
,input
,join
,pop
,reverse
etc.
When learning Python, we need to memorize each term and its meaning, as well as how to use it. For example, print
is the name of a function that will display whatever is passed into it on the screen. The truth is you won't know everything like the back of your hand – ever. The reality is that even professional developers may search for terms they haven't memorized while they're on the job.
While there's always new things to learn, you really want to internalize as much vocabulary as you can so that you can work more efficiently, with less interruption.
5. It takes time to gain fluency
In the beginning, when you're first learning to code, it might be frustrating when you can't remember things you feel you've learned. But as with any language, it takes time and patience to gain fluency.
Until you really internalize knowledge about the building blocks and their roles, the functions and data structures to use, and the syntax rules, your writing and comprehension will be slow. You may need to reference notes or meanings of pieces of code. You won't be able to enter that flow state where words come naturally – and that's ok!
Over time, you'll commit more of the words and phrases to memory. With experience, you'll be able to command the language fluently and know exactly what words and names to use when constructing your code.
6. Immersion helps you learn quickly
Immersion is one of the best ways to learn a language. For instance, living in another country gives you no choice but to learn it. While you can't quite immerse yourself in a nation that speaks Python at the grocery store and bus stop, diving deep into a language and spending focused time with it will be more effective than casually dabbling in it. Being part of a community of developers and programmers will also speed things up considerably.
The reason immersion works well with learning languages is because you're forced to learn by doing – which includes making mistakes. Learning by doing is the best way to learn to code as well. If you don't actively use the knowledge you gain, you won't commit it to memory or get a-ha moments after being stuck.
That being said, immersion can be a strenuous activity for your brain when you've just started to learn. Your brain needs to take breaks in order to process the new information.
So, it's helpful to give your brain a rest from absorbing the new language you're learning. Even in your downtime, your brain is saving that information in your memory.
7. We tend to pick up the habits of those around us (Be wary!)
We're social creatures, so there's an interesting phenomenon that happens to all of us with languages: we tend to speak the way that others are speaking around us. Even as a linguist, I'm not immune.
For instance, I currently live in the Netherlands and speak Dutch. Despite my proficiency in English, I've succumbed to the local blend of Dutch and English (colloquially known as Dunglish). It's not a terrible thing, but it becomes problematic because others look to me as an example of a proficient English speaker. In reality, I end up modeling incorrect practices.
In the case of programming, the risk is that you may pick up bad habits that contradict coding best practices. There are plenty of people out there who don't follow these best practices, but you really don't want to join their ranks. Bad habits such as lack of comments or not using meaningful naming will negatively affect the productivity of any team of developers you work with. Even if you're not a senior developer, other developers could be looking to you as an example, so it's important to be mindful of avoiding problematic habits.
How coding is different
I love language because it gives humans a way to connect with each other. And it's fascinating to explore the ways that our language affects how we see the world (and vice versa).
Despite the technical rules of linguistics (from syntax to grammar), human communication has a lot of variation and nuance. Sometimes, the tone with which someone speaks gives us information that isn't communicated through the words… and sometimes, it's what they don't say that tells us something too!
There are some fascinating nuances that come with interacting with humans, but I have to be honest – interacting with computers has some refreshing differences.
For instance:
- Computers don't understand ambiguity
- I know exactly what a computer requires, unlike a human
- I don't need to worry about making sure I'm polite (I promise, I'm a kind person, but it's nice to get a break from emotions sometimes!)
When you code, you’re communicating with computers, and you have a specific problem to solve. There's a whole process of understanding how to put your code together in a way such that the computer can extract exactly one interpretation and do exactly what you want.
Of course, there are many other differences between programming and natural languages. But these are the differences that I've found refreshing, despite my love for natural languages.
From English to Python
Every day, you're using language to interact with people around you. In our modern world, we also need to interact with computers now and then. The skills involved in learning a programming language are not so different from what you use in learning a natural language.
I never imagined I would be a programmer. In fact, I accidentally discovered coding while pursuing a degree in neurolinguistics. For me, the fact that I could apply it in the field of neurolinguistics fueled the fire under my desire to learn to code.
I think many people find it intimidating to learn programming, especially if they don't have a background or training in computer science. But there's a reason that many people around the world learn coding independently and still succeed. Our brains are built for language, and even if it takes time, you can become fluent as fluent in a programming language as your native language.
I hope seeing these connections will help you master fluency along your coding journey!
Continue reading about tips for learning to code
- Learn to code part-time: 5 tips for success
- Learn to code with these 5 proven learning strategies
- How to become a programmer without a degree
Start a discussion
What are some other ways that learning a programming language resembles picking up a new spoken language? Was this article helpful? Let us know in the comments below!
Top comments (0)