News for hackers. Stuff that matters.
Re:Modern Javascript: Everything you missed over the last 10... by hn_throwaway_99 on Saturday May 15, 2021 @03:19PM (#27168048)
This biggest "aha" benefit I get from TypeScript is that it is structurally typed, while Java is nominally typed. In my experience it has proven much easier to refactor in TS because I just need to ensure my objects have all the right properties. With Java if I have a Thing1, but a library is updated to add just a single new property so now there is a Thing2 type, well now then all the places I need a Thing2 I have to completely copy over from Thing1 - I can't just add the property and be on my merry way. This happened to me many times in my Java career - I still think I have PTSD having to do a Jersey 1.x upgrade to a Jersey 2.x version across a large codebase. It was a nightmare I've never had anything come close to with Typescript.

> I mean, this is a web-first language that has no concept of sending objects over the wire.. okay then.

I have no idea what you're talking about here. I use GraphQL with auto typegen of my TS types and I get typed data objects everywhere.

> TypeScript's generics system is cute, but I think it's mostly academic.

TBH this remark just makes me thing you really don't know much about TS. I use generics extensively, find them very helpful and are easy to use.

I'll give you the point on initial TS setup being non-trivial. Hopefully advances in tooling (things like Deno, which I'm not actually a huge fan of, or other projects like Rome) will make this easier, but even then I found this to be a "one and done" cost.

Re:Modern Javascript: Everything you missed over the last 10... by layer8 on Saturday May 15, 2021 @05:07PM (#27169030)
There is a reason for nominal typing though, because nominal types represent an interface contract that generally goes beyond just having the right type signature, but instead it is also about semantics. It's about the parts not covered by the type system, which the compiler therefore can't check. It depends on the kind of objects you are generally working with, but beyond pure data I find nominal typing preferable, because it makes it explicit that an implementation X conforming to interface contract Y is not just a matter of type signatures.
Re:Modern Javascript: Everything you missed over the last 10... by eurasiantiger on Saturday May 15, 2021 @04:12PM (#27168570)
Note that the upgrade pain with Java was not due to typing; rather, it was due to using a library directly instead of creating a class to interface with it. In other words, inadequate abstraction.
Re:Modern Javascript: Everything you missed over the last 10... by hn_throwaway_99 on Saturday May 15, 2021 @09:28PM (#27170448)
> Note that the upgrade pain with Java was not due to typing; rather, it was due to using a library directly instead of creating a class to interface with it. In other words, inadequate abstraction.

I'd look into what Jersey actually is before you say something like this, because what you've said really doesn't make sense.

Re:Modern Javascript: Everything you missed over the last 10... by eurasiantiger on Sunday May 16, 2021 @09:02AM (#27173426)
How so?
Re:Modern Javascript: Everything you missed over the last 10... by spiderice on Sunday May 16, 2021 @12:33AM (#27171255)
Yikes, is this really the expected way to do things in Java? That sounds frustratingly verbose. But I guess that is expected with Java.
Re:Modern Javascript: Everything you missed over the last 10... by 8note on Saturday May 15, 2021 @08:17PM (#27170135)
I find that making those classes is a pain in java, but really easy in typescript