[dmd-beta] dmd 2.064 beta take 2
Nick Sabalausky
bus_dmdbeta at semitwist.com
Wed May 15 12:59:24 PDT 2013
On Wed, 15 May 2013 15:07:13 -0400
Andrei Alexandrescu <andrei at erdani.com> wrote:
> On 5/15/13 3:02 PM, Walter Bright wrote:
> > I believe it was disallowed in earlier D2 versions. If I saw such
> > code in a project, I'd find it awfully suspect, not sensible.
>
> On the contrary, examples abound. Consider:
>
> class Image {
> const double scalingFactor = 1.0; // no scaling
> this(double sf) {
> scalingFactor = sf;
> ...
> }
> ...
> }
>
> What is suspect about this? I have about five others without even
> needing to think that hard.
>
I had almost been convinced of the opposite, but I think you're
absolutely right:
Being able to specify at runtime an instance-specific value which isn't
allowed to change again during the object's lifetime (not even from
within the same module) does indeed seem quite useful. I'm certain I've
come across cases in the past where I'd have liked that, but just
wasn't sure how to do it in a compiler-enforced way.
FWIW, I think the compiler flag Jason and Kenji suggested sounds like
the most sensible way to deal with this.
More information about the dmd-beta
mailing list