const by default.

John Reimer terminal.node at gmail.com
Sun Jul 2 19:19:11 PDT 2006


Dave wrote:
> Ok, I know 'const' has been beaten to death in previous threads...
> 
> However, one thing that I've not seen beaten to death is 'const by 
> default'.
> 
> In the following post, there's a link to comp.lang.c++.moderated where 
> Walter puts forward some very good arguments regarding what's wrong with 
> C++ (type modifier) const:
> 
> http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/39437
> 
> In that thread, Walter mentions that he should have made const the 
> default. Every subsequent post agreed with not one dissenter.
> 
> Walter, what exactly do you have in mind? Only reference types? Default 
> const for everything? Everything but function local variables? Or 
> function return types and function parameters only?
> 
> If some type of 'const by default' was implemented, it could have big 
> consequences for Phobos. As Phobos is 'officially' supported and 
> distributed w/ the compiler, it is the only thing that has to be changed 
> along with the compiler.
> 
> I'd say:
> - add the 'mutable' keyword in v0.163
> - let the community start modifying Phobos.
> - add a "warn on non-mutable" switch to the compiler by v0.167 (that way 
> Walter could implement all of the logic, and later cutover by removing 
> the switch and making those errors instead of warnings).
> - let the community test Phobos using the new warning switch
> - 'cutover' when Phobos is done.
> 
> I think the "too much water under the bridge" problem from Walter's 
> standpoint is that he can't count on anyone else but himself making the 
> changes to Phobos, and he simply doesn't have the time.
> 
> I would gladly volunteer for a few of the Phobos modules but I don't 
> have the time nor enough explicit knowledge of Phobos to lead the effort 
> efficiently. If we could just get the 'mutable' keyword in there, then 
> we could start a Dsource project and get "promises" from people in the 
> community to do the work.
> 
> Just some thoughts on the matter...
> 
> Thanks,
> 
> - Dave


Good points!

Sorry for the minimal post, but there's just not much to add to what 
Dave says here.

-JJR



More information about the Digitalmars-d mailing list