- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
There are 10 types of people: those who get binary, and those who don't. I fall in the category: File not found.
Admin
I worked at a company a long, long time ago, where they basically imported their C++ development rules over to C#.
So back in the old days, C/C++ technically had no boolean type, so the idea was that you transform the integer result of the variable with an tertiary operation into the constants TRUE and FALSE to make it more readable.
When I see this example, it reminds me about that company. Maybe the code is the same or the "lead" architect from back then read the same book with this crazy idea of "readability" as those guys? Who knows, but here you got an explanation I encountered for this "pattern" in C/C++ in the 90s - obviously it made never ever sense for C# because that language had a boolean type and exceptions form the start.
Addendum 2024-08-19 07:22:
Of the result of the method obviously.
Admin
The only way that'd have been better is if they'd left the leading
!
off and the results of the ternary were.. ? false : true ;
. With the "explanation" that a) negation is difficult to understand and b) the!
symbol is easy to overlook when reading code.Now there's a thin vertical stripe of truth in point b. Had we settled on
~
for negation there would be fewer sloppy reading errors in boolean expressions. Instead we'd misread whatever the!
was used for instead. :forehead smack:Admin
In the first version set a breakpoint when setting visible to false..... Now do the same in the "improved" versions...
Admin
C++ has always had a boolean data type since the beginning, even in the pre-standardization C++98 version.
C originally did not have a boolean data type, so the usual thing to do was to use
int
instead. The C99 version of the standard introduced a boolean type, but many compilers didn't support C99 for a while, and many devs still used the older C89 even when a C99 compiler was available. (That said, even if a C99 compiler wasn't available, it was still very trivial for devs to implement their own boolean using a typedef or macro.)Admin
It could be much worse if they introduced ambiguous (or at least "not so easy to parse") naming into things, combined with multiple negation, on "word level" and "code level":
pnlErrorMessage.Invisible = !string.IsNullOrEmptyOrBoth(errorMsg.toString()) ? untrue : notFalse;
if (!(pnlErrorMessage.Invisible != FILE_NOT_FOUND) > TrueOrFalse) doSomething(); // or maybe don't?
A nice negation symbol could have been the ¬ symbol, known as "lazy L", which is present in EBCDIC (and used, for example, in REXX) and even included in extended ASCII as 172 or 0xAC, but it never made its way to PC keyboards...
Admin
Yes but no. A C-ish set of defines and typedefs wouldn't achieve the key piece of a C++
bool
, collapsing all non-zero / non-nullptr values intotrue
. Well, unless the macros include a set-to method that includes a!= 0
(being thankful once more that a literal0
casts trivially to any pointer type asNULL
ornullptr
).But as soon as you do
typedef unsigned int bool;
followed bybool boolvar = XXX;
whereXXX
is of typeunsigned long long
, and of a value that's an integer multiple ofUINT_MAX+1LL
, you get a surprise.Admin
Actually, the lazy l is quite common on UK keyboards and i was always confused what it was usable for.
Admin
The Unreliable Source would like to point out, at https://en.wikipedia.org/wiki/British_and_American_keyboards , that that last part of your sentence ("never made its way to PC keyboards") isn't true as an absolute statement. On a UK-QWERTY keyboard, it's the shifted backtick top-left of the main keyboard, next to the 1/! key.
Admin
The only way that'd have been better is if they'd left the leading ! off and the results of the ternary were .. ? false : true ;
Or be consistent: (!condition) ? !false : !true
Admin
I am aware of that; with not having a boolean type I mean that a lot of library results still often used int for boolean results (hence the technically because with C/C++ library stack is was back in the days a extreme mishmash).
Admin
Use a conditional breakpoint?
Admin
“in some ways too concise”: tell it to the APL/J/K folks. Yes, they’re still around, coding blazingly fast trading bots for investment firms.
Admin
Also, and this doesn't even register for most of us readers, you need to have an understanding about operator order (namely that negation binds very tightly and ternary is about as loose as you can get, so it's
(!thing)? true:false
, not! (thing?true:false)
. Even more so because C-style languages' mandatory parentheses inif ()
statements.Admin
The type with the fewest possible values—not counting the unit type, which has one possible value; or the bottom type, which doesn't have any.
Admin
I knew someone once who refused to use false. Instead he always wrote !true. He rarely was wrong, but we knew all along the damage his method could do.
One day last July, when the weather was dry and the sun incessantly burned.
A deadline was looming, and he went on terning. Tern after tern after tern.
We still to this day know not what went array. Which pointer or he failed to release. All that we know is that there'll be no more snow and that summer shall newer more cease.
For up in the heavens, forever deployed, now lives an unfortunate !. And the shutdown button to turn off the summer forever refuses to click.