const assignments problem again

Jonathan M Davis jmdavisProg at gmx.com
Sun Aug 7 03:13:03 PDT 2011


On Sunday 07 August 2011 06:02:36 Kagamin wrote:
> Jonathan M Davis Wrote:
> > Being able to use const can be very valuable. For instance, what if you
> > were using std.algorithm.copy and got the arguments backwards? If the
> > source is const, then the compiler will complain, and you'll quickly
> > find the bug. If the source isn't const, then you could accidentally
> > end up copying the target to the source, and it may or may not be an
> > easy bug to catch.
> 
> I've seen a bug. I fixed two methods: begin and end and sent the patch to a
> man. They were calling other methods (sort of begin1 and end1). The man
> slightly fixed my patch and copied the fixed body of the first method to
> both of them (they look very similar). The compiler was happy, the
> application even worked. The bug was catched only because I checked whether
> the man did it right.

??? I don't understand what you're trying to say. I don't know if your English 
is just poor or if you're trying to make fun of me.

const has value. It obviously doesn't solve everything or catch every bug, but 
it can help a lot in ensuring that variables that are not supposed to be 
mutated aren't mutated. You can choose not to use it, and that's fine, but it's 
part of the language, and many other people value it highly.

- Jonathan M Davis


More information about the Digitalmars-d mailing list