Code-Switching: Switching Between Multiple Programming Languages
In the world of software developers, writing code in multiple programming languages is quite common. Most software developers are not only expected to be polyglot but be able to do so within the same day!
Learning a new language can be daunting but after some time learning the loops, the classes, the variable types, etc you get a hang for it. You settle into the new language and start to become comfortable with it. But now, what if you have to switch back and forth between programming languages? That sounds trickier… But don’t worry! Developers do this every day and it becomes easier with time!
What is code-switching? Code-switching is a term used by linguistics which means:
“the practice of alternating between two or more languages or varieties of language in conversation.”
It's used to describe what happens when people who speak multiple languages such as French, Italian, and Mandarin start to mix their words and phrases up. There are different types of code-switching, such as replacing a single word in another language to replacing an entire sentence.
I speak a few different languages with varying degrees of fluency. I speak Bengali and English with native fluency, my French would be intermediate, though fading with each day of no practice, and some conversational German leftover from my summer abroad. I naturally can move between these languages without much thought. So what are the mechanisms that help me keep track of my spoken languages and can I rely on them to help me fluidly transition between programming languages as well?
Context is the most important player here. It is very important to your ability to switch between languages, spoken or programming.
I speak Bengali with my family, I speak English with my husband and I speak French if back home in Montreal when I can’t seem to avoid it. The reason I don’t mix up what to say (normally) is all due to context. My brain knows what to say depending on the person in front of me without even thinking about it. Context helps it not get confused.
One thing linguists have noticed is that when it comes to speaking multiple languages it's not an on-off switch between them. You are in fact capable of using multiple languages at the same time. That's the whole basis of code-switching! So your brain is actually already wired to be able to handle multiple languages as it is constantly active and these languages are trying to interact with each other. You cannot stop is any more than you can turn your brain off.
So there really is nothing to worry about! You can switch between speaking formally and informally in the same language instantly and you know to not use swear words when a child enters the room. The same mechanisms can help you switch between functional programming or object-oriented programming languages.
I'm really not adding any value to the internet with this section. But ill say it anyway, you can only get better with PRACTICE. The more you actually practice switching between languages the better you will get. This is true for not only all types of languages but any skill really. I know, shocking! A good way to start is to just experiment in the languages. See if you can write the same program or function in the two languages. Then compare them and see how they differed as well. Just keep coding, just keep coding, just keep coding coding coding…
Costs of Switching Frequently
Now as beneficial it may be to move through languages in a day, there are a few things to note:
- You will be slower- it's ok, you won’t necessarily be slow, but you will be slower than if you focused on one programming language at a time. This occurs in spoken languages too! People who speak multiple languages, are slower to go from concept to words than monolinguals. They simply have more information to sift through.
- You may find yourself thinking in the context of the other language- As anyone who has used google translate to quickly finish an essay for Spanish class will let you know, literal translations are not always best. Remember to not just switch languages but switch your way of thinking too. As mentioned above, different languages have different strengths, and while switching back and forth be sure to keep that in mind.
- As with spoken languages, it is not a good idea to try to switch before you are completely comfortable in the new language- switching while still learning will slow down the learning process. Make sure to gain some comfort in both languages independently before allowing yourself to work in both concurrently. Remember, the best way to learn a language is by being fully immersive in it!
- If coming back to a language after a long gap, you may not be up to date on the language- programming languages change rapidly so always take some time to brush up if you haven’t coded in the language in a while. This would be the equivalent of using slang from the 90s, so not hot!
There you see, switching between languages isn’t that bad! In the end, you will become a more desirable software engineer with your ability to be so flexible. With the mastery of coding in multiple languages concurrently, you have now become a true polyglot programmer. Bonjour World!