Do we really need const?

Derek Parnell derek at nomail.afraid.org
Mon Sep 17 18:33:08 PDT 2007


On Tue, 18 Sep 2007 09:52:46 +1000, Derek Parnell wrote:

> On Mon, 17 Sep 2007 22:57:05 +0100, Regan Heath wrote:
> 
>> renoX wrote:
>>> Bruce Adams a écrit :
>>>> An example of one that catches me out quite often is:
>>>> strcpy(src,dest) vs. strcpy(dest,src);
>>> 
>>> If it helps you'not the only one to have this kind of issue: some 
>>> compilers even try to detect when people makes mistakes for 'memset'?
>>> Both case show why function calls with passing the parameter by position 
>>> instead of by keywords *sucks*.
>>> 
>>> Let's try it: do you think you would make the same mistake if you would 
>>> call your function this way:
>>> char[50] var_dest, my_src;
>>> strcpy(dest: var_dest, src: my_src)
>> 
>> My eyes... aaarghh!
> 
> Or ...
> 
>   copy(from: var_dest, to: my_src);

P.S.
This still doesn't remove the usefulness of 'const' concept though. For
example ..

   copy(from: ExampleA, to: ExampleB);

This line by itself doesn't tell the reader if 'ExampleB' is writeable or
not.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
18/09/2007 11:04:23 AM



More information about the Digitalmars-d mailing list