www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why are immutable fields with initializers deprecated?

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
A recent discussion 
https://github.com/D-Programming-Language/dmd/pull/3452 brought up a 
matter I'd forgotten - struct fields that are immutable and have 
initializer are deprecated.

Why?

Andrei
Apr 29 2014
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 29 Apr 2014 13:09:01 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail erdani.org> wrote:

 A recent discussion  
 https://github.com/D-Programming-Language/dmd/pull/3452 brought up a  
 matter I'd forgotten - struct fields that are immutable and have  
 initializer are deprecated.

 Why?

I think possibly it has to do with the fact that they originally did not get stored per-instance. I remember a conversation about this (being a bad thing), but have not searched the NG for it. -Steve
Apr 29 2014
prev sibling next sibling parent "Nick Treleaven" <ntrel-public yahoo.co.uk> writes:
On Tuesday, 29 April 2014 at 17:11:50 UTC, Steven Schveighoffer 
wrote:
 On Tue, 29 Apr 2014 13:09:01 -0400, Andrei Alexandrescu 
 <SeeWebsiteForEmail erdani.org> wrote:

 A recent discussion 
 https://github.com/D-Programming-Language/dmd/pull/3452 
 brought up a matter I'd forgotten - struct fields that are 
 immutable and have initializer are deprecated.

 Why?

I think possibly it has to do with the fact that they originally did not get stored per-instance. I remember a conversation about this (being a bad thing), but have not searched the NG for it.

http://dlang.org/changelog#staticfields2
Apr 29 2014
prev sibling parent reply Kenji Hara via Digitalmars-d <digitalmars-d puremagic.com> writes:
--047d7bb0398aa00f4604f8319fd2
Content-Type: text/plain; charset=UTF-8

In future release, non-static const or immutable field will be made an
instance field.

struct S
{
    immutable int x = 1;
}
static assert(S.sizeof == int.sizeof);   // will succeed in the future

So current "implicit static" behavior is now deprecated.

Related:
http://dlang.org/changelog#staticfields
http://dlang.org/changelog#staticfields2

Kenji Hara


2014-04-30 2:09 GMT+09:00 Andrei Alexandrescu via Digitalmars-d <
digitalmars-d puremagic.com>:

 A recent discussion https://github.com/D-Programming-Language/dmd/pull/
 3452 brought up a matter I'd forgotten - struct fields that are immutable
 and have initializer are deprecated.

 Why?

 Andrei

--047d7bb0398aa00f4604f8319fd2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>In future release, non-static const or immutable fiel= d will be made an instance field.</div><div><br></div><div>struct S</div><d= iv>{</div><div>=C2=A0 =C2=A0 immutable int x =3D 1;</div><div>}</div><div>s= tatic assert(S.sizeof =3D=3D int.sizeof); =C2=A0 // will succeed in the fut= ure</div> <div><br></div><div>So current &quot;implicit static&quot; behavior is now = deprecated.</div><div><br></div><div>Related:</div><div><a href=3D"http://d= lang.org/changelog#staticfields">http://dlang.org/changelog#staticfields</a=
<br>

g.org/changelog#staticfields2</a><br></div><div><br></div><div>Kenji Hara</= div></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">201= 4-04-30 2:09 GMT+09:00 Andrei Alexandrescu via Digitalmars-d <span dir=3D"l= tr">&lt;<a href=3D"mailto:digitalmars-d puremagic.com" target=3D"_blank">di= gitalmars-d puremagic.com</a>&gt;</span>:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">A recent discussion <a href=3D"https://githu= b.com/D-Programming-Language/dmd/pull/3452" target=3D"_blank">https://githu= b.com/D-<u></u>Programming-Language/dmd/pull/<u></u>3452</a> brought up a m= atter I&#39;d forgotten - struct fields that are immutable and have initial= izer are deprecated.<br> <br> Why?<span class=3D"HOEnZb"><font color=3D"#888888"><br> <br> Andrei<br> </font></span></blockquote></div><br></div> --047d7bb0398aa00f4604f8319fd2--
Apr 29 2014
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 4/29/14, 10:18 AM, Kenji Hara via Digitalmars-d wrote:
 In future release, non-static const or immutable field will be made an
 instance field.

 struct S
 {
      immutable int x = 1;
 }
 static assert(S.sizeof == int.sizeof);   // will succeed in the future

 So current "implicit static" behavior is now deprecated.

 Related:
 http://dlang.org/changelog#staticfields
 http://dlang.org/changelog#staticfields2

 Kenji Hara

That makes sense - thanks Nick and Kenji! -- Andrei
Apr 29 2014