4 ms·
OTOH, It does seem like magic if you have dealt with Java in your previous life
by abc_lisper 4y ago
OTOH, It does seem like magic if you have dealt with Java in your previous life
- karmakaze 4y agoI dunno if I'd say that. At least using recent versions of Java and some F#, I find the latter much nicer, but don't do things so extremely differently. It's just more concise and less keyboard typing when refactoring. Having worked with Rails codebases I tend to avoid magic when not needed. The best effect is using FP, then going back to what you used before and adopting more FP style: single assignment to local vars, immutable datastructures, less imperative control flow, etc.
- pharmakom 4y agoThe major differences between Java and F# are: - Discriminated unions and pattern matching - Global type inference - Tail call optimisation - Syntactic sugar for monadic code (computation expressions) Java is more “FP” than it used to be, but it is still not minimum viable FP
- kaba0 4y agoJava has sum types and is in the process of getting pattern matching (some basic form is already available, but `case Sphere(Point(int x, var y), var r)` already works in preview). For sum types, the syntax is like this: sealed interface Expression permits Add, Mult, Identifier {} // possibly later record Add(Expression a, Expression b) extends Expression {} record Identifier(String name) extends Expression {} I do like global type inference, but for anything that gets committed I often come to prefer at least Rust’s restriction of top level definitions needing types, as that aligns well with how I would also write Haskell and alia. Java imo made a good decision of only adding optional local inference, anything else would have been too disruptive for Java, given its existing talent pool’s background.
- karmakaze 4y agoDefinitely I would not call Java an FP language, even Rust has a flavoring of FP. Besides the monadic constructs not having proper sum types/d.unions is really annoying. Sealed enums are not the same utility.