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.
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.
Oh, because your "FooWidgetController", "FooWidgetService", "FooWidgetRepository" are all real world things?
This is just data modeling, has nothing to do with OOP.
Summary by Wikipedia is pretty good:
>Object-oriented programming (OOP) is a programming paradigm based on the concept of objects,[1] which can contain data and code: data in the form of fields (often known as attributes or properties), and code in the form of procedures (often known as methods). In OOP, computer programs are designed by making them out of objects that interact with one another.
But also, from same wikipedia page:
>Attempts to find a consensus definition or theory behind objects have not proven very successful (however, see Abadi & Cardelli, A Theory of Objects[68] for formal definitions of many OOP concepts and constructs), and often diverge widely. For example, some definitions focus on mental activities, and some on program structuring.
https://en.wikipedia.org/wiki/Object-oriented_programming
But I also recommend reading the chapter on objects from "Programming Languages: Application and Interpretation" by Shriram Krishnamurthi. https://www.plai.org/3/2/PLAI%20Version%203.2.2%20electronic...
One sentence summary there is: "Objects — the bundling of data with operations over them — are a generalization of closures."
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.
You need expression orientation, immutability by default, persistent collections in the standard library, some way to handle monadic code, etc…
Neither are monads. There are entire FP languages without monads for effects (obviously, you can write a monadic interface in them, but it's not part of the idiomatic core). For example, clean uses linear types to control effects and purescript / Idris use a custom effect-system. So no, monads are not a requirement, and even if they are, modern c++ fully supports them, as does rust, javascript, etc. It's very common in javascript to use Array.map() and Array.flat().
I mean the bindings and collections. For example, when you make an array in JS, the default syntax is a mutable list with a mutable binding:
let xs = [ 1, 2, 3 ]
> Neither are monads. There are entire FP languages without monads for effects (obviously, you can write a monadic interface in them, but it's not part of the idiomatic core).I should be more precise - there needs to be some way to mange effects. Monads with syntax extensions is simply the most common (Haskell, Scala, F#, Closure macros)
> and even if they are, modern c++ fully supports them, as does rust, javascript, etc. It's very common in javascript to use Array.map() and Array.flat().
JavaScript does not have good monad support. This is why async/await was added as a new language feature. Yeah, I know you can hack together something with generator functions, but it’s hardly idiomatic.
But we’re getting into the weeds here. My point is: I don’t consider a language to support FP when writing functional code in that language leads to lots of friction compared to what is idiomatic.
Have you ever tried FP in Java? It works for some toy thing but then you hit the lack of TCO, or the ridiculously long type names (not inferred) or the pyramid of doom…
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.