Keeping multiple programming languages straight

Someone sent me an email asking how I use multiple programming languages and how I keep them straight. I thought I’d write my answer here in case someone else had the same question.

I’ve learned programming languages out of a mixture of curiosity and necessity, maybe more of the latter. I’d rather use fewer languages, or at least use more languages out of curiosity.

Alan Perlis once said

A language that doesn’t affect the way you think about programming is not worth knowing.

In the spirit of Perlis, I’d say that it’s worthwhile to learn some programming languages just to expand your thinking. Learn a language outside your comfort zone, even if you don’t foresee any practical use for it. Expanding your mind is practical enough.

Another reason is to use multiple languages is to pick languages optimized for different tasks. For example, you might use SQL for interacting with relational databases, C++ for fine-grained control and efficiency, Perl for text munging, etc.

But keeping track of the differences between similar languages is just drudgery. When languages are very similar, there’s little educational or engineering reason to use both. But there may be good business reasons, such as preserving legacy code or serving different clients. Given a choice, I’d rather not use two similar languages, but often I do out of necessity.

So, how do you keep different programming languages straight?

  1. Try not to use similar languages in the same niche. Learn one system programming language, one scripting language, one markup language, etc. If you have to use two languages in a niche, pick one to learn well.
  2. Try to use one language at a time. Load that language’s syntax into your mental RAM and use it as long as you can before switching languages.
  3. Keep notes and save sample code.

Some of the more popular pages on my website are notes that I wrote for my own reference. Years ago I was confused about all the different kinds of strings I had to use in C++ and wrote these notes. And when I was learning PowerShell I wrote a cookbook of sorts.

Here are some more examples.

Regular expressions in:

Probability distributions in:

I’m glad people have found these notes useful, and I did have in mind that other people would read them, but I mostly wrote them for my own reference.

10 thoughts on “Keeping multiple programming languages straight

  1. > Keep notes and save sample code.

    Indeed. I’ve got dozens of files in a “notes” directory, on topics like SQL, Ruby, Rails, capistrano, CSS, Ubuntu, cpanel, etc.

    Each file varies from 20 lines to 2,000 lines. They contain snippets of sample code, memos to myself, and more.

    Not only do I refer to these files on a daily basis, they also save me time when working with others.

    “Hey, Travis, can you explain to me how to do polymorphism in rails?”

    “No…but I’ll email you 200 lines of examples and notes”.

    “Hey, Travis, how do I add an SQL index that uses multiple columns?”

    “Hang on….emailing it now”.

  2. As you say learning similar languages is not much help. One or two funcional languages where your interested in the result not the speed of the solution will help your thinking a lot.

  3. The worst are very different languages that are similar only in basic syntax such as Java and Javascript which many developers frequently switch between.

    Notes, references and focus. And a sense of humor when it suddenly hits you that the compiler is not the stupid one ;-)

    Mostly out of curiosity, I have also used, and keep notes and references on, several nosql databases such as MongoDB, CouchDB and Neo4J. Datomic looks particularly interesting for its immutability and sense of time. You can view the data at any point in time (except of couse for the future but how hard can that be? Python can import modules from the future ;-)

  4. I keep small Wiki VM running on my desktop, and use it to warehouse my notes about various programming languages. At one point, I was actively maintaining/extending projects in C, Perl, Python/Django and Ruby. Notes (even on basic stuff like ‘how this language structures if-then-else” and “file I/O”) were invaluable at times, especially when revisiting projects after many months away.

  5. Agreed. I find it difficult to work with similar languages like Matlab-R, Java-C#, python-ruby…

    I used to manage with cheat-sheets, but code samples + notes is a better approach.

  6. Your notes on “strings in C++” do not have much to do with C++.

    However, they do make me glad I have never used Windows and never will.

  7. Wouldn’t it be nice if the language maintainers would allow syntax from other languages, where it can be done without breaking the language? For example, in JavaScript, x={}; x.foo=7; is messier to do in Python, where even x={‘foo’:7} does not allow you to use x.foo.

    Python should allow // and /*xxx*/ for comments, and JavaScript allow lines starting with #, SQL’s –, etc., for comments. I wouldn’t port Visual Basic’s use of single-quote for comment anywhere though!

    Python gurus agonized for years about ternary if, such as C’s
    x==7 ? “This” : “That”
    but kept some sort of purity by making it be
    “This” if x==7 else “That”
    Neither is really clear, but for the sake of millions of programmers, wouldn’t it be nice to have each language support BOTH? (Really, only Python should change, but that’s unlikely.)

    Then you can imagine programming in a sort of pidgin JavaScript that works on every system, not for ALL your code but for ordinary stuff. It’s less likely to be buggy, and saves countless hours looking at cheat sheets for those switching among languages.

  8. nice article , but i still wonder , how many of these programming language or scripting tools gonna die with win8 release ? is win8 end of multilingual programming ?

  9. ah didnt saw that article (thanks also for providing the link ;) ).hmm “Projections” …intresting . will check it soon.

  10. Windows 8 includes better support for multiple programming languages than any previous version of Windows. See post here.

    WinRT has a new mechanism to generate idiomatic wrappers around core Windows APIs for various languages from metadata. This means that programmers in all languages get access to new APIs as soon as they come out (provided someone has written a “projection” that maps WinRT APIs into that language) rather than waiting for humans at Microsoft to hand-craft and release wrappers for each language.

Comments are closed.