Remix.run Logo
hyperpape 2 days ago

> Object-oriented (OO) patterns get a lot of flak in the Go community, and often for good reason.

This isn't really an OO pattern, as the rest of the post demonstrates. It's just a pattern that applies across most any language where you can make a distinction between an interface/typeclass or whatever, and a concrete type.

discreteevent 2 days ago | parent | next [-]

> distinction between an interface/typeclass or whatever, and a concrete type.

This is the essence of OOP.

"The notion of an interface is what truly characterizes objects - not classes, not inheritance, not mutable state. Read William Cook's classic essay for a deep discussion on this." - Gilad Bracha

https://blog.bracha.org/primordialsoup.html?snapshot=Amplefo...

http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf

9rx 2 days ago | parent [-]

> The notion of an interface is what truly characterizes objects

Objects, but not OO. OO takes the concept further — what it calls message passing — which allows an object to dynamically respond to messages at runtime, even where the message does not conform to any known interface.

discreteevent 2 days ago | parent | next [-]

The object has a known interface in this case. It's just not statically defined. Its interface is the set of messages that it responds to.

9rx 2 days ago | parent [-]

Not quite. With OO, there is no set. An object always responds to all messages, even when the message contains arbitrary garbage. An object can respond with "I don't understand" when faced with garbage, which is a common pattern in OO languages, but it doesn't have to. An object could equally respond with a value of 1 if it wants.

Dynamic typing is a necessary precondition for OO[1], but that is not what defines it. Javascript, for example, has objects and is dynamically typed, but is not OO. If I call object.random_gibberish in Javascript, the object will never know. The runtime will blow up before it ever finds out. Whereas in an OO language the object will receive a message containing "random_gibberish" and it can decide what it do with it.

[1] Objective-C demonstrated that you can include static-typing in a partial, somewhat hacky way, but there is no way to avoid dynamic-typing completely.

za3faran 2 days ago | parent | prev [-]

golang allows for the same

2 days ago | parent [-]
[deleted]
za3faran 2 days ago | parent | prev [-]

The ironic thing is that golang itself is OO.

9rx 2 days ago | parent [-]

It is not. The only languages (that people have actually heard of, at least) that are OO are Smalltalk, Ruby, and Objective-C. Swift also includes OO features, enabled with the @objc directive, for the sake of backwards compatibility with Objective-C, but "Swift proper" has tried to distance itself from the concept.

Go channels share some basic conceptual ideas with message passing, but they don't go far enough to bear any direct resemblance to OO; most notably they are not tied to objects in any way.