Extending D's support for object-oriented design with private(this)
NotYouAgain
NotYouAgain at gmail.com
Thu May 23 11:09:42 UTC 2024
On Tuesday, 21 May 2024 at 17:27:18 UTC, Jonathan M Davis wrote:
> ..
> ...
> - Jonathan M Davis
There discussion about all that going back to at least 2012.
see: https://forum.dlang.org/post/kb4lkc$2bm0$1@digitalmars.com
Since dmd 2.105.0 (released Aug 01, 2023) this code is now an
error.
If my facts, and maths are correct, that's like a decade after
the above discussion took place!
OT: But, D still has many, many others of these 'tricky little
issues' that 'some' programmers would be (or should be)
horrified with...
For example:
- allowing a subclass to expose a 'protected' API by simply
overriding it as 'public'!
- implicit conversion of double to float!
- and this...
{
void cube(double x) { writefln("%s : no ref", x); }
void cube(ref double x) { writefln("%s : ref", x); }
double x = 3.4;
cube(x); // which one is called? Well you guessed it - not the
one you expected!
}
- ... i can go on.. and on..
// -------
module m;
@safe:
private:
import foo;
import std;
void main()
{
Foo f = new Foo();
writeln(f.test(3));
}
/*
module foo;
@safe:
private:
public class Foo
{
private int test(int n) { return n; }
public string test(string str) { return str; } // this
overloads the private method.
}
// When a private method was overloaded with a public method that
came after it,
// you could access the private overload as if it was public.
*/
// -----------
More information about the dip.ideas
mailing list