why there are no multimethods in c++? [closed]
Asked Answered
B

3

13

I read many article about how to implement multimethod in c++:

  1. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1529.html
  2. http://www.codeproject.com/KB/recipes/mmcppfcs.aspx
  3. http://lambda-the-ultimate.org/node/2590
  4. http://parasol.tamu.edu/people/peterp/omm/

why there are no multimethod in c++?

why do not they get supported by c++ standard?

Bolshevism answered 30/1, 2011 at 18:28 Comment(4)
Why aren't functions first class objects in C++? Why doesn't C++ have function literals? Nobody knows. It wasn't part of the plan.Vaporing
@Rafe Kettler: C++0X has (will have) function literals... [](int x, int y) { return x + y; } for example s a function that given two ints returns the sumIndian
Bjarne 2007 proposal: www2.research.att.com/~bs/multimethods.pdfTame
W.r.t Bjarne's paper, it was only a reference for people wanting to propose evolutions on the subject. So we might see multi-methods in the future still, esp now that Bjarne has found a way to do it "properly" with less impact than other (library) approaches.Tame
L
35

Straight from the horse's mouth:

"I rejected multi-methods with regret, because I liked the idea, but couldn't find an acceptable form under which to accept it."

Bjarne Stroustrup, The Design and Evolution of C++ (p297)

And later:

"Multi-methods is one of the interesting what-ifs of C++. Could I have designed and implemented them well enough at the time? [...] What other work might have been left undone to provide the time to design and implement multi-methods?"

(p298f)

In general, whenever you feel the urge to know why some particular C++ feature was implemented, or was not implemented, or was implemented the way it is now, and if that feature pre-dates the standardization, you want to read D&E.

Limber answered 30/1, 2011 at 18:38 Comment(8)
Any quote from D&E for a question like this gets an upvote from me.Pandowdy
Thanks for this (with a citation too!). I find it interesting given what I wrote in my answer about Stroustrup being criticized for accepting too much into C++. One can infer something from his phrasing ("I couldn't find [a way] to accept it"), like he wanted to accept this as he did so many other things.Vintner
@John: I agree, that's the impression you get when reading this book. Until the beginning of the 90ies, when the standardization took off, Stroustrup was C++. Yes, he had very bright fellows to work with (what with K&R just down the hall, and Lippmann, Koenig and many others) and he keeps repeating that he ran his ideas by them. But according to his accounts (which nobody ever publicly challenged) it seems in the end he made the decisions (and he also implemented most of it). Given that, the success of C++ is truly marvelous. Who of us could have done this?Limber
FWIW, Bjarne has written proposal for it in 2007: www2.research.att.com/~bs/multimethods.pdfTame
@Macke: Interesting, especially since D&E is so much older. What became of this proposal?Limber
@sbi: Rejected for C++11, but not sure of details and I haven't been able to google it either.Tame
@sbi: Apparently, it was never a full proposal. Someone said "This paper is only a reference for people wanting to propose evolutions on the subject." in a comment somwehere.Tame
FWIW, Stroustrup proposal's updated link: stroustrup.com/multimethods.pdfPortia
I
15

As Bjarne has pointed out a number of times, when people criticize C++, it usually runs something like: "C++ is too big, too complex, has too many features, and it's too hard to learn -- you should really work at making it smaller and simpler. Oh, and while you're working on that I also have this really great idea for a killer feature that you should add!"

Iila answered 30/1, 2011 at 18:48 Comment(0)
V
10

Just because it could be done doesn't mean it's a problem that it wasn't done. One criticism of C++ is along the lines of "Stroustrup took everything anyone had heard of, and tried to include it."

Plus, as Raymond Chen says, "Every feature starts off with -100 points." That is, before you ask why C++ doesn't have these things, you should explain in detail why it needs them. Otherwise your feature stays in negative territory, due to the costs associated with it.

Vintner answered 30/1, 2011 at 18:36 Comment(1)
I like that Chen wisdom. He's been there, too, getting his lousy shirt. :)Limber

© 2022 - 2024 — McMap. All rights reserved.