Comment On Truth or Sim

A huge number of the bad code submitted to TDWTF is related to dates. This isn’t all that surprising- dates are very complex data structures with a vast number of possible representations and huge cultural variations. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Truth or Sim

2012-11-05 08:10 • by dmu (unregistered)
public class types
{
public enum bool
{

TRUE, FALSE, UNDEF, SIM
}
}


Almost like nullable bool in C#

Re: Truth or Sim

2012-11-05 08:11 • by Java? (unregistered)
Java??? with colons for types and "function" keywords??

TRWTF: faking code?

Re: Truth or Sim

2012-11-05 08:13 • by belgariontheking
That's not Java.

Re: Truth or Sim

2012-11-05 08:13 • by Warren (unregistered)
For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.

Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....

Re: Truth or Sim

2012-11-05 08:15 • by fanguad (unregistered)
That second example isn't Java.

Re: Truth or Sim

2012-11-05 08:15 • by ¯\(°_o)/¯ I DUNNO LOL (unregistered)
public class types
{
  public enum bool
  {
      TRUE, FALSE, UNDEF, SIM, FILE_NOT_FOUND
  }
}
Fixed.

Re: Truth or Sim

2012-11-05 08:16 • by ab (unregistered)
But how can you really check if the result of the isTrue() function is really true?

Oh, I get it!

if (BooleanUtilities.isTrue(BooleanUtilities.isTrue($val))) ...

Re: Truth or Sim

2012-11-05 08:20 • by Julia
Ah, the age old problem...

"Pilate saith unto him, What is truth? And when he had said this, he went out again unto the Jews, and saith unto them, I find in him no file at all."

Re: Truth or Sim

2012-11-05 08:25 • by Honnza (unregistered)
The second example looks like TypeScript. Not many languages have colon-delimited types.

Re: Truth or Sim

2012-11-05 08:33 • by renewest
Each time this program calls new BooleanUtilities().isTrue(val) a baby lemur cries.


That is not true. David Attenborough would have told us.

Re: Truth or Sim

2012-11-05 08:34 • by renewest
394122 in reply to 394121
Each time this program calls new BooleanUtilities().isTrue(val) a baby lemur cries.


That is not true. David Attenborough would have told us.

TRWTF is the delete button right here !

Re: Truth or Sim

2012-11-05 08:34 • by BBCode Okay (unregistered)
The "java" code is actionscript

Re: Truth or Sim

2012-11-05 08:35 • by David (unregistered)
That other example isn't Java... its Adobe ActionScript.

It follows this format

variable:DataType

function funcName(arg1:DataType, argN:DataType):returnDataType{
//contents...
}

Re: Truth or Sim

2012-11-05 08:36 • by Herwig (unregistered)
This was my favorite:
#define true 0

...the original author works now as chief developer for an Austrian company which codes software for medical healthcare...

Re: Truth or Sim

2012-11-05 08:41 • by TGV
394126 in reply to 394125
Herwig:
This was my favorite:
#define true 0

...the original author works now as chief developer for an Austrian company which codes software for medical healthcare...

I'm sure that the principal reason was that no-one would ever be able to use C's standard truthiness. You would just have to write if (b == true), or else your code would fail, thus making the programmer pay more attention and resulting in better code. Really, I don't see the WTF.

Re: Truth or Sim

2012-11-05 08:42 • by C-Derb (unregistered)
394127 in reply to 394114
Warren:
For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.

Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....
It's just a prototype. Once they get the production version up and running, I'm sure they'll switch the order and do === first.

Re: Truth or Sim

2012-11-05 08:45 • by Decius (unregistered)
In before FILE_NOT_FOUND = FALSE

Re: Truth or Sim

2012-11-05 08:49 • by The MAZZTer
394129 in reply to 394114
Warren:
For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.

Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....


The difference is == allows for type conversions while determining equality. === does not. Speed isn't a main reason for using it, it's based on whether or not you want to allow a true result if both sides are different types but with the same content.

Eg "0", 0, false, null, undefined are all ==, but not ===.

This only applies to primatives, classes (like Arrays and Objects and so forth) are judged on equality by reference only so there's no difference between == and === in those cases.

Re: Truth or Sim

2012-11-05 08:52 • by DonaldK (unregistered)
"Sim" is "Yes" in Portuguese.

Pronounced, it sounds close to the word "sing" in English.

All that said, it still doesn't make sense.

Re: Truth or Sim

2012-11-05 09:11 • by TheCPUWizard
Functions of the form:

public function isTrue(arg:Boolean):Boolean
public function isFalse(arg:Boolean):Boolean

do server a useful purpose - you can use them as functors, delegates, etc. a veritable slew of cases where one needs to be able to invoke (explicitly or under the covers).

Now having the if statement inside is wonky, but it does provide a place to put a breakpoint.

Re: Truth or Sim

2012-11-05 09:13 • by Nappy (unregistered)
This would make Yoda's head explode

Re: Truth or Sim

2012-11-05 09:21 • by firsttodye (unregistered)
Not a programmer here; could someone please explain to me what the thought process may have been to create a true/false test for a true/false test? I thought that was the whole deal for boolean logic?

Re: Truth or Sim

2012-11-05 09:22 • by Swedish tard (unregistered)
I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned.
I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced...
Which then made me replace the whole thing with return boolean1 == boolean2;

But there are pretty much something strange with booleans every week when I'm digging around in code.

Personally I think that being able to handle boolean logic should be a very lowest expectation of someone that is supposed to create software... No wonder every piece of software is crap and bug ridden, because if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?

Re: Truth or Sim

2012-11-05 09:26 • by JimLahey
Just last week I found a tri-state boolean managed in our application database. If you put true as the value, the code does a check on some subsequent fields. Put false and it doesn't check, but it writes a log entry. Put null and it does nothing. It's mapped to a string property using NHibernate and the getter calls .ToUpper(). There will be blood.

Re: Truth or Sim

2012-11-05 09:37 • by golddog (unregistered)
394136 in reply to 394134
Swedish tard:
I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned.
I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced...
Which then made me replace the whole thing with return boolean1 == boolean2;

But there are pretty much something strange with booleans every week when I'm digging around in code.

Personally I think that being able to handle boolean logic should be a very lowest expectation of someone that is supposed to create software... No wonder every piece of software is crap and bug ridden, because if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?


Pretty much the first thing I do when evaluating software (whether it's a code review sort of thing or third-party) is to try to look at the small things.

Through many years in this industry, I've found that when people can't get the little things right, it's very unlikely they get the big things right.

Re: Truth or Sim

2012-11-05 09:41 • by Trevel (unregistered)
394137 in reply to 394133
firsttodye:
Not a programmer here; could someone please explain to me what the thought process may have been to create a true/false test for a true/false test? I thought that was the whole deal for boolean logic?


I would assume the logic is that "if (X)" might be confusing to read where "if istrue(X)" isn't. I can read either with relative ease, but someone new to programming might find the latter helpful.

A nullable bool might be useful when, to pick an example, processing a true/false set of questions. You will need to deal with the difference between True, False, and Did Not Answer The Question. Assuming a default of 'false' would skew the results.

My personal favourite of these sorts is the classic

if (x == false) {x = true};

Re: Truth or Sim

2012-11-05 09:48 • by Watson (unregistered)
394138 in reply to 394136
Swedish tard:
I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned.
I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced...
Which then made me replace the whole thing with return boolean1 == boolean2;


In a similar vein, can anyone explain why
(booleanExpression1 && booleanExpression2) || (!booleanExpression1 && !booleanExpression2)
couldn't just be written as
(booleanExpression1 == booleanExpression2)
? Because I see the former (and its disjunctive version) too often for it to be an accident.

Re: Truth or Sim

2012-11-05 09:53 • by Swedish tard (unregistered)
394139 in reply to 394138
Watson:
Swedish tard:
I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned.
I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced...
Which then made me replace the whole thing with return boolean1 == boolean2;


In a similar vein, can anyone explain why
(booleanExpression1 && booleanExpression2) || (!booleanExpression1 && !booleanExpression2)
couldn't just be written as
(booleanExpression1 == booleanExpression2)
? Because I see the former (and its disjunctive version) too often for it to be an accident.


Because booleans are too damn hard? XD
I get those a lot too...
And another common ugly boolean construction I see is:

if(boolean == true)
return true;
else if(boolean == false)
return false;

...
So much fail.

Re: Truth or Sim

2012-11-05 10:14 • by sambista (unregistered)
There's something missing:


public class types
{
public enum bool
{
TRUE, FALSE, UNDEF, SIM, NÃO
}
}

Re: Truth or Sim

2012-11-05 10:19 • by Scott (unregistered)
394142 in reply to 394138
It depends on whether or not booleanExpression* variables are boolean expressions. In perl, let's say $val1 is the number of files found in directory1, and $val2 is the number of files found in directory2

# We want to execute this code if both directories are empty,
# or if both directories have files, but not if only one
# directory has files.
if ( ($val1 && $val2) || (!$val1 && ! $val2) ) {
...
}

In this case, $val1 might be 3, and $val2 might be 5. They're
both boolean true, but they're not numerically equal.

Re: Truth or Sim

2012-11-05 10:24 • by Remy Porter
I just took the submitter at face value and assumed one of the many changes in Java syntax had tried to make more convenient parameter passing or something.

Re: Truth or Sim

2012-11-05 10:29 • by shinobu
Adam:
shares this JavaScript helper function:

Boolean.prototype.isTrue = function () {
if (this == true) {
return true;
} else if (this === true) {
return true;
} else {
return false;
}
}

This isn't a WTF, in fact it's mandatory to be ISO 13485 / ISO 14971 compliant:
Each decision that may affect a user or a patient has to be double checked.

Re: Truth or Sim

2012-11-05 10:29 • by Billy (unregistered)
As Jesus said after healing the insane man, go forth and SIM no more.

Re: Truth or Sim

2012-11-05 10:33 • by MiffTheFox
I guess you can say that ActionScript is Java, in the same sense that JavaScript is. (ActionScript is based on ECMAScript, which JavaScript is an implementation of.)

Now then again ActionScript isn't exactly server-side, unless there's a big WTF I don't know about. (To the best of my knowledge, it's only implemented in Flash and Air.)

(Yeah, JavaScript is to Java as Car is to Whatever I've heard it a million times.)

Re: Truth or Sim

2012-11-05 10:34 • by Remy Porter
394148 in reply to 394147
Unfortunately, there are server-side Flash technologies. Ugh, Flex.

Re: Truth or Sim

2012-11-05 10:36 • by Geoff (unregistered)
394149 in reply to 394139
if(boolean == true)
return true;
else if(boolean == false)
return false;

is prefectly reasonable to do in some languages. I am thing object basic dialects for example. Its actually one of the faster and more clear ways to normalize return codes, in cases where boolean is not actually of type bool but will evaluate to true or false in the expected way. But yes in C,C++,Java its WTF.

Re: Truth or Sim

2012-11-05 10:36 • by Earnest (unregistered)
Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.

Re: Truth or Sim

2012-11-05 10:37 • by bv (unregistered)
Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible. Indeed, had some tyrannical god contrived to enslave our minds to time, to make it all but impossible for us to escape subjection to sodden routines and unpleasant surprises, he could hardly have done better than handing down our present system. It is like a set of trapezoidal building blocks, with no vertical or horizontal surfaces, like a language in which the simplest thought demands ornate constructions, useless particles and lengthy circumlocutions. Unlike the more successful patterns of language and science, which enable us to face experience boldly or at least level-headedly, our system of temporal calculation silently and persistently encourages our terror of time. ...

It is as though architects had to measure length in feet, width in meters and height in ells; as though basic instruction manuals demanded a knowledge of five different languages. It is no wonder then that we often look into our own immediate past or future, last Tuesday or a week from Sunday, with feelings of helpless confusion. ...

— Robert Grudin, Time and the Art of Living.

(Quoted in the GNU Coreutils info pages: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html )

Re: Truth or Sim

2012-11-05 10:37 • by D-Coder
394152 in reply to 394132
Nappy:
This would make Yoda's head explode
FTFY: This Yoda's head would make explode.

Re: Truth or Sim

2012-11-05 10:40 • by Whining Pride (unregistered)
394153 in reply to 394134
Swedish tard:
if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?
But, but... booleans aren't intuitive and I've been assured that I'm just as good as any computer user even though I'm too lazy to learn anything. Indeed, I've seen several forums where my ignorance is praised and encouraged! If the person doesn't understand the computer, it is always the computer's fault.

Re: Truth or Sim

2012-11-05 10:43 • by Jack (unregistered)
394154 in reply to 394139
Swedish tard:

And another common ugly boolean construction I see is:

if(boolean == true)
return true;
else if(boolean == false)
return false;
else
universe.Reboot();

FTFY

Re: Truth or Sim

2012-11-05 10:48 • by Larry (unregistered)
394155 in reply to 394150
Earnest:
Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.
The problem is that if it is the obvious way to do something, somebody has already patented it. To stay out of legal trouble, you need to invent something strange enough to be unique. Then, of course, go patent that.

If you're a programmer, you need two patent lawyers perched on your shoulder. One to look for existing patents on each line you write, and the other to patent anything the first one doesn't delete.

(This comment patent pending. Go write your own.)

Re: Truth or Sim

2012-11-05 11:00 • by xenoid
394156 in reply to 394155
Authors of dictionaries/thesauruses "poison" their work with fictitious words so that copies are easily spotted. This could be an equivalent behavior among coders :)

Re: Truth or Sim

2012-11-05 11:05 • by Captcha:suscipere (unregistered)
394157 in reply to 394150
Earnest:
Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.

Unfortunately, if there is an immediate method to achieve, it must already have been patented. To avoid legal inconveniences, the recommended way is to create a method that's strange enough that nobody has used it before. Of course, immediately afterwards, you patent it.

If you're programming, you need the supervision of two patent lawyers. One to check if your written code is patented, and the other to patent anything remaining from the first one.

(Comment made in PRC)

Re: Truth or Sim

2012-11-05 11:08 • by xenoid
More boolean weirdness... seen that once:

boolean foo=Boolean.TRUE.booleanValue();

Re: Truth or Sim

2012-11-05 11:13 • by suis (unregistered)
394159 in reply to 394158
xenoid:

boolean temp_bool=Boolean.TRUE.booleanValue();
boolean foo=(new BooleanUtilities().isFalse(temp_bool) == false);

Enterprised that for you (now it handles the case when Boolean.TRUE.booleanValue() returns FILE_NOT_FOUND correctly).

Re: Truth or Sim

2012-11-05 11:13 • by Michael (unregistered)
I would really like to start a competition on here to see who can make the LEAST efficient re-implementation of boolean logic. I'm sure we could get some intriguing entries.

Re: Truth or Sim

2012-11-05 11:36 • by Xavier (unregistered)
394162 in reply to 394160
Michael:
I would really like to start a competition on here to see who can make the LEAST efficient re-implementation of boolean logic. I'm sure we could get some intriguing entries.
Easy. XML. It makes everything easy.

Re: Truth or Sim

2012-11-05 11:40 • by Darth Paul (unregistered)
394163 in reply to 394151
bv:
Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible...
— Robert Grudin, Time and the Art of Living.

(Quoted in the GNU Coreutils info pages: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html )


One thing that is still missing from most implementations: catering for incomplete date times, which is necessary in real world systems.

Often you have a date that is YM only (no D), or simply a Y (no MD). But how best to handle it when the programming language or database cannot (as incomplete dates must seamlessly query, calculate and sort correctly against complete dates)?

Anything that is real world historical data will more often than not have this problem (date a photo was taken, date of birth are obvious examples). You can cludge it, but the cludge will always leave a gotcha in the data model.

Re: Truth or Sim

2012-11-05 11:46 • by F (unregistered)
394164 in reply to 394144
shinobu:
Adam:
shares this JavaScript helper function:

Boolean.prototype.isTrue = function () {
if (this == true) {
return true;
} else if (this === true) {
return true;
} else {
return false;
}
}

This isn't a WTF, in fact it's mandatory to be ISO 13485 / ISO 14971 compliant:
Each decision that may affect a user or a patient has to be double checked.


In which case it should be
if (this == true) {
return true;
} else if (this === true) {
return true;
} else if (! this == true) {
return false;
} else {
return false;
}
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment