08-Sep-2013 16:02, Michel Fortin пишет:
On 2013-09-07 17:00:05 +0000, Walter Bright <newshou...@digitalmars.com>
said:
Outlining of member functions is the practice of placing the
declaration of a member function in the struct/class/union, and
placing the definition of it at global scope in the module or even in
another module.
http://wiki.dlang.org/DIP47
About placing the definition in another module, you say that the
definition when outlined in another module would have private access to
the private members of the module of declaration. Does that mean that
the definition has access to the private members of two modules at the
same time, the one it is declared in and the one it is defined in? That
seems strange to me.
Same here. This was the ugliest point.
[snip]
I'd like to make a suggestion. If one goal is effectively to allow the
implementation of a function to live in a separate file from its
declaration, then we already have a mechanism for that: .di files. So
I'd like to suggest this: allow a .d file to "import" its corresponding
.di file. Then the .d file should only contain the missing definitions
for what's declared in the hand-crafted .di file. That'd remove the
dubious semantics of making the definition part of another module and
would also allow outlining of global functions. And it also matches
better the C++ model of header/implementation files.
Also, I'd allow outlining only for this specific case where a .di file
is imported by a .d file. This way you know for sure when you see a
declaration without the definition in a .di file that this declaration
is in the corresponding .d file and not anywhere else, making it easier
to hunt it down.
Example:
// test.di
module test;
class A {
void foo(int a, int b);
}
// test.d
import module test; // import declarations from the .di file
void A.foo(int a, int b) {
// member function definition
}
With this suggestion it finally becomes sane.
--
Dmitry Olshansky