3 ms·
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
by hn_throwaway_99 6y ago
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.
- eurasiantiger 6y agoNote 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.
- hn_throwaway_99 6y ago> 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.
- eurasiantiger 6y agoHow so?
- spiderice 6y agoYikes, is this really the expected way to do things in Java? That sounds frustratingly verbose. But I guess that is expected with Java.
- layer8 6y agoThere 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.