Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Programming languages are for peopleāāānot computers. Computers donāt need any programming language other than machine code. Good programming languages help make problems easier for people to reason about. This is important because writing code is not just about solving problems. Itās also fundamentally about how you think, communicate, and comprehend.
On the web today, we have one, dominant language: JavaScript. JavaScript was created because Marc Andreessen, ābelieved that HTML needed a āglue languageā that was easy to use by Web designers and part-time programmers to assemble components such as images and plugins.ā(1)
As front-end developers, we should not accept this. We should not allow ourselves to be restricted to one languageāāāespecially not a language, famously cobbled together in ~10 days that only has some āgood partsā. While Axel Rauschmeyer (for whom I have a lot of respect) may believe that itās a good thing for JavaScript to be a messāāāI couldnāt disagree more. We need languages that help us solve problemsāāānot languages that create more problems for us toĀ solve.
Language andĀ Idea
āThe words available in a programming language for expressing your programming thoughts certainly determine how you express your thoughts and might even determine what thoughts you can express.āāāāSteveĀ McConnel
Thereās an old joke that goes something likeĀ this.
In Heaven: the cooks are French, the lovers are Italian and the bankers are Swiss.In Hell: the cooks are English, the lovers are Swiss and the bankers areĀ Italian.
Along the lines of this joke, if we want to write well about cooking, we should write in French. While we might be able to write about cooking in English, we would be lacking in the vocabulary and paradigms present in French that are essential to cooking. And, in fact, if you know about cooking, you know this is true! There are many terms central to cooking that are specifically French. Even if you are writing an English cookbook, you use these French words (e.g., mise en place, Bain Marie, Coulis,Ā &c.).
The language that you work in has an impact on the way you think about and solve problems. To illustrate this, letās compare how currying works in Haskell with how it works in JavaScript. Weāll consider a simple currying function.
Hereās the HaskellĀ code:
In Haskell, functions are automatically curried. Currying is part of the Haskell paradigm. As a Haskell programmer, I know this. It influences every bit of code that I write. The way that I think about how to create a functionāāāi.e., solve problems and communicateāāāinvolves currying at someĀ level.
Hereās some JavaScript code that does more or less the same thing(2):
Currying is not implicit in JavaScript. If I want to use currying, I have to implement it. Then I have to use it explicitly. And there are a ton of implementationsā not counting the possibility that I might choose to implement it myself. Each implementation comes with its own costs and benefits.
Because I donāt have native currying, Iām having to deal with decisions I wouldnāt have to make in Haskell. In fact, if Iām trying to do Functional Programming in JavaScript, I may have to make many decisions like this. Each decision impacts my problem solving, and my code in severalĀ ways:
- Decision fatigue
- Multiple paradigms (the Ramda way, the Lodash way, the Folktale way, some random NPMĀ moduleā¦)
- More code to manage (more code to read and comprehend)
- etc.
As you can see, even from one small example, there are significant differences in the way that Haskell and JavaScript approach the same task. What is trivial and innate in Haskell turns out to be more involved, verbose, and alien in JavaScript.
To sum up, we can state our own version of Whitehead:
A good programming language, applied to the appropriate domain, can increase your problem solving ability. A bad languageāāāor one thatās a poor fitāāācan make thingsĀ harder.
Languages and ProblemĀ Solving
Knowing the impact of a language on problem solving and communication, it should come as no surprise that programming languages are often created to solve specific problems. A few examples:
- Ada was written to work with embedded and real-time systems.
- Erlang was designed to write telephony applications.
- ALGOL was designed to clearly describe algorithms.
- Pascal was written to teach students structured programming.
Modern web apps are written to solve a wide variety of problems. We should have a diversity of programming languages. We should be able to work with languages that were designed for our problem space, that fit our way of working with problems, or that we want to learn something from.
In short: Itās time to break free from just JavaScript.
We Can Do ThisĀ Now
Even though JavaScript is the only language supported by modern browsers, we can work with a wide variety of languages to build web applications today. Thanks to the work of many, well-supported projects there are a wealth of languages available that compile to JavaScript. There are even projects that support using those languages with popular frameworks like React and Vueāāāfor example, Reason-React, PureScript-React, Reason-Vue, andĀ others.
For a fairly comprehensive list of languages that compile to JavaScript, see Jared Ashkenasā GitHub list. The list includes all of theĀ .Net languages, Scala, Haskell, Ruby, Elm, Python, Erlangā¦ and on, and on. The number of languages represented on Ashkenasā list is so large that it suggests a companion to Atwoodās law: āIf a programming language exists, someone will write a tool to compile it to JavaScript.ā
The RoadĀ Forward
While there are a TON of languages that compile to JavaScript, this is not a perfect option. Compiling to JavaScript comes with knownĀ issues:
- Debugging compiled JavaScript can beĀ hard.
- If there are tools to help with debugging, many are immature (though Elmās debugger looks quite promising).
- Because of the conceptual differences between languages, certain concepts in one language may not translate well into JavaScript. This can impact performance and comprehension.
- Tuning and performance improvements to your scripts can be challenging.
- etc.
Innovation always comes with a cost. So does stagnation. The costs of stagnation are higher. If weāre going to make progress in front-end development, we must have more diversity. Someone needs to lead the way. When there are enough developers who use a given language in the web app space, there will be a motivation for the tool creators, vendors, and community to give their support. Even if we only end up with two or three dominant languages, weāll have richer vocabularies and paradigms to workĀ with.
Notes
- https://en.wikipedia.org/wiki/JavaScript
- This code example was taken from Steven Syrek. He wrote an article on learning Haskell using JS. You can access it here: https://medium.com/@sjsyrek/using-javascript-to-learn-haskell-f57509015842
- The topic of Language and Thought is a rich one. If it is interesting to you, you may enjoy this article: https://www.linguisticsociety.org/resource/language-and-thought
JavaScript No More was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.