6 ms·
I was able to use my experience implementing C++ name lookup rules to make a less complex one for D: There's no notion of a "primary" template. Templates are l
by WalterBright 6y ago
I was able to use my experience implementing C++ name lookup rules to make a less complex one for D:
There's no notion of a "primary" template. Templates are looked up like functions are.
C++ has rather complex function overloading rules that differ substantially from template overloading rules. The former is a hierarchical list of rules, the latter is based on partial ordering. D uses partial ordering for both.
D doesn't need argument dependent lookup, because it has modules.
D lookup sees all the declarations in a module at once, not just ones prior to the point of use.
The end result works pretty much the same, and hardly anyone notices the difference. Except for that last point - in C and C++, the order of declarations is inverted. The private functions come first, the public ones last, because lookup is dependent on the lexical order. D code is written with the public ones first, private ones last.
- dgellow 6y agoD is really underappreciated.
- yvdriess 6y agoDid 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.
- exdsq 6y agoWhat's the standard use-case for D 'in the wild'? It looks interesting and is one of the few languages I've heard of but haven't used -- might try it out on my next project :)
- ncmncm 6y agoProbably the reason D never got much attention is that D seems too much like C++, similarly to the way that C# is much like Java. (C# has the full weight of MS behind it, which D never had; yet, C# has not displaced Java.) D works for basically the same set of problems as C++, in much the same way. D, not bound by history ("mistakes", you could say) could be simpler than C++, and able to do some things more neatly, but not enough so to match C++'s momentum—also a product of history. Since D came out, C++ has evolved in ways hard to keep up with. Some make it more like D, but those don't help D. Rust is different enough from C++ to have some hope of carving out its own space, while trying to address the same sort of problems C++ does. Rust also abandons history, with consequences like D. However, Rust is developing its own complexities. In the end, if it survives, Rust and Rust code will be fully as complex as C++ and C++ code, just off in a slightly different direction. But it is too early to know whether Rust too will, in the end, fail to find a mainstream place. Ada and Pascal both once had far wider use than Rust, and faded. Ultimately, C++ can do anything Rust can, has capabilities Rust is not expected ever to match, and is still evolving fast. So, for anything that might need to be maintained by somebody else someday, it is easier to believe that a C++ programmer could be found to do it. In the end, the only true determiner of whether a language succeeds is if a miracle occurs. C got one, C++ got one, Java got one, Javascript got one. Python probably got one. I don't know of any others newer than Fortran. Julia and Rust still have a chance.
- whatshisface 6y agoC++ will structurally never have a borrow checker, because it's simply not designed in a way for that to be possible.
- WalterBright 6y agoD has a prototype borrow checker now. I'll be talking about it at the April NWCPP meeting.