News for hackers. Stuff that matters.
Re:The Gang of Four is Wrong and You Don't Understand Delega... by munificent on Tuesday August 14, 2012 @07:00PM (#4383509)
From Design Patterns (first edition):

> Delegation is a way of making composition as powerful for reuse as inheritance [Lie86,JZ91]. In delegation, two objects are involved in handling a request: a receiving object delegates operations to its delegate. This is analogous to subclasses deferring requests to superclasses. But with inheritance, an inherited operation can always refer to the receiving object through the "this" member variable in C++ and "self" in Smalltalk. To achieve the same effect without delegation, the receiver passes itself to the delegate to let the delegated operation refer to the receiver.

Sounds like they're perfectly clear and correct to me. As the author of the post points out the GoF don't actually show examples of delegation in the book and I don't recall them using the term much, so I don't see how they're perpetrating any misinformation here.

> In JS we can assign a prototype: the equvalent of the parent slot in Self.

No, .prototype is not equivalent to a parent slot in Self. It's closer to a traits object, I think. The unstandardized __proto__ property is equivalent to a parent slot in JS.

> Yeah, Design Patterns showed examples in Java. And Java can’t do delegation. So is that a valid argument for rewriting the meaning of a term?

Design Patterns is older than Java. Maybe later editions use it, but the original version used C++ and Smalltalk.

Otherwise, good troll post, original author. I'm sure you'll get lots of traffic and people noticing your book. Well played!

Re:The Gang of Four is Wrong and You Don't Understand Delega... by saturnflyer on Tuesday August 14, 2012 @07:11PM (#4383549)
Thanks for clarifying. I had most of it written before posting and had forgotten the code samples. My copy of Design Patterns is packed up for a move. I've update it to refer to C++.

Actually, people have visited, but few have stayed to read. My goal is to clarify the concept. I did plenty of research before writing this including asking Lieberman and others about it. I first wondered how everyone's notion could be wrong and doubted that my understanding was correct.

This is a term that others have attempted to clarify as well http://javalab.cs.uni-bonn.de/research/darwin/delegation.htm...

Re:The Gang of Four is Wrong and You Don't Understand Delega... by munificent on Tuesday August 14, 2012 @07:49PM (#4383672)
Clarifying the underlying concept is great. Self-style delegation gets to the heart of why "this" is dynamically bound in JavaScript, which is one of the language's most confusing features. Self-style delegation is also just generally cool and more people should know about it.

At the same time, getting hung up on terminology and trying to mandate a definition that goes against current usage just because it's older is a fool's errand and doesn't help.

Language is a social construct. It's very important for us to have consensus and agree on what words mean so that we can communicate efficiently. At the same time, there's nothing wrong about having definitions change over time.

"Car" used to mean a two-wheeled Celtic war chariot. It wouldn't be helpful to insist that it still mean that, and it's just mean to proclaim that everyone who uses "car" to mean "automobile" is wrong and doesn't understand the idea of war chariots.

Re:The Gang of Four is Wrong and You Don't Understand Delega... by scott_s on Tuesday August 14, 2012 @07:20PM (#4383579)
If you agree with munificent, then perhaps you could soften your title and introduction to say that many people confuse what the GoF meant, not that the GoF are wrong.
Re:The Gang of Four is Wrong and You Don't Understand Delega... by saturnflyer on Tuesday August 14, 2012 @07:46PM (#4383662)
good point. I'll verify the citation and update it.