Which language futures make D overcompicated?
Adam D. Ruppe
destructionator at gmail.com
Fri Feb 9 17:31:47 UTC 2018
On Friday, 9 February 2018 at 16:44:32 UTC, Seb wrote:
> Forget inout, it's seldomly used and there have even attempts
> to remove it from the language.
inout rox. I think this is more of a documentation
discoverability problem. We should be having people read the
spec, which is written toward compiler authors [!], when they
want to just know how to use it.
Here's the basic rules of thumb:
If you don't need to change a variable:
1) use immutable when declaring a new variable
immutable myvar = "never gonna change";
2) if you are returning a member variable or function argument,
use inout on both
class myclass {
Object member;
inout(Object) getMember() inout {
return member;
}
}
inout(char)* identity(inout(char)* s) {
return s;
}
inout is like const, just paired return value to arg, so notice
that inout will appear twice in the typical signature when you
use it.
3) use const when declaring function parameters. Exception: if
you need to store the passed reference or pass it to another
thread, then immutable may be the better choice.
void inspect(const char[] data) {}
Implicit conversion flowcharts are useful for a deeper
understanding but are unnecessary for most effective use...
More information about the Digitalmars-d
mailing list