Fullstack web languages
In web development there have been many attempts to unite the code running on the server and the code running in the browser. There are variety of approaches, here I explore some of the approaches and the latest developments in the fullstack world.
Embedding runtime environments
In the beginning a simple solutions was to create a browser plugin which would run your native code inside a sandbox. One of the main downsides was that the plugin had to be installed by users before it would run. Current project examples include:
- Java Web Start allows you to embed Java in the browser
- Brython allows you to embed Python in the browser
Compiling code from one language into another
Another popular approach was to transpile/compile your code to a language which the browser supports. Examples include:
- Transcrypt compiles Python to JavaScript
- jsweet compiles Java to JavaScript
- EmScript compiles C to WebAssembly
However both these approaches have limitations to the features which are available, and still require knowledge of multiple languages in order to create end-to-end web application.
We now have a viable third approach which has the potential to offer the same language everywhere and code sharing between backend and frontend.
Fullstack JavaScript
With the rise of JavaScript on the server with NodeJS, and JavaScript in the browser both improving runtime performance. Is fullstack JavaScript finally the holy grail of web development?
Advantages:
- Write one language everywhere
- Reuse code and libraries between frontend and backend
- Development time saved, no compilation needed
- Runtime performance has massively improved (check performance tests)
- Efficiencies of working on frontend and backend features together
Disadvantages:
- JavaScript language itself has it’s flaws/issues, is not opinionated enough and can be written in many ways.
- By handling frontend and backend code, you as a developer may not become a specialist in either.
- Temptation to use Isomorphic JavaScript could make your stack less scalable and potentially cost more to run.
Fullstack TypeScript
Now imagine if we could take all of the advantages of Fullstack JavaScript, but somehow mitigate some of them? TypeScript has some useful features which eliminate pain points of working with JavaScript.
Additional advantages:
- More opinionated type system and coding styles make code cleaner
- Easier to share code between developers as it will look more similar between them.
- Supports the latest features, and can be compiled to support older browsers
- Fast compile time
- Can be used alongside JavaScript if needed
I’ve created a simplified example project to show how easy fullstack TypeScript web applications can be with this approach. It uses:
- TypeScript 3.7.x
- Express 4.17.x
- ts-node-dev 1.0.x
In a future blog post I’m planning to go into more depth about the best TypeScript libraries and frameworks, so stay tuned!