deprecate boolean evaluation of floating point and character types
Quirin Schroll
qs.il.paperinik at gmail.com
Thu May 16 17:55:14 UTC 2024
On Friday, 10 May 2024 at 19:25:45 UTC, Guillaume Piolat wrote:
> On Tuesday, 30 April 2024 at 17:01:42 UTC, Basile B. wrote:
>>
>> instead of an assertion failure what we should get is rather a
>> message such as
>>
>> error, cannot evaluate `f64` to a `bool`
>
>
> With float you often want to be more specific anyway.
>
> Do you mean isFinite?
> Do you mean !isNaN?
> Do you mean non-zero?
>
> Can't really see a legit use for: if(float) { }
I wrote that once thinking it meant (!isNaN(x) && x != 0.0),
thought I be smart. Introduced a bug. Maybe I overreacted, but I
never used implicit conversions to bool in conditions ever. `i !=
0`, `x != 0.0`, `ptr !is null`, it’s all so much clearer.
Whenever I see `if (x)`, I have to think what it means, unless
`x` is a `bool`.
More information about the dip.ideas
mailing list