DMD 2.000 alpha release

Derek Parnell derek at nomail.afraid.org
Wed Jun 20 21:20:47 PDT 2007


On Wed, 20 Jun 2007 19:55:47 -0700, Walter Bright wrote:

> Charles D Hixson wrote:
>> The potential argument in favor of const strings seems, to me, to be 
>> speed.  But I don't know whether it applies.
> 
> The argument for const strings isn't speed, it's understandability. 

I thought it was about safety. About not accidentally changing stuff that
was not indented to be changed.

> People tend to think of them as value types (like ints),

No problems with that so far ...

>  and by making 
> strings const (or invariant) it makes them behave like value types.

This is where you lose me though. Your statement seems to only apply when
talking about function parameters -- and then it really is about speed too.

For example, I can get the same effect as const even when not using const,
but at a run-time cost.

Without CONST
   void func(char[] a) { ... }
   char str = "abc".dup;
   func(str.dup); // Now I don't care what 'func' does with my data.

With CONST
   void func(const (char)[] a) { ... }
   char str = "abc".dup;
   func(str); // I still don't care what 'func' does with my data.

The difference is that the CONST version is faster and gives the compiler a
clue about the writer's intentions (and thus can issue appropriate error
messages)

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
21/06/2007 2:00:38 PM



More information about the Digitalmars-d-announce mailing list