News for hackers. Stuff that matters.
Re:Functional programming is finally going mainstream by LAC-Tech on Tuesday July 12, 2022 @09:53PM (#32078148)
Just to steel man the "Functions and Data" side of the equation in a lot of FP languages that'd be something like

    newData = oldData |> f |> g |> h |> i |> j |> k
Re:Functional programming is finally going mainstream by vanjajaja1 on Tuesday July 12, 2022 @11:54PM (#32078878)
And to straw man the OO way a little...

newData = oldData.f().g().h().i().j().k()

wont work by default unless you also happen to return the object after every method (builder style) which looks weird and is not standard

Re:Functional programming is finally going mainstream by imtringued on Wednesday July 13, 2022 @03:20AM (#32079860)
I don't know what you mean. You can return a different type, the only constraint is that the methods don't return void and the subsequent method exists. This has nothing to do with the builder pattern.
Re:Functional programming is finally going mainstream by zelphirkalt on Wednesday July 13, 2022 @10:16AM (#32083052)
You still have to do work though, to ensure, that always some fitting object with the correct methods is returned, so that you can chain further. Functions by definition (as opposed to procedures) return something and as long as that is the correct thing or type of thing for the next function, all is fine.
Re:Functional programming is finally going mainstream by stickfigure on Wednesday July 13, 2022 @12:40PM (#32085145)
You don't have to do work; at any step you have the functions available that operate on the object returned (whatever it is). On the "Functions and Data" side you are similarly constrained by the possible functions that operate on that data.
Re:Functional programming is finally going mainstream by zelphirkalt on Wednesday July 13, 2022 @01:27PM (#32085906)
What I meant by "work" is, that inside your methods you have to return an object, which has the method, which is the next thing in your a().b().c()... chain. Often in OOP you would not return the object itself, unless you do the builder pattern. Of course you can return other objects, if it is intended, that the chain has a call to a method of another object next. However, you may only call methods of the returned objects and you must return objects.

In the function and data scenario, all that needs to be made sure is, that your functions have the return type, which the next function expects, otherwise it is a type error, regardless of whether the language complains or not. A function call chain implicitly assumes the types to be correct, otherwise you will likely run into an error.

The difference is, that in the functions and data scenario, you already have functions, which take data of some type and return data of some type. You do not change them in any way, while on the other hand with objects and methods you need to change the methods, so that they do return some fitting objects.

Re:Functional programming is finally going mainstream by LAC-Tech on Wednesday July 13, 2022 @04:42PM (#32088488)
There's no law stopping you returning a new object from a method outside the builder pattern.

Immutable objects are a pretty old idea, smalltalk had select (map) methods that returned a whole new collection back in the 80s.

Re:Functional programming is finally going mainstream by stickfigure on Wednesday July 13, 2022 @07:55PM (#32090233)
...and in fact most strings in OOP languages work like this:

    String next = original.substring(2);
Re:Functional programming is finally going mainstream by singularity2001 on Wednesday July 13, 2022 @04:08AM (#32080125)
this has nothing to do with OO, function chaining depends on the output of the previous function regardless