Which is more maintainable -- boolean assignment via if/else or boolean expression?
Posted
by
Bret Walker
on Programmers
See other posts from Programmers
or by Bret Walker
Published on 2012-11-30T21:23:42Z
Indexed on
2012/11/30
23:19 UTC
Read the original article
Hit count: 338
Which would be considered more maintainable?
if (a == b) c = true; else c = false;
or
c = (a == b);
I've tried looking in Code Complete, but can't find an answer.
I think the first is more readable (you can literally read it out loud), which I also think makes it more maintainable. The second one certainly makes more sense and reduces code, but I'm not sure it's as maintainable for C# developers (I'd expect to see this idiom more in, for example, Python).
© Programmers or respective owner