Re: Adding syntacti sugar for simple "readonly" attribute ?

2017-10-27 Thread Jacob Carlborg via Digitalmars-d
On 2017-10-27 11:06, bauss wrote: Ahh yeah, that's true. I wasn't thinking that far I think head const [1] is what he's looking for. Similar to "final" in Java. [1] https://dlang.org/const-faq.html#head-const -- /Jacob Carlborg

Re: Adding syntacti sugar for simple "readonly" attribute ?

2017-10-27 Thread bauss via Digitalmars-d
On Friday, 27 October 2017 at 06:49:47 UTC, Jacob Carlborg wrote: On 2017-10-27 01:04, bauss wrote: The first example would not equal the second, because you could set bar from anywhere within the module. Immutable will already do your behavior. class Foo {     immutable string bar;    

Re: Adding syntacti sugar for simple "readonly" attribute ?

2017-10-27 Thread Jacob Carlborg via Digitalmars-d
On 2017-10-27 01:04, bauss wrote: The first example would not equal the second, because you could set bar from anywhere within the module. Immutable will already do your behavior. class Foo {     immutable string bar;     this(string baz)     {     bar = baz;     } } That only

Re: Adding syntacti sugar for simple "readonly" attribute ?

2017-10-26 Thread bauss via Digitalmars-d
On Thursday, 26 October 2017 at 21:19:28 UTC, LunaticWare wrote: Hello everyone i am new to the D community and i really enjoy programming in D, i haven't done anything significant so far. but being a very lazy person, when writing a bit of code i noticed that maybe for such a simple thing we

Re: Adding syntacti sugar for simple "readonly" attribute ?

2017-10-26 Thread Ali Çehreli via Digitalmars-d
On 10/26/2017 02:19 PM, LunaticWare wrote: > i don't know if this is the correct way to suggest enhancement to D, Improvement proposals are handled through DIPs here: https://github.com/dlang/DIPs > so maybe we could add syntactic sugar for "readonly" attributes. There is the following

Re: Adding syntacti sugar for simple "readonly" attribute ?

2017-10-26 Thread jmh530 via Digitalmars-d
On Thursday, 26 October 2017 at 21:19:28 UTC, LunaticWare wrote: [snip] You can use string mixins. template GenGetterSetter(string Type, string Name) { const char[] GenGetterSetter = "private " ~ Type ~ " " ~ Name ~ "_;\n" ~ "this(" ~ Type ~ "

Adding syntacti sugar for simple "readonly" attribute ?

2017-10-26 Thread LunaticWare via Digitalmars-d
Hello everyone i am new to the D community and i really enjoy programming in D, i haven't done anything significant so far. but being a very lazy person, when writing a bit of code i noticed that maybe for such a simple thing we could have a shorter syntax. i don't know if this is the correct