Javascript to a strongly typed language..
What approach can one take to move an existing Javascript code base to a strongly typed language?
Published: Wednesday, Jan 19, 2022 Last modified: Wednesday, Oct 2, 2024
Less bugs wanted
There comes a time when a weakly typed Javascript project wants to adopt strong typing to improve quality and avoid bugs.
Given the choice:
- TypeScript by Microsoft
- The Go language (aka golang) by Google
What are the arguments for and against?
Pros of Typescript
- Assumed easier migrate an existing Javascript code base, doesn’t require a “rewrite”. However the process of getting Javascript 100% migrated isn’t as clear as it might be if you used Go. Update: Tools like https://github.com/alexcanessa/typescript-coverage-report might help!
Cons of Typescript
TypeScript is a scripting language for C# – https://twitter.com/coolaj86/status/1485166837163642883
- Tied to the Microsoft ecosystem
- Package dependencies are a mess, some have Typescript bindings, some don’t. Lots of blind spots.
- Lots of churn and difficult choices need to made wrt tooling
- Different Javascript styles can make the code base confusing
- Slow
- Some argue that Javascript with JSDoc is a better approach
Pros of Golang
- Simple, well-designed end to end ecosystem supported by Google
- Better error handling
- Faster performance, which can be further enhanced to concurrent execution (not limited to being single threaded)
- Far better package design
- Easier to maintain in the long run
- Produces static binaries which are easier to deploy
- Go can be learned in a weekend
- Moving between Javascript and Golang is actually suprisingly simple
Cons of Golang
The biggest con of Go isn’t that people don’t know it - it’s that they refuse to learn it. They’ll die with a cold, hard grip on their overly-complicated polymorphic inheritance systems and useless utility libraries. – https://twitter.com/coolaj86/status/1485167527814590465
- Less people know Go than Javascript
- Assumption that the JS isn’t front end code. Of course Go isn’t a browser language and hence JS is far better suited for dynamic frontends, e.g. using https://vuejs.org/
- Again if you have JS on the frontend, you might argue it’s easier to hire or form a cross-functional team that can switch between front and back end.