Adding syntacti sugar for simple "readonly" attribute ?
LunaticWare
exemple at gmail.com
Thu Oct 26 21:19:28 UTC 2017
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 way to suggest enhancement to
D,
and i am sorry if this is already in the language.
so maybe we could add syntactic sugar for "readonly" attributes.
here is simple example, where the following code
---
class Foo
{
@readonly int bar = 12; // or maybe "@directread" ?
this(string baz)
{
this.bar = baz;
}
}
---
would be the same as
---
class Foo
{
private string bar_;
this(string baz)
{
this.bar_ = baz;
}
@property string bar()
{
return this.bar_;
}
}
More information about the Digitalmars-d
mailing list