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-06 19:49 • by Nagesh (unregistered)
394319 in reply to 394197
dkf:
cellocgw:
Dates are not "complex" structures. They're purely reals.
Or strings.
Dates are fruit that grow on date palms.

Married programmer is only having to date palm one week per month.

Re: Truth or Sim

2012-11-06 19:59 • by Meep (unregistered)
394320 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...

Say you have a main function in C:

int main(void) {

return stuff_worked() ? true : false;
}

What should true and false be, if we want to be compliant with standard exit codes?

In bash, try:
( exit 34 ); echo $?

true; echo $?
false; echo $?
true && echo yes, that worked
false || echo nope, that failed

Re: Truth or Sim

2012-11-07 06:33 • by Trolleh (unregistered)
394331 in reply to 394152
FTFTFY: This Yoda's head explode would make.

Re: Truth or Sim

2012-11-07 11:08 • by vt_mruhlin (unregistered)
My favorite bool WTF was the guy who made a java program with two static AtomicBooleans, FileReader.TRUE and FileReader.FALSE.
Everywhere throughout the code, he would do a reference comparison between a given bool and either FileReader.TRUE and FileReader.FALSE.

The general idea was that there would be multiple kinds of readers, but this guy only implemented the FileReader, then passed it on to me for the rest. So I did some quick refactoring and quickly found that things were failing because SQLReader.TRUE != FileReader.TRUE

I went and asked the guy WTF he was doing and had the most awkward "you're not getting it" conversation ever when he kept trying to tell me that he did it that way because "it has to be atomic".

Re: Truth or Sim

2012-11-07 13:19 • by Jonathan (unregistered)
lol I like the hidden Cornify :)
(click on "truth truly is ," on one of the last paragraphs... you won't be disappointed)

Re: Truth or Sim

2012-11-08 21:07 • by Worf (unregistered)
394565 in reply to 394264
Antti Alien:
TRUE, FALSE, UNDEF, SIM


In some situations that is completely sensible. In a hardware simulator, for example. Verilog uses four state logic:
- 1 for true,
- 0 for false,
- Z for high-impedance state of an unconnected input, and
- X for unknown.


That's not enough to resolve all the possible states...

There's also weak pull up/down, strong pull up/down as well. As well as open-collector/open-drain.

Otherwise you can't simulate some logic, like say, USB.

(USB uses weak pullups on the host - the stronger pulldowns on the device give determination between USB slow speed and USB full speed. High speed is negotiated through some special signalling during enumeration (chirps), and super speed well, probably uses the other pins.

But having logic tied together means the logic has to take into account any pullups and pulldowns to resolve. (And yes, "driven" will override any pullup/pulldown, and a strong pull up/down will override a weak pull down/up, respectively).

Re: Truth or Sim

2012-11-11 06:40 • by M.L. (unregistered)
TRUE, FALSE, UNDEF, SIM

Maybe the author was preparing his code for quantum computing. SIM = simultaneous (true and false)

Re: Truth or Sim

2012-11-13 04:39 • by Captain Boolean (unregistered)
394715 in reply to 394118
Invoice for new keyboard in the post!

Captcha: Paratus, Even almighty!

Re: Truth or Sim

2012-11-23 07:38 • by toshir0
395476 in reply to 394118
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."
So be IT.

Re: Truth or Sim

2013-06-20 02:06 • by true_Ouch_false (unregistered)
if (x == false) {x = true};

This can actually save cycles and bandwidth:
Say you have x in your desktop box but setting x is logged at the server. Fhen, if you set x, you'll have to wait until the server logs "User set x to true" and tells your box that it did. Checking if x isn't already true takes place in your box, which takes only nanoseconds or less. Setting x to true adds network traffic and a wait which is usually some microseconds, if not milliseconds. Depending on your environment, it may be better to avoid as many logged actions as possible.
/* If you have to check for performance reasons, it always deserves a comment - */
/* or some other coder will rewrite it and bottleneck the LAN eventually */

if (a) foo(a); else foo(a);

I must confess that I wrote that code twice. Once, it survived for weeks, the other one more like ten minutes. (Decent compilers detect that kind of waste and compile foo(a); anyway) The old code used to be

if (a) foo_nonzero(a); else foozero(a);

Both times, the old foo_nonzero() had been improved to handle zero, thus eliminating the need for foo_zero.
So, I'd say that an if (a) foo(a); else foo(a); is not a WTF. It's an artifact of old code. Unless it's in new code. Then it IS a WTF.

About x.isTrue() and all the "boolean" silliness, some of them are less silly if they imply a type cast to boolean. However, type-casting is a WTF waiting to happen /* if it's not documented */

Capcha: causa.
As in, "I code in VB, causa fucked up manager duzn't allow any real language"
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment