3 ms·
Learning multiple programming languages
I have been coding primarily in one language (C) and from time to time attempted to learn other languages too (C++, perl, python, PHP). However, even if I learn the syntax or niche offered by a specific language, I find it difficult to imbibe the spirit of language and still try to think from C perspective. How do people who claim to have mastered multiple languages, do so? What am I lacking here?
- sanxiyn 12y agoYou should learn from examples. Instead of writing codes in languages you learned, read good examples of codes in languages you learned, and try to copy their style.
- confused_coder 12y agoYes, but then only one language appears to be dominant in my mind at a time and I try to use it's features in others. For e.g. after spending time with python, when I switch to C, I digress thinking about how this could be done with maps or zip or something which I'll have to implement in C and probably would end up being non-efficient solution. Similarly, when switching back to python, I digress thinking about how this feature must have been implemented in Cpython and eventually end up thinking even more about C and way solution would be approached in C.
- nostrademons 12y agoCode more in each language, enough that you actually forget how to code in your previous language. Then switch back and re-learn it, including the old idioms. Your goal is getting the idioms, best practices, and language philosophy ingrained unconsciously in your brain, so you don't have to think about it. It's much like switching from Qwerty to Dvorak. When you first do it, if you do it right, you will forget how to type in Qwerty. It's only after switching between them a couple times, re-learning the previous layout, that you'll become fluent in both. Switching does become easier after the first few times, though.
- devnonymous 12y agoI agree with what nostrademons said in his reply. However, I also find it useful to try your hand at coding stuff that the language is good or well suited for. For example, when doing python, don't write cli tools (although you can very well do that with python). Write a web app or learn Django and try and build something using the framework. Focus on the spaces where people claim the language is best suited for. When switching back to C, do systems level programming. Also, set your goals (ie: what you'd like to build using the language) according to the strengths of the language. Off the top of my head, here's something I would suggest: Ruby -- Build a webapp -- possibly a complex enough app. Aim big -- like gitorious perhaps. Focus on learning rather than completion. Python -- Build a game C -- Contribute to the linux kernel :) ...you get the drift, I guess
- confused_coder 12y agoThanks! all great, practical tips. edit: BTW I do contribute to kernel (occasionally) and have written games and done moderately sized projects in python (out of interest). But I think main thing is probably to contribute often so that I switch back and forth often too.
- prostoalex 12y agoYou can only learn idiomatic code by working with idiomatic code. Pick a popular project on GitHub in that language (popular ones are more likely to be led by language connoisseurs) and contribute to it in some small way, or just play around with your local fork.
- jarcane 12y agoWrite code in it. Lots of code. And not all your own code. Find books that give clear 'type it yourself' examples that you can follow along with, or books that test your ability to think in the language by giving you problems that need idiomatic code to be solved (perhaps the best example of a book like this that I've seen is The Little Schemer). If there are 'koans' or 'katas' or similar interactive exercises for the language, find them and do them. All of them. I learned so much about basic style of a language from these. Try sites like Project Euler and Codewars. Find tutorials like 'how to build an X in Y' and follow the whole thing from start to finish. It doesn't even necessarily matter, IME, whether the code is particularly good or idiomatic: once you've made a project of any considerable size you'll start to see the strengths and weaknesses of the code and the advantages of the native idioms. Finally, find yourself at least two non-trivial personal projects to write in your new language, and just write. Write big code, that needs proper maintenance and bug-checking and testing. Don't worry so much about idioms yourself though, just write: when you go back over your code again, you'll see where you've gone wrong, and do better next time. Your first big project in a new language will be terrible. But you'll know exactly why it's terrible by the time it's done, and you'll do better next time. This is what's helped me, anyhow; obv. everyone is different, I am not an expert, etc. etc. The important take away is that ultimately: "idioms" are just ways that people have found work best in the language; the best way to drill on the style of the language is just to use the language a lot and read the language a lot. Idiomatic code comes from practice, more than anything.
- brudgers 12y agoThere is a book out there designed specifically to move C programmers outside their comfort zone: J for C Programmers. http://www.jsoftware.com/help/jforc/contents.htm http://www.jsoftware.com/help/jforc/contents.htm That's not to say that it will redirect your career from C programming to J programming (my impression is that there are not a huge number of all day every day J programming jobs). But rather, J is one of those languages that requires people to change the way they think about programming languages. It's pretty amazing in my opinion, but I've been drinking the Kool-Aid ever since coming across the book.
- confused_coder 12y agoThanks! Will read.