3 ms·
Seems pointlessly complex too. Why didn't you just make it cast(T, x)?
by throwawaymaths 3y ago
Seems pointlessly complex too.
Why didn't you just make it cast(T, x)?
- WalterBright 3y agoNeither is more complex. I just like the former better.
- throwawaymaths 3y agoWell, certainly my eyes need to add an extra parsing case so maybe don't assume it's equally complex. I don't think I'm wrong on that count.
- absdiff 3y agoPython and Haxe have a function-like cast like that, but the argument order differs between the languages. I prefer D's approach because it doesn't have this opportunity for confusion. The prefix operator only has one place for the type to go. https://docs.python.org/3/library/typing.html#typing.cast https://docs.python.org/3/library/typing.html#typing.cast typing.cast(typ, val) https://haxe.org/manual/expression-cast.html https://haxe.org/manual/expression-cast.html cast expr; // unsafe cast cast (expr, Type); // safe cast
- throwawaymaths 3y agoit doesn't have this opportunity for confusion 1) it'll be a compiler error anyways 2) of course there's room for confusion. It could be cast(T) var Or it could be cast(var) T And you must remember which is correct.