3 ms·
Did you ever feel the itch to add a 'trait' to access and manipulate the partial ordering set? Something like CLOS' method combinators or call-next-method (to c
by yvdriess 6y ago
Did you ever feel the itch to add a 'trait' to access and manipulate the partial ordering set? Something like CLOS' method combinators or call-next-method (to call the next most specific function).
- WalterBright 6y agoNo, I never thought of it. I have no idea what purpose calling the next most specific function would serve. Besides, there are ways to call specific functions other than the best match - like casting the arguments to types that make it an exact match with the desired function. Despite the power of D's overload mechanism, my advice is to use overloading modestly, not cleverly. You've written your best code when a newbie looks at it and remarks "pshaw, I could have written this! Why does Walter make so much money?"
- bmn__ 6y ago> I have no idea what purpose calling the next most specific function would serve. This is a replacement for calling the superclass, but it uses C3 method resolution order.
- yvdriess 6y agoThis reminds me that you can get the precedence list in Python with C.__mro__, similar to CLOS's (class-precedence-list C)
- yvdriess 6y agoIt's one of those things where on rare occasion where it's applicable it really simplifies the code. Kind of like dynamically scoped variables. It's been a while that I've hacked CL, but I remember method combinators being used in mixin-style programming[1]. A call-next-method is a simplification tool in that context, and it doesn't hard-couple your generic functions. With concepts now in C++, I wouldn't be surprised to see a resurgence of template-mixins, and there it really helps to have some introspection into the partial ordering. [1] That is, Flavors mixins, not dlang mixins ;)
- beeforpork 6y agoWell, I think they should rather react like this: "Wow, so Walter gets so much money because he writes much less convoluted code than what I would have come up with."
- cylon13 6y agoThey will react that way when they stop being newbies.
- WalterBright 6y agoExactly. Sometimes I think about the advice on how to carve a figure in stone - chip away anything that is not part of the figure. The same applies to programming. Easy to say, hard to do.