3 ms·
Type conversions have to be explicit when they are lossy, otherwise it's just useless noise and cognitive overhead that can lead to a bug.
by zzzcpan 9y ago
Type conversions have to be explicit when they are lossy, otherwise it's just useless noise and cognitive overhead that can lead to a bug.
- ben0x539 9y agoI dunno, "newtypes" are a fairly popular patterns, and if they automatically converted between the base type and other newtypes of the base type, they'd not really be useful.
- k__ 9y agoCan't they have performance impacts even if they aren't lossy?
- Too 9y agoType conversions, even non lossy ones, can teach people to use the wrong type, in c++ it's very common to see people use a int in a for loop indexing an array when you should always use size_t for that purpose. This misuse is so widespread that people hardly even know that the size_t type exists. https://www.viva64.com/en/a/0050/ https://www.viva64.com/en/a/0050/ has some nice material about why this matters and the type of bugs this can cause.
- Gibbon1 9y agoPersonal opinion, heavy use of int is a code smell. Ada with 'range' probably gets this right.