Static types are sanity when the people and years keep increasing. It isn't at all important in small one man projects since most of your defined types are in your head in any case. There is nothing wrong with JavaScript as a language beyond it's, originally questionable, foundations that have since been iterated upon (much like PHP). As a massive fan of static typed languages. There is no denying that dynamic typed…
Ask HN: Changing my mind about JavaScript
41–50 of 73 posts
Re: Ask HN: Changing my mind about JavaScript
#42Re: Ask HN: Changing my mind about JavaScript
#43For the base language I recommend Dr. Axel Rauschmayer's books (https://exploringjs.com/) as they're kept very much up to date.
Where things get really interesting is TypeScript, which takes all of this dynamism and manages to model it with a type system that doesn't feel all that constraining. It also ameliorates most of the core language papercuts. I don't really have good recommendations for TypeScript for now, other than browsing typescript issues and pull requests for examples written by Anders Hejlsberg
You have to be very careful with the library and tooling ecosystem, however. There are a billion ways to do things, many of them incompatible with each other, and things break all the time. This includes major, popular libraries and frameworks with good looking documentation websites, so it can be difficult to pick something solid and stable. This is where most of the pain of using JS comes from.
Re: Ask HN: Changing my mind about JavaScript
#44Scripting languages are faster for prototyping but they are a nightmare for maintenance. TypeScript might look like a good middle ground but the many escape hatches really allow you a single bad coder to wreck havoc in your codebase. You can't trust a codebase you don't know in TypeScript the same way you would trust a Rust codebase.
JS is good for job security because the node.js hype cycle brought a lot of JS in enterprise places - it's been used for massive codebases and now there are plenty of microservices nobody wants to touch or know how to debug. The rise of horrible, enterprisey frameworks (eg. NestJS) helped this. JS could be the COBOL of the next generation, if it weren't for the web, which will likely keep JS alive for a long time.
If you really want to learn JS, focus on the good parts.
Avoid classes and `this`, avoid prototypal inheritance.
Postpone the frontend as much as you can as that changes every 5 minutes.
Start with bun (if you have no dependencies on node, it's not really compatible), so you'll have no issues with imports / require and all the tooling / transpiling (which rightly give JS a bad name)
Re: Ask HN: Changing my mind about JavaScript
#45While I lean on the static languages front, I am a big fan of dynamic languages as well, like Smalltalk and anything Lisp.
In regards to JavaScript, it isn't the Scheme/SELF we wanted, it is what we got and already quite powerful.
Some advanced stuff, how prototype inheritance works, how the new class model is actually mostly syntax sugar on top of prototype inheritance and not really Java like even if it looks similar, how decorators work (not yet fully there but will come), JIT and GC across the various runtimes, if care about server code how to write native extensions for the various runtimes.
Re: Ask HN: Changing my mind about JavaScript
#46https://www.destroyallsoftware.com/talks/wat
C has lots of uglyness and quirks but it has the excuse of being ancient - when people knew less. Zig/Hare are attempts to revisit the space with cleaner designs
Somehow several decades later something even more gross was created. No thanks. And the "well just stick to the good parts" stinks of C++
Thankfully there's Clojurescript if I ever need to touch the browser
Re: Ask HN: Changing my mind about JavaScript
#47I would recommend getting your head around closures. It’s possible to statically determine what variables exist in which scope, and so if you can nail down those rules it makes analyzing code much easier.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Clos...
I would recommend a light linter. I see too much new JavaScript code using `var` written by non-JS devs in 2024.
But I don’t think you need TypeScript if you’re first learning the language. Instead, revel in the dynamically-typed flexibility, and learn the error messages JS gives. There are only really 4 or 5 things that will cause JS to error, which can make debugging difficult initially, but once you learn those error messages, it makes debugging comparatively easy.
Re: Ask HN: Changing my mind about JavaScript
#48Re: Ask HN: Changing my mind about JavaScript
#49JS is broken and TypeScript is a way of fixing it but at the end of the day, you use Frameworks anyway like Anguular. If you just want to hack around it, hey just use it as any other scripting language
Re: Ask HN: Changing my mind about JavaScript
#50JS is broken and TypeScript is a way of fixing it but at the end of the day, you use Frameworks anyway like Anguular. If you just want to hack around it, hey just use it as any other scripting language
JS isn’t any more or less broken than every other language under the sun
JS has also missing features and semantic which got added through typescript.
I don't want to dismiss langauges because of this but saying 'every other language' is not true and not true in an objective sense either.