by silvestrov · 2y ago · 0 comments
But "Functional programming approach" has been subsumed into existing programming languages, e.g. records in Java. You get most of the benefit of FP while keeping all of the other good stuf from an imperative language.
Records are basic data modeling and something that has been around since the beginning of programming languages, whether procedural or functional. It's one of the bare minimums of having a type system, and Java didn't have this due to the misguided belief that "everything is an object". I think records being added is more of a symptom of that belief weakening.
There are functional features that have made it over to Java which are the things related to functions, i.e. lambdas and such which are a welcome addition.
Many people would define an object as something that has externally visible behavior and internally hidden _data_. Objects could never be compared to each other for equality, because one could not access the internal data, only its public behavior. However, Java records can be compared for equality which objects would not.
Java records also cannot be extended from. Inheritance is the only uniquely OOP feature, which doesn't apply here either.
So I'm not sure that Java records are an object-oriented construct. First, the precise definition of OO should be established, and then we'll see
Records can have no state - compared to regular classes - so they are an anti-OOP feature.
Pure functional programming seems tempting. In small projects it can produce beautiful, readable code. In large projects I've only seen it result in messes, and I still haven't decided whether that's due to limitations of functional purity, due to the team (and myself) misusing features that we don't understand, or both.
If you try to write mostly pure code in Java I’m afraid you’re in for a bad time, despite the (big!) improvements of records and lambdas.
Minimum viable FP starts at OCaml, F#, Scala and Closure, yet none of these are mainstream.
However, most developers wouldn’t understand, say, a result monad implemented via LINQ, so you’re still fighting the ecosystem somewhat.
Functional programming means functions are first class citizens and can be constructed on the fly. Modern python, c++, rust, even java now do this.
Purity is a nice to have (and arguably rusts borrow system enforces a kind of purity).
FP is much more than this one language feature.
java.time
Valhalla even
Aren't these just C structs?
> You get most of the benefit of FP
FP = Functions. Same output for the same input. No capability to interfere with (or to be interfered with) other functions.
Are C structs guaranteed to be immutable at compile-time?
Sure, technically a single computer's local RAM is being managed with strict guidelines, but that correlates less and less to overall application state and behavior these days.
The problem is that nobody made an usable FRP system yet. It's not obvious why it's so hard, and everything feels like it should be easy. But everybody just keep failing.
Knowing that a small collection of functions is not referentially transparent is better than having to deal with any part of the program potentially changing your state.
The real world is messy and stateful.