Why Modern Javascript Is the Future Language

8 minute read

Introduction

When I was working with HPC, I was trying to solve the biggest challenge impacting my experience. It wasn’t that Linux was a bit challenging, not because I took time to optimize my custom-made programs good enough to run them without bottlenecks, not even because I took time understanding various technologies. These stuffs weren’t my problem. The thing that was on my nerve most was Remote Access. Regardless of whether my computing node or workstation was 50 meters from where I was working in, a city away, or overseas, this was always my problem. Sure, if I do everything in terminal command prompts, this isn’t really a big problem. But my computations involved graphical stuffs like having to assay various structures and plots of micromolecules or view simulation rendering results. I tried using VNC, RDP, NX, X SSH Forwarding, even TeamViewer, all kinds of protocols for Linux remote access you name it. If a protocol compressed the screen, it had too much latency to be practical. If a protocol just sent the raw screen, the network bottlenecks the program and stutters. The closest comfortable experience that was satisfactory enough was Apache Guacamole, which used HTML5 technologies for clientless remote access. This was good enough for viewing simulation results, but was still painful for coding. Guess what saved my day? The JavaScript-based applications Jupyter Lab and both the open-source Eclipse Theia / code-server browser-based code editors each based on Visual Studio Code.

Major Languages

C/C++ has been the de-facto language for CPU/GPU-intensive high-performance computing applications for the past few decades (C and C++ are used for OpenCL, CUDA, and other GPU frameworks and steadilly holding more popularity compared to Fortran, which is still used for numerics but diminishing) and C# (coupled with the .NET framework dominating universal environment programming along with the Java Virtual Machine) has become the language for Windows desktop apps and games that touches less of complicated low-level aspects (while Julia, Go and Rust wants to replace C/C++ while being blazing fast enough for time-critical applications, it is not yet to a stage that can dethrone the languages except maybe Fortran). SQL has been the default framework for server-side databases as well. Python (which has Cython using C as its backend and thus able to accelerate only a certain time-critical part with C/C++) became the default language for data science overall (quickly replacing Excel, SAS, SPSS, Matlab, even the Wolfram Mathematica Computer Algebra System, etc) and all kinds of machine learning (led by scikit-learn, Tensorflow, Keras, PyTorch, and etc), as well as the universal language for interpreter-based object-oriented programming for coding learners (Visual Basic no longer the language for beginners), quickly replacing the position held by Java just a decade ago. The “pythonic” syntax and semantics are well-known as the standard for many modern languages to benchmark, and also widely emerging as the new server-side web programming language, replacing PHP (Wordpress is quickly losing ground nowadays). Java is still holding strong as the development language for Google’s Android OS, and Kotlin became the modern language (= for Android apps) that drastically simplifies the Java syntax while running on the Java Virtual Machine. R, Perl, Ruby each have their own niche but Python packages aim to cover even these niches. Shell (bash) and PowerShell are really obvious, you need knowledge of this to script Linux/Windows properly. Objective-C and the more recent Swift are keeping their presence as the language used for iOS apps. Scala (using the Java Virtual Machine) and Haskell are slowly superceding LISP as the more mathematics-tasted functional programming languages.

Programming Languages

Image by Stack Overflow Annual Developer Survey (2020), redistributed with open-source license from https://insights.stackoverflow.com/survey/2020.

JavaScript

Now you should see I missed out one big chunk of language intentionally. JavaScript, along with HTML/CSS. After around 2010 when HTML5 was first created, web development is no longer aesthetical site design or creating and embedding Flash animations which were people’s perceptions before HTML5. Since HTML5, web development became a programming technology just like Python, C/C++, Desktop or Android Java, and R. The concept of JavaScript changed with it, unleashing a concept called web applications instead of ancient code snippets that just compliment traditional websites. Websites since became applications joined by JavaScript engines embedded in then-new browsers Chrome, just like an Android/iOS app or a spreadsheet program installed on Windows. Trident and EdgeHTML engines (which were the rulers of the era before HTML5) are end-of-life, Webkit (still by Safari and all iOS browsers) forked to V8 (Node.js also internals of Chromium-based browsers) and Blink (Chromium-based browsers) and is the biggest decider of the internet, and Gecko (Firefox) is holding well as one of the major deciders of the internet standard with a history of almost 30 years since Netscape. Now I just made a spoiler: Node.js, enabling Javascript to be serverside just like Python, PHP, Java, and all other languages used for servers and standalone applications. Javascript is no longer a scripting language only embedded in a website. It became an interpreter language that is run in a local computer or as a server just like Python.

This has sparked the rise of decentralized client-side web applications like various web-based blockchain technologies executed inside the browser completely, but most importantly, stuff that was thought not able to be done in the browser are now very possible. Most of you wouldn’t have known that the Trident and EdgeHTML rendering engines (that has reached EOL with Internet Explorer and the legacy Microsoft Edge) is included in the Windows Explorer (default file browser for Windows), Control Panel (where you remove programs, manage printers, and what your CPU is), and many other default programs embedded within Windows. The relationship between web rendering engines and Operating Systems are expanding more and more, thus Trident has to be phased out for the security of the world. Microsoft has started doing so by moving the Microsoft Edge default browser to the same Blink and V8 engine and codebase Chromium and Chrome uses. Microsoft also published the Chromium-based WebView2 API to replace the web engines in Windows default programs, gradually being updated in a near release of Windows 10.

Electron

The Electron framework, developed by GitHub which was aquired by Microsoft, has been developed to use the server-side Node.js platform and create cross-platform desktop applications while using the same codebase to power web applications with near no difference in the experience. The text editors and partially IDEs Visual Studio Code and Atom, the chat and remote meeting applications Slack, Discord, Microsoft Teams, and Skype (also owned by Microsoft) are the most notable programs that use Electron. Electron has revolutionized program development. It is as fast as Python, and already went faster than PHP and Java in the modern multithreaded environment of servers and computers. So why don’t people make a desktop program or a server with the same language used to code in the web? Node.js and Electron is exactly what did this.

Let’s come back to my endeavor for a comfortable remote access environment. For most HPC workloads, even visual simulations, do not really need interactive control of all aspects of the GUIs. We aren’t doing interactive Youtube editing or Photoshop, instead most stuffs are tuning some parameters or putting in commands and small code snippets, and fetch results and tune stuff again. Video or image/plot results don’t really have to be seen interactively. So basically screen casting causes high latency and makes our heads fume without practicality. Jupyter Notebook and Jupyter Lab has introduced the concept of kernels of various languages (Python used most nonetheless) to the data science audience, which is a running instance of the server that can be executed and get results in small snippets by pausing while keeping the variables it had and continue again to the next code. This has really streamlined development in data science, and client-side JavaScript interfaces merged with the server-side Python kernels greatly improved user experience because GUIs like buttons and code snippets are edited client-side. This means that there is greatly less overhead in client-server communication over literally casting an encoded video of a remote screen. But we want more. We want a text editor or an IDE that can do remote tasks on a client-side interface. Recall Visual Studio Code, the open-source universal text editor that becomes effectively an IDE if linked with extensions and its own customizable environment coupled with virtualenv or conda, is already dominating the userbase of developers regardless of language, and was already made as a Javascript program. All that had to be done is put the same codebase into a web server. GitPod and its open-source backend Eclipse Theia, code-server, and the proprietary GitHub Codespaces and Visual Studio Codespaces are the results, web-based coding applications with the same experience as desktop.

Conclusion

This is a miniature change compared to how the web has evolving. People think Python is a server-side language binded to certain builds of installations. WebAssembly and Emscripten made browsers possible to execute C/C++ code by compiling to a browser-compatible version of Assembly and running client-side inside the browser without a large impact on speed. Tensorflow.js already utilizes the GPU (using WebGL that was originally designed to do in-browser 3D graphics and rendering tasks) of the local browser when integrated into a web application, and Pyodide (made possible by connecting the Cython backend of Python based on C/C++ codebase with WebAssembly and currently in its incubation phase) enables integrating all kinds of pure Python modules including data science inside the web browser. JavaScript and Python will now be effectively merged together to create purely client-side web apps. In conjunction with decentralized trustless integrity verification technologies like blockchains and IPFS, Content Delivery Networks that reduce the time of initial overhead caused by more hefty downloads of data and modules than before, FaaS, new languages complimenting JavaScript that resemble that of Kotlin to Java such as Dart, TypeScript, CoffeeScript, Elm, and others, JavaScript frameworks like React, AngularJS, Express.js, and Vue.js, and static site technologies like Jekyll (powering this website right now) and Gatsby will reduce the need of large servers in web environments completely.

It is truly the age of JavaScript. Flash is out-of-support from all major browsers from 2021 and no serious website uses Silverlight nor Java Web Start in 2020, opening the way only for JavaScript to expand more and more. This is the biggest reason of why JavaScript should be known as a universal language to everyone, even if the main languages they use are C/C++, C#, Python, R, Java, etc.

Comments