On Friday, 17 December 2021 at 13:14:50 UTC, Igor wrote:>
I hate language constructs that go in opposite order from my thoughts making me type something then having to navigate back to add another thing. Best example for this is casting in any language. I always have to write cast operator before the thing I am casting yet in my head I never think "then I need to cast to int the variable X that I want to add". I think more like "Then I need to add variable X but I have to cast it to int".
I feel the same about writing. But you have to consider how code is read, too. C# kind of has an infix cast operator: You write
x as TargetType there. In D, you can do the same:
auto ref TargetType as(TargetType, SourceType)(auto ref SourceType object)
return cast(TargetType) object;
auto result = fun(x.as!int).as!string;
I'll agree that an operator would look nicer, but – as is more often than not the case with D – if a library solution is found that isn't horrible, the probability that the language will be extended is around 0.