3 ms·
Having to write type names when defining variables is a tradeoff between ease-of-writing and ease-of-reading. When reading code in e.g. a book or a patch, where
by zetalyrae 5y ago
Having to write type names when defining variables is a tradeoff between ease-of-writing and ease-of-reading. When reading code in e.g. a book or a patch, where semantic tooling is not available, it helps to know the type of a thing.
My main complaint with Java verbosity is in the type declarations: everything is in triplicate (property names, constructor parameters, getters and optionally setters are all duplicated). The IDE can write these for you, but you still have to read that code.
Something that would be a five-line algebraic data type in Haskell becomes five files, each with a single anemic data class.
- scns 5y agoThis. After learning about ADTs through OCaml, i felt sad working in other languages that don't have them. Spoiled yes, but in a different way than the way the word usually gets used (bratty | pampered). I thought i'll have to stop learning advanced languages because it would make working a dayjob miserable, years before i had my first job. Making impossible states irrepresentable? Yes Please. Kotlin enabling an approximation through sealed classes and exhaustive, compile time checked, matching with when was noticed, gratefully. "You can take those ADTs from my cold, dead hands." - Yaron Minsky
- zetalyrae 5y agoDoubly so for building compilers, or compiler-like programs (a long chain of intermediate representations, with lots of little transformations from one to the next). Adding a new type of node, in a language with ADTs, leads to compile-time breakage I can fix. In a language where exhaustiveness errors are caught at runtime, it's like building on quicksand.
- kaba0 5y ago(Modern) java has ADTs. Sealed classes as sum types and records as product types. Full-blown pattern matching with destructors is coming.
- scns 5y agoThat is good to hear. How long will it take till developers, working in shops that contemplate their migration to Java 11, can use it? No snark intended.
- kaba0 5y agoJava has a huge user-base. Some will use it sooner, others will continue to use 8 for decades to come.
- vips7L 5y agoThis is a good question. From my observations, it feels like half the community is just following the "LTS" releases (11, and 17 next month). And then the other 50% is split between chasing the current release and forever being stuck on 8. It's really sad because JDK 8 really is an antiquated runtime. You're doing a disservice to your developers, users, and your $$ if you're still running it.