Learn a Second Programming Language

Learning Python as a first programming language is awesome.

Learning JavaScript as a second programming language is also awesome.

Here are some things I like better in JavaScript, just after a few days of practice:

  • JavaScript console is part of every modern web browser. So you don’t have to install any software to start using it. And the JavaScript console handles multiline code, unlike, say, OSX Terminal with Python.
  • Block statement with curly braces instead of just indentation. Python’s use of indentation seems to be more readable at first. On the other hand, the fact that you can do indentation with tabs as well as 4 spaces, sometimes leads to errors in the code. The readability advantage of Python disappears, while modern text editors and the JavaScript console render curly brace notation indented anyway. And curly braces give you more flexibility, you can write a whole function definition on one line, if you like.
  • Objects with dot access to properties instead of Python dictionaries and classes. Two syntactically different implementations for basically one and the same thing (namely hash tables) in Python doesn’t seem to be very useful. Moreover, instead of the simple object.attribute notation in JavaScript, with Python dictionaries you have to type more to get properties: dictionary["key"], which is more error-prone. “Imitation is the sincerest form of flattery”: there are many implementations of the “Bunch” class in Python, which gives you what JavaScript already has: “A dot-accessible dictionary (a la JavaScript objects)”. And JavaScript handles inheritance quite well without classes, namely with prototypes.
  • JSON, which seams to be the winner over XML for serialising structured data nowadays, has evolved from JavaScript object notation (as already the resolution of the “JSON” acronym suggests.)
  • The difference between the weak and strong form of identity, denoted with “==” and “===”. The weak identity2 == "2" for instance evaluates to true, while the strong form 2 === "2" evaluates to false.
  • The string .replace() function accepts regular expressions natively, without any hocuspocus. In Python you have to import the re module, and use a different name, re.sub(...) for the same function (“sub” coming from “substitute”). The .replace() function even accepts functions, which compute the replacement string on the fly, so you can convert for instance Farhenheit into Celsius degrees with this function.
  • JavaScript Promises are objects, which represent some value that may or may not be delivered in the future. Either way, waiting for promises doesn’t block the execution of the other parts of the code. The concept comes from the Ajax technology, which made it possible to refresh some data on a web page without reloading the whole page. And “imitation is the sincerest form of flattery” again: “asynchronous programming” as they call it (I think the alternative name, “non-blocking”, or even “non-linear” conveys the idea more accurately though) is a hot topic in the Python community as well.

The jury is still out, which will be my favourite language in the future.

The JavaScript based React framework for developing user interfaces and data visualisation for instance seems to be promising. Though maybe for data science and AI, the Python based libraries are more suitable.

In any case, learning a second programming language, and get exposed to the fact, that similar concepts can be implemented different ways, is in itself very instructive.