const by default.

Boris Wang nano.kago at hotmail.com
Tue Jul 4 00:03:58 PDT 2006


"Derek Parnell" <derek at nomail.afraid.org> 
??????:zrz58urdcgmf$.yw3ohvtn0rct$.dlg at 40tude.net...
> On Tue, 4 Jul 2006 13:42:11 +0800, Boris Wang wrote:
>
>> "kris" <foo at bar.com> ??????:e8cu1q$nbc$1 at digitaldaemon.com...
>>> Chad J wrote:
>>>> So far I'm pretty convinced that some kind of "constness" is a good
>>>> thing.  I've already run into one area where this would be useful.
>>>>
>>>> I have one peeve about it though: I really would not like it if the
>>>> keyword used to represent constness was "const".  I will explain from 
>>>> my
>>>> newbie-to-Cplusplus background, having come from languages that seem, 
>>>> at
>>>> least to me, to be much more well thought out than Cplusplus.
>>>>
>>>> When I see "const" I think of it as a shorthand for "constant", just as
>>>> "bool" is shorthand for "boolean".  My understanding of something
>>>> constant is that it does not change... EVER.  Thus it makes no sense to
>>>> me why something as ephemeral as data passed into a function could be
>>>> considered constant.  If the constant data leaves the scope of the
>>>> function, becomes no longer constant, and gets changed, then it isn't
>>>> really constant to me.
>>>>
>>>> I do like the mutable word though, as it seems to have an english 
>>>> meaning
>>>> very close to its programming meaning  :)
>>>> It also seems that if we were to make things immutable by default, we
>>>> could make an "immutable" keyword.  Sure it's kinda long, but since 
>>>> most
>>>> things are that by default then we won't be typing it much.  It also
>>>> seems so much more logically related to the word "mutable".
>>>>
>>>> Another worry I have is that of being stuck with many instances of
>>>> "mutable" littering my code, if only because said code happens to 
>>>> modify
>>>> referenced data a lot.  One way I might see this worry dissappearing if
>>>> there was a way to blanket stuff into being immutable, in order to 
>>>> avoid
>>>> repeating the word over and over again.  Sorta like:
>>>>
>>>> class Foo
>>>> {
>>>>   mutable:
>>>>     int[] data; // this is mutable
>>>>     char[] name; // this too
>>>>     // etc
>>>> }
>>>>
>>>> or maybe even something as radical as
>>>>
>>>> mutable
>>>> {
>>>>   // from now on everything works as it used to
>>>>
>>>>   void func1( char[] string1, char[] string2 )
>>>>   {
>>>>     string1[5] = 'a'; // ok
>>>>     string2[3] = 'b'; // also good
>>>>   }
>>>>
>>>>   void func2( int[] data )
>>>>   {
>>>>     data[8] = 42; // just dandy.
>>>>   }
>>>> }
>>>>
>>>> Note:  I am probably so newbish at language design compared to you guys
>>>> it is not even funny, so maybe the syntax suggestions suck, but please
>>>> consider my naming plea, at least as a "this experience was unpleasant 
>>>> so
>>>> please fix it" sorta thing.
>>>
>>>
>>> hehe -- that would certainly resolve the problem for existing libraries:
>>> just wrap each entire module in a mutable{} block -- phobos would be 
>>> done
>>> in 15 minutes :D
>>>
>>> Good idea!
>>>
>>
>> NO, Yet another colon / brace syntax.
>
> Disregard Boris ;-)   It's a great idea.
>
Please disregard me, again, :)

I work at linux kernel about two years once, love reading the kernel mail 
list. i learn about
what's seriousness, professional and hacker in there. until now, my whole 
works not on windows os.

IMHO, in NG of D, i can't get the feelings got from linux kernel mail list. 
The idea, like above, can't be approved in the world of LK.

> -- 
> Derek
> (skype: derek.j.parnell)
> Melbourne, Australia
> "Down with mediocrity!"
> 4/07/2006 3:48:13 PM
> 





More information about the Digitalmars-d mailing list