implicit conversion from bool to char, is it really necessary ?
bearophile
bearophileHUGS at lycos.com
Wed Sep 26 04:15:12 PDT 2012
Brad Roberts:
> Out of curiosity, what's your working definition of 'common'
> here? It seems to be something not far from "I've seen a
> report of it happening in more than one code base" which is
> overly broad, imho.
Regarding (!x & y) I have seen studies (done by the Coccinelle
devs) that shows how often this erroneous code pattern is present
in the already reviewed Linux code. I have seen the same pattern
in tens of articles from Viva64 where they apply their static
verifier to large amounts (tens of millions, surely) lines of
code, where they have spot tens of such bubs in already carefully
debugged code.
This pattern:
int r = x op y ? : z : w;
is present in several of those Viva64 reports. This is not a
proof that such ?: requires parentheses (those reports just show
common problems in already tested and widely used code, they
don't suggest language improvements), but it's more than enough
to open a discussion.
> but there's a line where too much compiler 'help' is just
> annoying.
I agree, this requires judgement, and there's the risk of
overdoing the compiler tests. As an example this thread and
article discuss that the "unused imported modules are an error"
and "unused variables is an error" rules of Go are too much harsh
during code development:
http://ridiculousfish.com/blog/posts/go_bloviations.html
http://www.reddit.com/r/programming/comments/10fvmh/go_bloviations/
On the other hand I think the unused variables warning is useful,
because they help keep code clean and avoid some bugs.
Experience shows that in most programs the pattern (!x & y) is a
bug, so I think disallowing it is an improvement for D, you will
find it not easy to demonstrate the contrary.
Bye,
bearophile
More information about the Digitalmars-d
mailing list