News for hackers. Stuff that matters.
Re:Functional programming is finally going mainstream by ravi-delia on Tuesday July 12, 2022 @08:48PM (#32077719)
With immutable objects, aren't you just left with syntactic sugar around structs and functions? I'm picturing CLOS, which is undoubtedly an OO system but lacks 100% of what you use objects for. Are there languages which let you use dot-syntax for "methods" which just wrap normal functions?
Re:Functional programming is finally going mainstream by LAC-Tech on Tuesday July 12, 2022 @08:53PM (#32077753)
With immutable objects, aren't you just left with syntactic sugar around structs and functions?

Yeah I've gone down this thought experiment. Conclusion I came to is that while you could view it that way, there's something powerful about Just Having One Thing, not structs + functions. It's almost a mindset shift as well, like you're requesting the object to do something and don't care how.

Are there languages which let you use dot-syntax for "methods" which just wrap normal functions?

Yeah, Dlang has that.

https://tour.dlang.org/tour/en/gems/uniform-function-call-sy...

Re:Functional programming is finally going mainstream by ravi-delia on Tuesday July 12, 2022 @10:37PM (#32078443)
> It's almost a mindset shift as well, like you're requesting the object to do something and don't care how.

I definitely see what you mean, a lot of FP encourages very general abstractions rather than something domain specific. That being said, I think Elixir has a pretty good handle on using functions as sort of black-box interfaces you can change later. Not sure if that's a language thing or a culture thing though.

> Yeah, Dlang has that.

Ooo, that's really nice. Super simple but a definite improvement to readability. Reminds me of |> in Elixir (or ~> in Clojure), particularly the chaining part. It clicks differently though, and definitely makes things readable for many programmers. Now that I'm writing this out, doesn't Rust have something like this? Like functions strapped right to a struct?

Re:Functional programming is finally going mainstream by singularity2001 on Wednesday July 13, 2022 @04:11AM (#32080146)
I suggested this wonderful feature to julia but it was rejected:(

Glad to hear D has it.

as OP said it would make functional languages more ergonomic (especially for OO folks) and most importantly enable code completion!

Re:Functional programming is finally going mainstream by ChrisRackauckas on Wednesday July 13, 2022 @04:39AM (#32080278)
There already is a syntax for that: a |> bar |> foo
Re:Functional programming is finally going mainstream by singularity2001 on Wednesday July 13, 2022 @11:24AM (#32083981)
neat, thanks!

it's still a bit unergonomic to type but a very useful beginning!

Reminds me of hurting my fingers in c where you had to type '->' instead of '.' !

Re:Functional programming is finally going mainstream by raiflip on Tuesday July 12, 2022 @08:59PM (#32077790)
At that point you're left with two benefits: 1) Organizing your codebase so that it is easy to find which functions operate on which data 2) Controlling access to those methods on the programming language level. I.E, TankerService is the only class with Tanker instances and therefore the only part of the code with access to those methods.
Re:Functional programming is finally going mainstream by rq1 on Tuesday July 12, 2022 @08:56PM (#32077774)
Re:Functional programming is finally going mainstream by Jtsummers on Tuesday July 12, 2022 @08:51PM (#32077738)
What does CLOS lack that you want from an OO system?
Re:Functional programming is finally going mainstream by ravi-delia on Tuesday July 12, 2022 @10:31PM (#32078411)
Nothing! I mean I personally just use defstruct unless I want inheritance, but that's certainly not because CLOS lacks anything. I meant "you" as in the person I responded to, who wants immutable data structures with tightly coupled functions. It's because CLOS is among the most object oriented systems I know of that I used it as an example; there seem to be some basically orthogonal traits which nonetheless wind up highly correlated, and CLOS is the purest OO you can get this side of Smalltalk while looking different from what you see in Java or whatever.
Re:Functional programming is finally going mainstream by skavi on Wednesday July 13, 2022 @01:26PM (#32085898)
Koka has that [0].

a.f(b) == f(a, b)

[0]: https://koka-lang.github.io/koka/doc/book.html#sec-dot

Re:Functional programming is finally going mainstream by mypalmike on Tuesday July 12, 2022 @11:21PM (#32078698)
Dynamic dispatch is really what differentiates OO from just being syntactic sugar around structures and functions.