3 ms·
Thanks for the two upvotes so far! Please feel free to leave criticism of the article or my writing; I'm trying to strengthen my composition muscle.
by Jaxkr 5y ago
Thanks for the two upvotes so far! Please feel free to leave criticism of the article or my writing; I'm trying to strengthen my composition muscle.
- zodiakzz 5y agoYour jab at TS was lame as Java itself has complete type erasure for generics. >by crystallizing type definitions and guaranteeing type guards by default. Not so crystallizing if you know.. if you've ever used a Java List, Set or a Map. i.e., List<icouldbeanythinginhere>. such guarantee. wow. Honestly, I'd prefer TS with strict mode over Java any day because nullability is explicit, don't have to watch out for the dreaded NullPointerExceptions left and right.
- Jaxkr 5y agoThank you, good point. I forgot about HashMap's type unsafety even though I wrote the following monstrocity a few days ago to loop over a HashMap<UUID, ExpiringEntityPlayer> Iterator ghostI = hashtableNPCs.entrySet().iterator(); while (ghostI.hasNext()) { ExpiringEntityPlayer expiringEntityPlayer = (ExpiringEntityPlayer) ((Map.Entry) ghostI.next()).getValue(); } Apparently this is the only way to do it, and the Map.Entry type absolutely nukes any semblance of type safety.
- cesarb 5y agoYou are supposed to use generics: Iterator<Map.Entry<UUID, ExpiringEntityPlayer>> ghostI = hashtableNPCs.entrySet().iterator(); while (ghostI.hasNext()) { ExpiringEntityPlayer expiringEntityPlayer = ghostI.next().getValue(); } However, it's a sham. The generic types are stripped at runtime. The compiler will prevent you from putting values in the map that are not an ExpiringEntityPlayer, as long as you are diligent in using generics everywhere, and don't fall in the few traps where the wrong type can slip by without a warning, but you can still be hit by a ClassCastException at runtime if you're not careful.
- tpxl 5y ago> but you can still be hit by a ClassCastException at runtime if you're not careful. While it is true the generics are more or less syntactic sugar, I have never seen a ClassCastException due to this in all my years.
- twic 5y agoThis is exactly like saying all types in C or C++ are a sham because you can cast a typed pointer to a void pointer.
- oftenwrong 5y agoIn modern Java there are more terse APIs available. For example: hashtableNPCs.values().forEach(ExpiringEntityPlayer::something);
- baby 5y agoYou def. are doing well with both title and content, controversial stuff always has an audience. I would just recommend learning another programming language :)
- da39a3ee 5y agoI'm curious which editor/IDE you used while writing typescript? I've recently started writing typescript and I've been finding it more or less a mecca of good editor completions and LSP support, compared to what I was doing previously (Python in an old school editor) (I'm using VS Code for typescript).
- twic 5y agoOne thing to bear in mind as you read the comments is that the great majority of people commenting clearly do not have good up-to-date experience of working with Java. They're arguing against the Java that they used a decade ago, or perhaps even just repeating flames they read a decade ago.
- marcodave 5y agoThe INCREDIBLY VAST majority of people that are working with Java/JVM for a living most likely have never even heard about HN. And yes, there are countless shitty projects in maintenance mode maybe even written in pre-1.5 Java. If I were stuck in such projects for years I would also be super-bitter about Java