2 ms·
In my opinion, some features of D are good, but I do not like all of them. CTFE is good. I do not really like the UFCS; if you want it to be used like a membe
by zzo38computer 1y ago
In my opinion, some features of D are good, but I do not like all of them.
CTFE is good.
I do not really like the UFCS; if you want it to be used like a member of the first parameter then you should define it as a member of the first parameter (possibly as a inline function that only calls the freestanding function with the same name, if that is what you want it to do). (You could use a macro to do this automatically if you want to.)
Scoped imports is good, but I think that scoped macros would also be helpful.
Exhaustive switch seem like it might be better if designed differently than it is, but the idea seems to be not bad, in general.
- LorenDB 1y agoUFCS is a bit overreaching but I think it's great for its intended use of chaining expressions on ranges and such.
- destructionator 1y agothat actually wasn't its intended use; that's a side effect. The original intended use came from Effective C++ by Scott Meyers: "Prefer non-member non-friend functions to member functions.". It was meant to make that as syntactically appealing as the members.
- Doxin 1y agoHonestly the main reason UFCS is good is when you don't "own" the type your function would need to be a member of. Most common one I run into is the "to" function from the stdlib. You can do this: import std.conv; int foo=3; string bar = foo.to!string But now lets say you want to convert ints to MyCustomInts? You can hardly attach a new "to" member to int, but with UFCS it's easy. Just declare a to function anywhere in scope: MyCustomInt to(T)(T v) if(is(T==int)){ return MyCustomInt.from_int_value(v) // or however you actually do the conversion } and it'll magically work: int foo=3; MyCustomInt bar = foo.to!MyCustomInt;