Comment #0 by bearophile_hugs — 2010-03-12T14:47:11Z
This program seems to show that "in" function arguments are the same as "const", and "immutable in" are immutable:
import std.stdio: writeln;
void foo1(const int x) {
writeln(typeid(typeof(x))); // const(int)
}
void foo2(in int x) {
writeln(typeid(typeof(x))); // const(int)
}
void foo3(immutable in int x) {
writeln(typeid(typeof(x))); // immutable(int)
}
void main() {
foo1(1);
foo2(1);
foo3(1);
}
So the "in" attribute for function arguments can be removed from the language, so programmers can use "const", "immutable", etc in a more explicit way.
According to Python Zen: "There should be one-- and preferably only one --obvious way to do it."
Comment #1 by aldacron — 2010-03-13T00:10:54Z
I strongly object. Currently, 'in' is one of the few constructs remaining that allow compatibility between D1 and D2 without resorting to versioned blocks and mixins. Take this away, and cross-version compatibility becomes even more of a headache than it already is.
Comment #2 by bearophile_hugs — 2010-03-13T04:33:05Z
My opinions on the topic:
- As a Python user I have seen the usefulness of that part of its Zen. It speeds up coding, speeds up code reading, makes code more uniform among different programmers, etc.
- When Andrei's book is out, people will learn the D2 language. I like D1 but it will probably not last many years. I think some years from now D1 will be unused. Keeping in D2 a redundancy and baggage for a language that will not last is bad.
So if you don't want to remove that "in" now, to help in the transitory period of code that works in D1 and D2, it can be kept, deprecated, _plus_ it has to always raise an informative deprecation warning, it must be noisy, otherwise new D2 programmers will use it and it will never be possible to remove it from the language. And then it can be removed in one or two years from now.
Comment #3 by andrej.mitrovich — 2012-12-20T15:39:40Z
"in" is equivalent to "const scope" (there might be some related opened bugs about it though), so it's not redundant.