On Friday, July 27, 2012 12:29:13 Namespace wrote: > 1. > Why are these two method header identitcal? > > const Foo some_function() { > > and > > Foo some_function() const { > > ?
> const(Foo) but ref Foo. This is inconsistency, if you ask me. > So why is between C++ and D such a huge difference? > Why isn't it simply const Foo instead of const(Foo)? Sadly, the reason is consistency. const is an attribute just like pure or nothrow, and you can do both pure Foo func() {} and Foo func() pure {} as well as pure { Foo func() {} } and pure : Foo func() {} If const Foo func() {} made Foo const rather than func, it would be inconsistent with the other attributes, and if const on func were only legal on the right (as in C++), then it would be inconsistent with the others. Many of us think that const Foo func() {} should just become illegal inconsistency or not because of all of this confusion, but Walter doesn't buy into that. > 2. > What's about a shorthand for debug assertions? > E.g. to avoid not-null references (yes, if you're a windows user, > you hate them): Walter's stand on this is that the OS gives you null-dereferencing detection - i.e. segfaults and access violations. He's not going to add extra syntax for it. - Jonathan M Davis