It is really hard to write good software in Javascript
Six years of building Golang services gave me fewer race conditions than one year of writing Javascript. I have spent that year on vidstudio.app , an in browser client only video editor, which means I have had to write a lot of Javascript and have come to the conclusion that it is in fact a challenging language to master. The worst part is how easily I got there. Most of those races I introduced…
Despite six years of experience building Golang services, the author found that writing Javascript for vidstudio.app, an in-browser video editor, presented significant challenges. The worst of it was the ease at which race conditions occurred, often unnoticed. The author's most enlightening experience came when replacing a dependency in the export pipeline, which involved demuxing, decoding, drawing, applying effects, encoding, and assembling a video file.
The original dependency, mp4box.js, was a demuxer but also capable of muxing, returning a synchronous result which simplified the coding process. However, the new muxer, mediabunny, returned a promise, forcing the author to explicitly handle the sequencing of the assembly process. This change highlighted the stark contrast between Javascript's asynchronous nature and the more predictable linear execution of languages like Golang, C++, C#, and Java.
Javascript's asynchronous I/O operations, even when not desired, necessitate explicit handling to maintain correct and efficient code. The author emphasizes the importance of understanding Javascript's event loop, which manages asynchronous operations, but notes that it adds an additional layer of complexity compared to other runtimes.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.