Named constructors

IchorDev zxinsworld at gmail.com
Tue Nov 12 21:13:18 UTC 2024


On Saturday, 9 November 2024 at 00:02:52 UTC, JN wrote:
> Much clearer for the user, user can type "new Angle." and the 
> IDE would suggest only constructors instead of all of the 
> static methods on the class. Assumption would be that if named 
> constructors exist, there is no implicit argumentless 
> constructor so Angle a3 = new Angle() won't work anymore.

1. Why are your examples using C++ syntax? You should provide 
examples that at least compile with *minimal* modification so 
that people can actually work off of them and test them. Garbage 
in, garbage out.
2. When your DIP is based on a problem with a feature of an IDE, 
then the problem lies with your IDE, not the language. The 
language doesn’t shape itself around IDEs, or else we’d have to 
discard templates, mixins, and aliases.
3. Is there any reason you can’t just use an external factory 
function? This is very common practice:
```d
Angle angle(float deg) => new Angle(deg*PI/180f);
Angle angle(float rad) => new Angle(rad);

auto a = angle(deg: 90);
auto b = angle(rad: PI/2);
```


More information about the dip.ideas mailing list