2 ms·
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
by LAC-Tech 4y ago
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-syntax-ufcs https://tour.dlang.org/tour/en/gems/uniform-function-call-sy...
- ravi-delia 4y ago> 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?
- singularity2001 4y agoI 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!
- ChrisRackauckas 4y agoThere already is a syntax for that: a |> bar |> foo
- singularity2001 4y agoneat, 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 '.' !