3 ms·
> Is this a real problem? If there's a function signature that accepts `Operation`, the caller must explicitly cast the `int` to `Operation`. At that point, it'
by glenjamin 3y ago
> Is this a real problem? If there's a function signature that accepts `Operation`, the caller must explicitly cast the `int` to `Operation`. At that point, it's the caller's own fault.
You would think that, but that isn't always the case: https://play.golang.com/p/Ze3pfNEVTVs https://play.golang.com/p/Ze3pfNEVTVs
It's very easy to create an enum value that isn't actually in the defined range
- mseepgood 3y agoCan you explain the thought process of a developer when they write 'performOperation(2)'? What do they believe '2' signifies in this context? I struggle to believe that this could occur by accident.
- avgcorrection 3y agoYou struggle to imagine a programmer passing a value of the wrong type to a function?
- bb88 3y agoOr passing a wrong value and the compiler allows it because the programmer trusted the compiler to "always do the right thing".