Live data from Hacker News

Ask HN: Changing my mind about JavaScript

news.ycombinator.com

41–50 of 73 posts

Re: Ask HN: Changing my mind about JavaScript

#41
post #19

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…

Type safety is important but 80% of the infra is built on bash :rolleyes:

Re: Ask HN: Changing my mind about JavaScript

#43
There is honestly not much to learn, and that might be part of the appeal. At its core, JS is a relatively simple dynamic language with a clean syntax. Despite the clean syntax there are quite a few quirks in how some of the internals work (sorting and pervasive string comparison and casting, equality operator, etc). The most interesting thing about it is probably the programming model of free-form objects and closures: rather than using classes, you could write functions that return free-form records containing functions (and getters) that close over the lexical scope of the function. This gives a kind of dynamic object construction flexibility without the additional boilerplate.

For 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

#44
I've been doing JS for 18 years. I don't think it particularly deserves to be learned but I think in general you should know a scripting language and JS is very popular (and can be embedded with v8 isolates fairly easily). If you know python or lua I wouldn't bother. Lua would probably be my first choice.

Scripting 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

#45
I have started with a dynamic language with optional typing (BASIC), back in 1986, went through several static and dynamic typing throughout the years.

While 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

#46
I don't write JS, but the Wat talk makes me want to stay as far away as possible

https://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

#47
JavaScript is one of my favorite languages. It has the nearly unique design constraints of having multiple implementations and being unwilling to break backwards compatibility, which gives it a lot of warts that are easy to ridicule. But I think the language on the whole is very flexible, very simple, and very usable.

I 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

#49

JS 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

Re: Ask HN: Changing my mind about JavaScript

#50

JS 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

PHP has a lot of issues in comparision to java and other languages.

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.

Post reply on HN