Const on the call site?

Robert Fraser fraserofthenight at gmail.com
Wed Nov 14 01:39:08 PST 2007


Well, between episodes of Veronica Mars, I thought I'd visit Digital Mars with an idea that just popped into my head. I understand Walter has solved the const thing, and the conversation has been done to death, so this isn't a serious proposal as it is more a mental language-design exercise (it wouldn't work for D anyway, since there's no way to use this info for functional programming or optimization, which are the goals of the new const regime).

What about requiring constants be declared on the call site rather than at the function declaration? The compiler then checks the function and issues an error if the value isn't const. That way, library writers wouldn't have to worry at all about const, so only the people ho WANTED to use const in their code could. It's not part of the interface of a function, but for most functions, it's the caller who knows whether or not the data SHOULD be constant, and that way the caller can see automatically that a function changes something, and find out where.

Thoughts?



More information about the Digitalmars-d mailing list