Const, strings, and other things.
Paul Findlay
r.lph50+d at gmail.com
Mon Nov 12 21:23:39 PST 2007
> It has something to do with it. If you have a function like so:
>
> void drawImage(Image i, int x, int y) ...
>
> And Image is a class type, do you expect images that you pass in to be
> modified? No, because that would be stupid.
Yeah, but it happens with code I use in ruby land. This is a bug I reported:
http://projects.jkraemer.net/acts_as_ferret/ticket/181
(happens easily since ruby strings are like references to classes).
Having optional const may not have prevented the error, but if ruby had
something like a const attribute I imagine I could have simply added it and
tracked down the modification by waiting for a compiler/runtime error
rather than tracing the whole flow of the code manually.
I don't really know, but I wish the D compiler had support for ensuring
things that could be const are, and that functions that can return
null-references get checked their return value checked by their users. I
don't think it should substitute for programming habits, but a compiler
should be able to do so much more grunt work.
- Paul
More information about the Digitalmars-d
mailing list