Timeline for Why Use !boolean_variable Over boolean_variable == false
Current License: CC BY-SA 3.0
50 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 30, 2021 at 10:10 | answer | added | gnasher729 | timeline score: 0 | |
| Dec 9, 2020 at 5:20 | comment | added | StingyJack |
Because if (!IsVisible... is easy to misread and creates defects, and if (IsVisible == false) does not risk that.
|
|
| Feb 18, 2020 at 22:40 | history | edited | gnat |
edited tags
|
|
| Jul 22, 2019 at 19:53 | comment | added | john c. j. |
Just for the record, PEP 8 suggests to use if var:. The use of if var == True: is marked as bad.
|
|
| Oct 8, 2018 at 15:29 | history | protected | gnat | ||
| Oct 8, 2018 at 13:32 | answer | added | daphtdazz | timeline score: 0 | |
| Apr 12, 2017 at 7:31 | history | edited | CommunityBot |
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
|
|
| Feb 28, 2017 at 13:09 | review | Close votes | |||
| Mar 5, 2017 at 3:05 | |||||
| Feb 28, 2017 at 12:50 | comment | added | gnat | Possible duplicate of Make a big deal out of == true? | |
| Mar 6, 2012 at 15:35 | comment | added | ThomasX | Real programmers write !!!boolean. !!! is called the "really not"-operator. | |
| Feb 27, 2012 at 17:55 | vote | accept | ell | ||
| Feb 27, 2012 at 8:43 | comment | added | Dan Diplo | I think part of the distaste for "boolean == false" is the lingering suspicion it arises in the experienced reader that the programmer in question hasn't quite grasped boolean logic. | |
| Feb 27, 2012 at 4:53 | answer | added | junky | timeline score: 0 | |
| Feb 27, 2012 at 1:10 | comment | added | poke | @AscensionSystems Java isn’t ECMAScript. And you better not mention Java and JavaScript together in the same sentence like that. They are unrelated. – Needless to say that all the mentioned languages are indeed influenced by C (directly or indirectly). | |
| Feb 26, 2012 at 19:08 | comment | added | mowwwalker |
I personally prefer if(boolean?true:false)
|
|
| Feb 26, 2012 at 17:48 | comment | added | Mike DeSimone | In JavaScript, !___ is actually better form because it forces ___ to be converted to a boolean value (it might not be initially). In fact, you often see !!___ used as a shorthand typecast to boolean. | |
| S Feb 26, 2012 at 15:09 | answer | added | Konrad Rudolph | timeline score: 14 | |
| S Feb 26, 2012 at 15:09 | history | made wiki | Post Made Community Wiki by Konrad Rudolph | ||
| Feb 26, 2012 at 13:02 | answer | added | Lightness Races in Orbit | timeline score: 0 | |
| Feb 26, 2012 at 13:02 | comment | added | Lightness Races in Orbit |
If you named your variable properly, then !boolean is more natural. It reads as not boolean to anyone who's enough of a programmer to read code mentally.
|
|
| Feb 26, 2012 at 11:44 | comment | added | user22018 | @Andres, you should have said to zzzzBov, "Oops (...). !YourBad" | |
| Feb 26, 2012 at 11:43 | comment | added | user22018 | @zzzBov I completely disagree with your sweeping statement of languages which are C style. Java, Javascript/Actionscript are ECMAScript based languages. Java I think might be the closest bet you have here to classifying it as "c-style" but I wouldn't agree still and wouldn't agree with C# either. They're based on ECMA and and I would say that aside from the odd similar similar syntactic expressions, they're not styled after C. | |
| Feb 26, 2012 at 6:47 | answer | added | KyelJmD | timeline score: 0 | |
| Feb 26, 2012 at 5:15 | comment | added | zzzzBov | @AndresF., sparkleshy, it wasn't until Keith Thompson mentioned the ambiguity that I realized it that I hadn't been explicit with my comment, and it looked odd in comparison next to Maxpm's comment, which was a couple seconds ahead of my own. | |
| Feb 26, 2012 at 5:06 | comment | added | amara | @zzzzBov: OH. No! I totally agree with you! I also completely misread your comment o//o | |
| Feb 26, 2012 at 5:03 | comment | added | Andres F. | @zzzzBov Oops, I completely misread your comment as if it was advocating boolExp == false. My bad! | |
| Feb 26, 2012 at 4:39 | answer | added | lcllam | timeline score: 3 | |
| Feb 26, 2012 at 0:00 | comment | added | user34530 |
And more importantly, how come nobody wants to write boolean != true?
|
|
| Feb 25, 2012 at 23:49 | history | tweeted | twitter.com/#!/StackProgrammer/status/173555255404003328 | ||
| Feb 25, 2012 at 23:32 | answer | added | Keith Thompson | timeline score: 86 | |
| Feb 25, 2012 at 23:19 | comment | added | zzzzBov |
@sparkleshy, I would venture to guess that more than 50% of C-style programmers use !foo over foo == false. Are you disagreeing with this?
|
|
| Feb 25, 2012 at 23:06 | comment | added | Keith Thompson |
@zzzzBov: Your comment is ambiguous. If you meant that !boolean_variable is the way most C programmers do it, I agree.
|
|
| Feb 25, 2012 at 22:08 | answer | added | Fabio Ceconello | timeline score: 1 | |
| Feb 25, 2012 at 21:39 | comment | added | Andres F. | @ell I suggest this isn't "language-agnostic". Pick a language and follow its conventions! | |
| Feb 25, 2012 at 21:35 | comment | added | Andres F. | @zzzzBov: It's true that Java's syntax resembles C, but its conventions and best practices are different in many ways. | |
| Feb 25, 2012 at 21:09 | answer | added | knut | timeline score: 0 | |
| Feb 25, 2012 at 21:08 | answer | added | user1249 | timeline score: 19 | |
| Feb 25, 2012 at 21:04 | comment | added | amara | @zzzzBov: Um, no. That's not how most (C-style) programmers do it. | |
| Feb 25, 2012 at 20:57 | answer | added | AProgrammer | timeline score: 7 | |
| Feb 25, 2012 at 20:54 | answer | added | Andres F. | timeline score: 106 | |
| Feb 25, 2012 at 20:53 | answer | added | kba | timeline score: 173 | |
| Feb 25, 2012 at 20:52 | answer | added | WuHoUnited | timeline score: 0 | |
| Feb 25, 2012 at 20:51 | comment | added | zzzzBov | @AndresF., Java is a C-style language, as is C#, C, C++, JavaScript, ActionScript, php, and numerous others. | |
| Feb 25, 2012 at 20:51 | answer | added | ratchet freak | timeline score: 8 | |
| Feb 25, 2012 at 20:49 | comment | added | Andres F. |
@zzzzBov I haven't programmed in C in ages... is that the idiomatic way of evaluating a boolean expression? In any case, consistency is relative to specific languages. In Java it's idiomatic to write if (condition) {...} rather than if (condition == true) { ... } (same with false).
|
|
| Feb 25, 2012 at 20:44 | comment | added | zzzzBov | Because that's how most (C-style) programers do it, and consistency is important. | |
| Feb 25, 2012 at 20:43 | answer | added | BЈовић | timeline score: 4 | |
| Feb 25, 2012 at 20:43 | comment | added | Maxpm |
It's like doing boolean == true: it doesn't make sense. Expressions inside if statements are just that: expressions. If something already evaluates to a boolean expression, why would you add a check to force it to evaluate to that?
|
|
| Feb 25, 2012 at 20:41 | comment | added | Zenon | It is shorter to write. | |
| Feb 25, 2012 at 20:39 | history | asked | ell | CC BY-SA 3.0 |