3 ms·
The difference between implicit conversion and explicit is just syntactic sugar: do you have to put some visible tokens into the code to allow a conversion to h
by kazinator 1y ago
The difference between implicit conversion and explicit is just syntactic sugar: do you have to put some visible tokens into the code to allow a conversion to happen, or not.
Implicit conversion can be seen as the compiler deciding among several possible conversions (or possibly just one) and inserting the coercion/casting operator into the intermediate code to make it happen.
(Of course, this can be a run-time decision based on dynamic types also, but the reasoning is the same. E.g. the run-time sees that a plus operation is adding an integer and float, and can either signal an error (requiring the program to be repaired by inserting a conversion operation into the expression), or just do that conversion, like the integer operand to float.
- shakna 1y agoI really wouldn't call something you need to write, to make something happen, "syntactic sugar". Otherwise types are just sugar. Indicies are just sugar. Lists are just sugar.
- fc417fc802 1y agoIt's the other way around. Implicit conversion is syntactic sugar for explicit conversion. Sugar is anything that is functionally identical, just notated more conveniently. That said, I think you're correct about the casting versus conversion distinction. Languages frequently overload established terminology with slightly modified variants and it's incredibly confusing.