There are more than 500 programming languages. Hence, it’s pretty normal for you to start learning a new programming language today. It’s possible that you know C++ and Java but your work requires Python or you are well versed in Python and you need to code in Java at work. Or maybe you want to learn that cool language just to expand your expertise.
What are your options if you want to learn a new programming language?
- Learn from some online tutorial or
- Learn from some online (MOOC) course
Some of you may even argue that the best way of learning a new language is actually as follows:
- Learn syntax of the new programming language and
- Build some personal project using that language
Fair enough! This makes sure that you apply the knowledge you gain from learning the syntax of the language you want to learn.
I have developed more than 20 mini projects while learning different languages. Trust me, when you write code for your personal project which may be a weekend project or an overnight quick hack, you write code to get something done. All you care about is — “Does my code work?”. You hardly care about the quality of the code.
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — (Martin Fowler)
So, how do you learn good practices of the new programming language that you are trying to learn?
Contribute to an open source project in that language.
Surprised? Some of you may be thinking — “But wait, open source is hard. We can contribute to an open source project only if we are expert in that language, right?”. The answer is No.
Let me tell you a story.
Last year, I got an offer for full-time job from Booking.com and I knew that I’d be working on Perl (which is their primary language for backend). In June 2016, when I got done with my college degree, I started learning Perl so as to prepare myself for my first job after college. Since I was to join in second week of the July, I had roughly one month.
I started reading about syntax of Perl and started understanding some of the common patterns of the language. Now, I really wanted to build something using Perl so that I could apply my knowledge of the language and practice various concepts of the language. While I was looking for ideas to build something in Perl, I came across DuckDuckGo’s open source organization on GitHub. I noticed that some of the open projects were written in Perl. I had a look at the issues and found a lot of “beginner” issues. I immediately started working on them and submitted a couple of pull requests. Fast forward to today, I am one of the main contributors for a couple of their open projects and also one of the 20 Open Source Community Leaders for DuckDuckGo.
Moral of the story — I ended up learning Perl by contributing to open source projects written in Perl.
So why did it work?
Right after I learnt the syntax of Perl, I started contributing to open source projects. While doing so, I always used to look at the existing modules. I used to notice the patterns being used in Perl. Hence, I started picking up those good practices in my own code and it helped me in learning how to write good code in Perl.
That wasn’t just a coincidence; let me tell you another story to derive more correlation.
Recently, while working at Booking.com, I picked up some task which included working (adding a new feature) on one of the services written in Go language. This was the conversation I had with my teammate —
Me: I really like this task. I want to work on it. What do you think about it?
Him: Yes, it’s indeed an interesting one. However, it requires knowledge of Go. Do you know Go?
Him: Do you want to learn Go?
Him: *smiles* There you go!
So there I was — at the verge of learning another programming language — Go!
I started reading about the syntax of Go and found an awesome beginners language tour on their official website. It was good enough to get me acquainted with all the basic concepts of the language.
Once again, I started looking for open source projects in Go which had some “beginner” or “easy-fix” issues. I found a project by Google which is basically a Go wrapper for GitHub’s REST API.
I had my first PR on that project 2 days after I started learning Go.
How Does Open Source Help?
So now you may be wondering about how open source contributions can help you in learning good practices of a language. There are various aspects of it. Let’s discuss them one by one.
Most of the good open source projects have strict coding guidelines which you have to adhere to in order to get your code merged. This will help you in adapting those guidelines and hence writing good quality code even though you are just learning the language.
Not just that, you have a chance to look at the rest of the code and see how well it’s written and/or documented.
The best part about open source contributions is code reviewing. When you push your code, you get feedback from the experts associated with that project and hence it gives you a chance to improve your understanding of a language.
This is like getting a free-of-cost personal guidance about how to write good code.
We, as software developers, really need appreciation for our work; and open source community makes sure you have enough of that. In my whole experience with open source contributions, I have never received even a single comment which was insulting or demotivating. Everyone is super encouraging and helpful.
So next time you want to learn a new language, go ahead and take the plunge! Find an open source project to contribute to and march ahead on the path to learning that language and its nuances ;)
Do let me know how this unconventional way works for you. Also, please recommend (❤) this post if you think this may be useful for someone.
Feel free to share any other way that worked for you really well. Tweet/follow me @sahildua2305.