3 ms·
I got back into java recently and am appreciating how you can define an interface reference type super class then swap out the different data structure subclass
by abledon 7y ago
I got back into java recently and am appreciating how you can define an interface reference type super class then swap out the different data structure subclasses as their implementation. E.g. make a queue refer to either PriorityQueue or LinkedList. Or make a Map a HashMap or TreeMap. It kind of provides an "aha!" moment in deeper understanding of why there are so many Datastructures and why it actually matter to pick 1 over the other if in the end they are both implementing the same functionality. With python/js , yes those DS are still there but they are most of the time hidden for your convenience (which is great sometimes when you just wanna pump out some idea). The Accidental joy of Java (with its verbosity) is that by pushing the DS choice to time of reference setting, it makes me have to actually think about the choice more and what it would mean.
- lostcolony 7y agoThat's my contender for both biggest pro, and biggest con, of Java. Because where it breaks down is where the implementations are not clear, the tradeoffs are not clear, and the interfaces are not abstract enough to switch between (for instance, this useful library gives you a Future, and this other one requires a CompletableFuture).
- jkoudys 7y agoIf you're looking to go lower (systems) level, or even if you're not, rust is worth checking out then too. It's the best experience I've had letting you require only the interface that does what you need, and it's also great at letting you make a type "from" something. e.g. you could require something be a HashMap, or merely that it can be converted `Into` a HashMap (a free action if it's already a HashMap).
- crematoria 7y agoYep, sum and linear types are two of the biggest improvements of Rust over, say, C++. The third would probably be that it's a lot smaller than C++.