Live data from Hacker News

The Gang of Four book is wrong about delegation (2012)

saturnflyer.com

11–20 of 26 posts

Re: The Gang of Four book is wrong about delegation (2012)

#11

> If the message is delegated further, all questions about the values of variables or requests to reply to messages are all inferred to the object that delegated the message in the first place. I'm not sure how the author jumps from that quote to: > When that object delegates to another, then any reference to "self" always refers to the original message recipient. Always. The high-order bit is that the delegating obj…

From what I can tell, this is a whole lot of bickering about the difference between prototypical languages (like JS) and inheritance-based OO-languages (like C++/Java/C# etc).

The Gand of four wrote Design patterns for the inhertance-based world, because that was what was churning out most business software and had the biggest need for some standard patterns and conventions. And they used (reused?) the word delegation to fit a useful pattern in a non-prototypical language.

And AFACT that's his argument. That all modern OOP languages got it wrong. So they got delegation wrong too. And GOF got it wrong because the wrote it for modern OOP.

Or did I miss anything?

Re: The Gang of Four book is wrong about delegation (2012)

#12

> If the message is delegated further, all questions about the values of variables or requests to reply to messages are all inferred to the object that delegated the message in the first place. I'm not sure how the author jumps from that quote to: > When that object delegates to another, then any reference to "self" always refers to the original message recipient. Always. The high-order bit is that the delegating obj…

That is probably because what he and we are talking about here is the technical definition of "delegation". If you just call a method of another object and then that object perhaps but not necessarily sends some messages back to the original sender, to get further information, that could conceptually be seen as "delegation". But technically that's just normal (bi-directional) message-exchange. "Delegation" needs to r…

For languages which didn't have function-pointers as a first-class construct (like Java), you had to create another way to delegate functions between different objects. A way to encapsulate them, if you like.

It may not seem novel now, but it was not obvious to everyone at that time that this was a possible design-pattern.

Re: The Gang of Four book is wrong about delegation (2012)

#13
post #8

The Gang of Four book is terrible. The explanation are very unclear (often because of excessive abstraction, even in the description and discussion). It's been a long time so my memory is hazy on its particular sins, but I've vowed never to touch it again. I never understood what anyone saw in that book (except that it was one of the first book on the topic of design patterns).

> The Gang of Four book is terrible.

I don't agree. It's a seminal book which, in spite of having been released about 2 decades ago, is still required reading. The book also is well suited as a reference due to their clear explanations, descriptions, and use-cases.

Re: The Gang of Four book is wrong about delegation (2012)

#14
post #8

The Gang of Four book is terrible. The explanation are very unclear (often because of excessive abstraction, even in the description and discussion). It's been a long time so my memory is hazy on its particular sins, but I've vowed never to touch it again. I never understood what anyone saw in that book (except that it was one of the first book on the topic of design patterns).

I always thought I was too dumb to understand the Gang of Four book. I thought everyone else must be so much smarter than me, because everyone praised this book. I really had trouble getting a clear picture in my head of the ideas, concepts and how it all fits together, due to the, as you say, excessive abstraction.

I guess it was mostly due to my inexperience in software design in general. I haven't tried to read it again since then, but I'm sure by now I'd at least understand some of the words in there :) So I wouldn't recommend it for beginners, but I think even experienced developers could still learn something new.

Re: The Gang of Four book is wrong about delegation (2012)

#15
post #5
post #2

I'd hate to be the Gang of Four, especially since they wrote their book 20 years ago. Since then numerous people (including myself) have discussed how to evolve some of their ideas given today's landscape. My position is many ideas are still valid in their book, but they are less novel today and are often implemented with simpler tools. I'm sure the Gang would concur. Other ideas may be less valid over time and I'd b…

I forget who said it, but I ascribe to the notion that most design patterns exist to work around insufficiencies in languages or ecosystems. To that end, a lot of them totally still exist--they've just been reduced in difficulty and ceremony, as you mention. The command pattern, for example, is literally just a closure.

You're probably thinking of when Peter Norvig said: "Design patterns are bug reports against your programming language."

Re: The Gang of Four book is wrong about delegation (2012)

#16
post #2

I'd hate to be the Gang of Four, especially since they wrote their book 20 years ago. Since then numerous people (including myself) have discussed how to evolve some of their ideas given today's landscape. My position is many ideas are still valid in their book, but they are less novel today and are often implemented with simpler tools. I'm sure the Gang would concur. Other ideas may be less valid over time and I'd b…

Same problem a lot of good ideas have (like unit testing or agile), an idea meant to be evolved and applied thoughtfully instead becomes ossified instantly and applied mindlessly, with many mistakes, and zealously.

The concept of design patterns is highly useful. The particular patterns in one book would always be of limited usefulness. Often times devs are more eager to prove their smarts than to get a job done well.

Re: The Gang of Four book is wrong about delegation (2012)

#17
> And C++ can't do delegation

Sure it can. The syntax is a little different, though. And there are a few ways to do it. Here's one:

    #include 
    #include 

    struct Container {
        template 
        void announce(Self const & self) const
        {
            std::cout  announce;

        template 
        explicit Bucket(
            Delegate const & delegate,
            std::string const& aThings) :
                things(aThings),
                announce([&](){ delegate.announce(*this); } )
        { }
    };

    int main()
    {
        // Container works with anything with a 'things'
        // attribute
        Container container;
        // Bucket takes anything with an announce method
        // that accepts a Bucket-like object
        Bucket bucket(
            container,
            "planes, trains, and automobiles"
        );
        bucket.announce();
        return 0;
    }

Re: The Gang of Four book is wrong about delegation (2012)

#18
post #8

The Gang of Four book is terrible. The explanation are very unclear (often because of excessive abstraction, even in the description and discussion). It's been a long time so my memory is hazy on its particular sins, but I've vowed never to touch it again. I never understood what anyone saw in that book (except that it was one of the first book on the topic of design patterns).

I found it easy to understand and I knew nothing about small talk (examples were in smalltalk).

I found it helpful - it allowed me to think and talk about structures in more explicit way, so problem solving got easier.

I think it should be read when you already have some experience with project that has some logic in it (e.g. not crud and also not frontend - frontend requires entirely different structures imo) where you had to make decisions about what goes where. It cease to be abstract then (or your brain adjusted to thinking in more structural way).

Re: The Gang of Four book is wrong about delegation (2012)

#19
post #2

I'd hate to be the Gang of Four, especially since they wrote their book 20 years ago. Since then numerous people (including myself) have discussed how to evolve some of their ideas given today's landscape. My position is many ideas are still valid in their book, but they are less novel today and are often implemented with simpler tools. I'm sure the Gang would concur. Other ideas may be less valid over time and I'd b…

Same problem a lot of good ideas have (like unit testing or agile), an idea meant to be evolved and applied thoughtfully instead becomes ossified instantly and applied mindlessly, with many mistakes, and zealously. The concept of design patterns is highly useful. The particular patterns in one book would always be of limited usefulness. Often times devs are more eager to prove their smarts than to get a job done well…

> ...an idea meant to be evolved and applied thoughtfully instead becomes ossified instantly and applied mindlessly, with many mistakes, and zealously.

That's such a good quote, I just may copy + paste it mindlessly into my next presentation and assert it with zeal. (With credit of course)

Re: The Gang of Four book is wrong about delegation (2012)

#20
I guess that the meaning of the word delegation changed between 1986 and now, definitely in the context of languages that are not prototypal.

I have heard the word delegation as in "this object methid here just returns value somebody else calculated" so many times, that I am pretty confident everybody would be just confused if I started to use different terms.

Post reply on HN