On 05/15/2013 11:19 PM, Andrei Alexandrescu wrote:
On 5/15/13 5:14 PM, Walter Bright wrote:
It means I can't read the code and easily determine what that const
value is, even though it is explicitly initialized with a value.

I now understand the concern. I'd argue that static immutable/const
fulfills that role, and that a member const is supposed to be
initialized in a constructor (or via the default initializer syntax as
for any other member) and stay constant throughout the lifetime of the
object. That _is_ a very useful notion.

I'm not assuming you're proposing this, but I'm clarifying just in case:
a member that takes per-instance memory YET always has the same value in
all objects would be positively useless. _That_ should at best be an error.

Are you proposing that this be allowed:

  struct S
  {
      immutable int c = 123;
      this(int i) { c = i; }
  }

and that the compiler should report an error on the following?

  struct S
  {
      immutable int c = 123;
      // No constructor
  }

Lars
_______________________________________________
dmd-beta mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/dmd-beta

Reply via email to