- Feature Articles
- CodeSOD
- Error'd
-
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
Of course, rsEmplExp.MoveFrist only applies when not True!
Admin
The docs make me thing this is the case - it's a read-only Boolean. https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/recordset-eof-property-dao
Admin
Well indeed. Not all models of reality adhere to Tertium Non Datur.
There is an entire branch of mathematics whose thesis is that TND may not necessarily hold.
The programmer in this case is prudent and sensible, and has written code that is bullet-proof.
Admin
I recognise the pattern. In my case the reason was "standards" (why use two constants when one suffices?) the other (anti-) patterns was to write it like if (true == someCondition) because one developer was once burned by: if (someCondition = true), however this application was written in VBA (yeah, you can poke fun now.)
Admin
Visual Basic, you say? I remember from my kidhood that boolean expressions in MS-BASIC return 0 for false and -1 for true, but IF accepts any non-zero value as true. You just don't want to combine random "boolean" values with AND and OR because there's no && or || like operator. This looks like a cargo cult response by someone who discovered that the hard way.
Admin
It's VBA. This is just a know-nothing version of 'if false or error'. It likely indicates something is mildly broken elsewhere in the code, but I don't think there's much to laugh about when beginners hack away until they get something working.
Admin
Reading that M$ doc, I come to the thought that some steps in the development of the code are nowadays missing: tinkering around with both BOF and EOF and their various combinations. And what ever crap they did with the recordset before they arrived at that line of code...
Admin
Which is why you should just omit the "= true" part: if (someCondition).
Admin
A sane compiler does not allow a boolean constant as an operand of a comparison operator.
Unfortunately, I've never met a sane compiler.
Admin
A looong time ago, I recall in some book with a name like "C++ for Dummies" or "The Complete Idiot's Guide to C++", there was a sidebar titled "How to Annoy a Visual Basic Programmer". It said (presumably in jest) that VB devs do "if x = True" while C++ devs do "if (x != false)". Maybe someone read that, took it seriously, and thought they'd be cute?
Admin
Sure about that? If such a compiler existed, I assure you that a lot of programmers' brains will fry as they attempt a paradigm shift without a clutch.
Admin
Defining e.g. Integer to be a subset of Float is supported by sound foundations, but considering Boolean to be a subset of Integer is making a mockery of mathematics. According to MS's VB specification for EOF: "returns an Integer containing the Boolean value True when [...]".
WTF? Does that mean that the logarithm of True is a diluted truth and therefore False?
Stuff like that has borne code like b==true ("b, it it true that you're true?") or perhaps even (b==true)==true (b, is it really true that it's true that you're true?). Programmers should be admonished for writing silly code like that, but the real culprit is the language.
PHP deserves the crown (preferably with nails pointing inwards) for playing on both sides: strpos(str, substr) returns 0 if str starts with substr and False if str does not contain substr. That makes perfect sense, except for the fact that in PHP booleans are a subset of integers similar to in VB.
Admin
This construct was written to deal with Schrodinger's Boolean.
Admin
I just realized that one of the reasons that -1 makes for a good "True" value, is that a register filled with 1's allows one to perform bit logic conveniently. Gone are those days for most programmers presumably.
Admin
We've heard of fuzzy logic; perhaps such a language has to allow for statements that are 'less than true' and 'more than false'. We should ask a lecturer in Woolly Thinking about this...
Admin
In general, I'd advocate going a step further and banning the comparison of boolean values (constants or not), as if (in C++ terms)
bool operator ==(bool, bool)
does not and cannot exist.Admin
While it's always fun to speculate, I have a hunch the answer is something much more mundane: style preference.
If my shirt is not red, how did you parse this sentence?
if ( shirt (is not) red ) or if ( shirt is (not red) ) ?
There were probably just two different people who read the sentence differently.
Admin
That would also make something like this impossible:
which does come in handy from time to time. I've used this more than once, if not with
==
then!=
, but same difference. Withoutoperator==
you'd have to do the following, which I don't find more readable:Yes, someone who genuinely needs to compare bools that way can be expected to come up with the alternative, but it doesn't convey the intent the same way.
// let's see if I got those code blocks right... 🤞
Admin
I’ve run into VB bool logic like that. It’ll accept any non-zero as true indeed. Unfortunately, the ! (logical not) operator is actually a binary operator, which can lead to a nice case where
value
and!value
will both evaluate to true. Took some time to debug that one.Admin
Some languages have EQV and NEQV operators (or XOR) which are equivalent to comparison but more logical (aha).
So you could have if (a EQV b). Anybody who writes if (a EQV True) should hopefully get a compiler warning for writing a stupid operation.
Admin
This is it. It's a natural pattern in BASIC for those who haven't yet realize that if clauses don't need a conditional operator. It's more correct than the code it replaced, but it's still demonstrating a lack of experience.
Admin
It's an Access database with a frontend of some kind, the devil is likely in the missing detail.
We aren't told how these booleans are presented to the user, in Microsoft Access, there is a setting you can set on them called 'Triple State', this allows the checkbox to have 3 states, it can be: yes, no, null.
In the 'yes' state, the checkbox has a tick in it, in the 'no' state, the checkbox is blank.
In the 'null' state, the checkbox has a gray blob inside it.
By saying
If rsEmplExp.EOF <> True Then
It's very likely they are trying to get around the 'null' state that a 'Triple State' checkbox supports.
Admin
Exactly. I often do filtering, where I want to check if (isMatch == wantMatch), which allows for filtering based on what you do OR do not want to find.
But yes, if (isMatch == true) should be torched.
Admin
"to the resultset objects (implied by the rs prefix, so there's the one time in my life I've been happy to see Hungarian notation)"
It's ok if you know what "rs" stands for. I didn't, so I am still yet to see a good use for Hungarian notation.
A better name would have been "emplExpResultSet". An even better name would be "<whatever empl stands for><whatever exp stands for>ResultSet". Who cares if it's 20 characters long when we have auto-complete and copy/paste.
Admin
And you're unlikely ever to meet one, as first you'd have to have a sane language design.
Admin
Unlike many environments where any non zero value is True, in VBA, "= false" and "<> true" are not equivalent! You should not test for False if you are looking for a value of True. False = 0 and True = -1, so :
(-1 = false) 'is false ( 0 = false) 'is true (1 = false) is false (2 = false) is false ... BUT (-1 <> true ) 'is false (0 <> true) ' is true (1 <> true ) 'is true (2 <> true ) 'is true ...
Admin
There's true, false and 'maybe'. 'Maybe' is not false, but also not true.
Admin
That looks like an XNOR operation. Shame there isn't an actual factual boolean XOR in most C-ish languages. Would have been nice if K&R had given us
a^b
for bit XOR anda^^b
for boolean XOR, so your operation would be:although I have seen people abusing C and C++'s silent promotion of
bool
toint
to cheese it as (note single ^):Admin
I think this is the opposite of some Visual Basic / COM problem. I recall vaguely that some configuration of tech glue ends up with True being treated as 1, and False as 0, but sometimes COM APIs return some other non-zero value (like -1) for "true". Doing "<> False" may therefore be necessary, but I don't see why you'd need "<> True".
Admin
The low-level Win32 COM APIs return HRESULTs, which are a 32-bit unsigned integer value, with all "high-bit set" values indicating an error (and the rest of the bits identifying the error).
High-bit clear indicates a success, which is usually
S_OK
(zero), but a few can returnS_FALSE
which is 1.Admin
You know, I'm surprised no one's submitted my VBA WTFs - I had the (mis)fortune of having to create and maintain several applications in Access. It was just a "mere" document tracking system, but helped keep track of what drawings where on a project and if you sent any off to any customers, you picked them off a list and it generated the transmittal sheet (list of drawings included) and logged the transmission into the database, so you can see per drawing who got sent what (and what revision), If drawings were approved you added the event to the list and it populated the approval field for the document.
The annoying bits was that it was surprisingly much harder to create a database record than it had to be - all these things generated events for documents that had to be logged for the document - so documents that went out, approved, etc, all had to be logged as document events.
Let's just say the code is a nasty collection of code I'm surprised is not on the WTF list here.
Admin
What would happen if EOF was (null)?
Admin
Perl 6 actually lets you do exactly that -
$x | $y
is a value, represents a superposition of the two values, and can be used anywhere the values can, the result of which is another superposition. Then eventually you end up with a superposition of bools, which when evaluated in a boolean context collapse via OR. Or you can make the superposition with &, or ^, and there's even one for the NOT case, though unfortunately lacking a convenient operator.Admin
Why not call it what it is: an equality operator? There's no problem with
==
if your boolean type properly has only two values, nor!=
which is the same as xor. There is absolutely no problem with such things unless your type standing in for boolean is really an integer and that is the real WTF.Admin
Are you, by any chance, referring to "Logics with Semiring semantics" ?