Is your first programming language holding you from learning your next language?

In one of my previous posts, I mentioned how I was using the Java syntax of lambda expressions while I was programming with Kotlin. In my observation, whenever we are working on something, if our brain finds a match to what we already know, often end up using the same solution. This pattern matching can happen at various levels like code syntax, design, architecture etc.

Now consider the scenario of you learning your second programming language. In my opinion, whenever you decide to write a piece of code, your brain will tell you how to write that piece of code in your first programming language. The extent to which this can happen will depend on how fluent are you in your first language. The more fluent you are, the better the chances of you becoming a hostage to that language.

Depending upon the nature of the languages, this can have various impacts on you. If the languages are similar (for example Java and C#), then the amount of friction will be least (of course it will vary by individuals). However, if they are based on different paradigms, then you might struggle more.

Let's take a look at some of my observations here. During my college days, I have seen many folks learn 'C' and then learn 'Java' (I know - you learn C++ too before learning Java!). As a result, people would end up writing procedural code with Java! Also, they would reinvent the wheel, without looking for the utility methods available in the standard library. There would be only one reason why they would create that second class - they have to extend another class!

Let me share an incident. I wanted to learn Java and joined a course that teaches Java, along with some other web technologies. The instructor asked us (my friend too had joined) if we know C and we had just started learning 'C' as part of our regular curriculum. The instructor was worried about how he could teach Java to the folks who don't know C/C++ already. I never felt that fluency in C would have improved my Java code in any way. Instead, object-oriented thinking had the most significant impact on my Java code.

If your second language uses a different paradigm than your first programming language, then the struggle might be more. You may not find a construct that is similar to your first language. It might take a while for you even to accept that the same problem can be solved in multiple ways and you need to pick an approach which your new language supports/ favours. (for example currying, function composition, infinite and lazy collections in functional programming).

Overcoming the syntax barriers

Syntax barrier is the easiest to overcome. First, you have to convince yourself that it would take a while to get used to the syntax of your new language. It is perfectly alright to keep a reference aside to take a look at whenever you think you can't recall the syntax correctly. As you practice, you will get fluent. You must get past the syntax barrier and understand what it takes to solve problems with that language. Also, modern IDEs support auto-completion and templates to help you with the syntax.

Overcoming the paradigm barriers

The first step in overcoming paradigm barriers is to convince yourself that there can exist multiple solutions to the problem. Look at several examples of how folks who have already mastered the language solve problems. Don't stop when you have a working code. Instead, look for opportunities to improve.

Different languages may have different building blocks

Even though two languages are based on the same paradigm, they can be different. For example, both Clojure and Haskell are based on the functional-programming paradigm, yet they hugely differ. Both Java and Groovy support object-oriented paradigm. However, you would use Traits in your Groovy code to design composable features, wherein Java, you might probably overuse default methods to achieve the same impact (or use composition using multiple interfaces).

Conclusion

The more languages you learn, the better you get at learning, and you learn the next language quickly. Ensure that the language indeed influences the way you think. Otherwise, that language may not be worth learning. As independent deployability characteristic is more indispensable today than ever, we are getting more opportunities to use multiple languages in our application. Hence being a polyglot programmer may be worth the effort.

Show Comments