Generic programming ramifications of const by default

Georg Wrede georg at nospam.org
Tue Jun 12 04:17:14 PDT 2007


Walter Bright wrote:
> Bill Baxter wrote:
> 
>> Walter Bright wrote:
>>
>>> Bill Baxter wrote:
>>>
>>>> * "having same type defaults is better for generics"
>>>>   (maybe...but I'm not convinced. If you have powerful enough 
>>>> metaprogramming it shouldn't be hard to strip const from a type 
>>>> tuple, or add it.  And people do far more programming than 
>>>> meta-programming.)
>>>
>>>
>>> This is a good point. With const-by-default, you have function type 
>>> declarations behaving *fundamentally* different from other 
>>> declarations. 

True. See below.

>>> Given the metaprogramming ability to use tuples to 
>>> declare parameters, doing function template type deduction for 
>>> parameters, and type inference on parameters, making this 
>>> fundamentally different may wind up really screwing things up.
>>
>>
>> Yes, it's a good point (it's David Held's point), but again your 
>> argument is "may wind up really screwing things up".  On the other 
>> hand it may wind up *not* screwing things up.  Gut feelings are great, 
>> but neither you nor David have given any concrete examples.
> 
> 
> The problem is that metaprogramming is in its infancy. I don't know a 
> case that will screw up, but there's not a lot of metaprogramming out 
> there. Any sort of glaring inconsistency in how declarations work is a 
> potential future train wreck.
> 
> It reminds me a bit of how people argued that using < > for template 
> arguments would be fine, it was just a minor inconsistency. It wasn't, 
> as the inconsistency threw wrench after wrench into the gears of later 
> ideas, and eventually forced several wacky syntactical workarounds.

I think parameter passing is a world separate from "other const or 
const-as-default" areas. Thus, having parameters behave differently from 
them poses no risk for confusion, and, IMHO, is a conceptually clean and 
intuitive choice. It also has a crystal clear perimeter, which 
dramatically reduces the mental strain of having to remember things.



More information about the Digitalmars-d mailing list