Remix.run Logo
DavidPiper 6 days ago

So much gold to mine in this talk. Even just this kind of throwaway line buried deep in the Q&A:

> I prefer to write code in a verb-oriented way not an object-oriented way. ... It also has to do with what type of system you're making: whether people are going to be adding types to the system more frequently or whether they're going to be adding actions. I tend to find that people add actions more frequently.

Suddenly clicked for me why some people/languages prefer doThing(X, Y) vs. X.doThing(Y)

shuaiboi 5 days ago | parent | next [-]

bjarne (creator of c++) has a quote about this:

Unified function call: The notational distinction between x.f(y) and f(x,y) comes from the flawed OO notion that there always is a single most important object for an operation. I made a mistake adopting that. It was a shallow understanding at the time (but extremely fashionable). Even then, I pointed to sqrt(2) and x+y as examples of problems caused by that view.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p19...

Ferret7446 3 days ago | parent | next [-]

The flaw here isn't OO, but the idea that it should be applied in all cases. The point of OO methods is to control access and mutation of an object's private members. Rather than have clients know to, e.g., lock specific fields before accessing, you expose a method that handles the locking appropriately.

saghm 5 days ago | parent | prev | next [-]

The main benefit of x.f(y) IMO isn't emphasizing x as something special, but allowing a flat chain of operations rather than nesting them. I think the differences are more obvious if you take things a step further and compare x.f(y).g(z) and g(f(x, y), z). At the end of the day, the difference is just syntax, so the goals should be to aid the programmer in writing correct code and to aid anyone reading the code (including the original programmer at a later point in time!) in understanding the code. There are tradeoffs to using "method" syntax as well, but to me that mostly is an argument for having both options available.

atsbbg 5 days ago | parent | next [-]

That's exactly the context of where this quote comes from. He wanted to introduce Unified call syntax[1] which would have made both of those equivalent.

But he still has a preference for f(x,y). With x.f(y) gives you have chaining but it also gets rid of multiple dispatch / multimethods that are more natural with f(x,y). Bjarne has been trying to add this back into C++ for quite some time now.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n44...

saghm 5 days ago | parent [-]

That makes sense! It wasn't immediately obvious to me from the context of this discussion though, since it seemed like you were responding to the parent comment's framing of it as a choice between one or the other. This might just be from me never having heard of the term "unified call syntax" though, and I admit that I didn't expect to need to read through the PDF you linked before super carefully after opening it and seeing a bunch of C++-specific details that I knew would go over my head. (On a good day, I can remember what words SFINAE is an acronym for, but I don't think I ever really felt like I got comfortable enough with C++ to fully understand how the template code I saw actually encoded behavior that fit what I'd expect those words to mean).

nickitolas 5 days ago | parent | prev [-]

If my memory isn't failing me, that was part of the reason rust went with a postfix notation for their async keyword ("thing().await") instead of the more common syntax ("await thing()")

saghm 5 days ago | parent [-]

Yep, and that itself was similar to the rationale for introducing `?` as a postfix operator where the `try!(...)` macro had previously been used. In retrospect, it's kind of funny to look back and see how controversial that was at the time, because despite there being plenty of criticism of the async ecosystem in once, the postfix `.await` might be the one thing that seems to consistently be praised by people needing to use it. People might not like using async, but when we do use it, it seems like we're pretty happy with the syntax for `.await`.

ivanjermakov 5 days ago | parent | prev [-]

There is the most important argument regardless, whether it is a method or regular function - first one (or last one in languages supporting currying). While it's true that there are functions with parameters of equal importance, most of them are commutative anyway.

BoiledCabbage 6 days ago | parent | prev | next [-]

More info on "The Expression Problem" https://en.wikipedia.org/wiki/Expression_problem

robertlagrant 5 days ago | parent | prev | next [-]

> Suddenly clicked for me why some people/languages prefer doThing(X, Y) vs. X.doThing(Y)

It's when you start writing ThingDoer.doThing(X, Y) that you begin questioning things.

morkalork 5 days ago | parent | next [-]

But if you make it thingService.doThing(x,y) you're all good.

phlakaton 4 days ago | parent [-]

In Go, of course, thingService would implement the interface Thinger.

LearnYouALisp 5 days ago | parent | prev [-]

Excuse me, you need a BeanShell.BeanThread.GeneratorStalk.VeggFactory to do that in this Environment®™

ahonhn 4 days ago | parent | prev | next [-]

This mention of verbs reminds me of Steve Yegge's blog post "Execution in the Kingdom of Nouns" from 2006.

https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo...

pjmlp 5 days ago | parent | prev [-]

There are OOP languages that use doThing(X, Y), though.

Ada, Julia, Dylan, Common Lisp for example.

Yet another example why people shouldn't put programming paradigms all into the same basket.

virgilp 5 days ago | parent | next [-]

There are a handful of (somewhat exotic) languages that support multiple dispatch - pretty much, all those listed by you. None of the mainstream ones (C++, Java, C# etc) do.

(also Common Lisp is hardly a poster child of OOP, at best you can say it's multi-paradigm like Scala)

olvy0 4 days ago | parent | next [-]

C# does support a form of multiple dispatch, through the dynamic keyword. Used it myself for writing a parser.

https://shawnhargreaves.com/blog/visitor-and-multiple-dispat...

pjmlp 5 days ago | parent | prev | next [-]

I guess Julia and Clojure are exotic.

Since when do OOP languages have to be single paradigm?

By then point of view, people should stop complaining about C++ OOP then.

virgilp 4 days ago | parent [-]

> Since when do OOP languages have to be single paradigm?

What I really meant to say with that was that it's lisp at its core -i.e. if one wants to place it squarely in one single paradigm, imo that one should be "Functional".

I was just surprised to see it listed as an example of OOP language, because it's not the most representative one at that.

pjmlp 4 days ago | parent [-]

The Art of Metaobject protocol was written and researched in Lisp.

Provides an OOP programming model, that no mainstream language, other than Common Lisp fully supports.

https://en.m.wikipedia.org/wiki/The_Art_of_the_Metaobject_Pr...

Dylan, Julia and Clojure only have subsets of it.

igouy 5 days ago | parent | prev [-]

Multi-methods do seem like a missed opportunity:

"Visitor Pattern Versus Multimethods"

https://nice.sourceforge.net/visitor.html

pjmlp 4 days ago | parent [-]

At least we have Julia and Clojure as more mainstream versions of them.

Still it isn't CLOS.

saghm 5 days ago | parent | prev [-]

Yeah, the dot operator is not a particularly strong signal of whether something is OOP or not. You could change the syntax of method calls in OO languages to not use the object as a prefix without the underlying paradigm being affected.