Comment On Rarely Just TRUE or FALSE

Our friend R.L. writes in with a twist on a common snippet, illustrating an important scientific fact: solutions in life are rarely just TRUE or FALSE ... [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Rarely Just TRUE or FALSE

2007-02-08 09:05 • by nelle (unregistered)
#define FILE_NOT_FOUND 3 // is missing

captcha: tesla - yeah charge me up ... ups ...

Re: Rarely Just TRUE or FALSE

2007-02-08 09:17 • by Jens (unregistered)
MAYBE I just read that...

I often sit back with the feeling, that something is missing. There's gotta be some kind (good or most likely bad) of explanation to WHY this was done.

CAPTCHA: Sanitarium - Thanks, needed that after reading this

Re: Rarely Just TRUE or FALSE

2007-02-08 09:20 • by skztr (unregistered)
It's forwards-compatible with quantum computers. No WTF here.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:22 • by MB (unregistered)
Another variation on a classic anti-pattern.


Hooray!

Re: Rarely Just TRUE or FALSE

2007-02-08 09:26 • by anon (unregistered)
What? No FileNotFound?

captcha: doom - it shall be coming to Sarnath

Re: Rarely Just TRUE or FALSE

2007-02-08 09:28 • by Ed Heil (unregistered)
Dude should be programming Haskell!

http://www.haskell.org/onlinelibrary/maybe.html

Re: Rarely Just TRUE or FALSE

2007-02-08 09:31 • by Winter (unregistered)
Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness

Re: Rarely Just TRUE or FALSE

2007-02-08 09:31 • by passer by (unregistered)
117806 in reply to 117804
#define MAYBE_NOT 3

Re: Rarely Just TRUE or FALSE

2007-02-08 09:34 • by codemoose (unregistered)
117807 in reply to 117806
#define LIKELY 4

Re: Rarely Just TRUE or FALSE

2007-02-08 09:36 • by MadMike (unregistered)
Maybe some sort of lazy-evalutation scheme?

Re: Rarely Just TRUE or FALSE

2007-02-08 09:37 • by TheMagic8Ball (unregistered)
#define ALL_SIGNS_POINT_TO_YES 13

Re: Rarely Just TRUE or FALSE

2007-02-08 09:41 • by steven22 (unregistered)
If he had called it UNKNOWN instead of MAYBE, would you guys be okay with it?

Re: Rarely Just TRUE or FALSE

2007-02-08 09:42 • by erKURITA (unregistered)
#define WTF (!TRUE && !FALSE && FILENOTFOUND)

B)

Re: Rarely Just TRUE or FALSE

2007-02-08 09:42 • by mkb
117813 in reply to 117805
Winter:
Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness


Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:44 • by Super the Pieman. (unregistered)
Shenanigans.

And tat.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:45 • by akatherder
I like the fact that someone else could define FALSE as 1 or 50 and his code won't even fix that.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:46 • by J Random Stranger (unregistered)
This sounds like a workaround for the sorts of glitches that always come up when you test for geometric intersection when using floating point forms.

There are shapes that clearly intersect or not intersect. There is also a class of shapes where roundoff errors can give you false answers. Generally this class involves abutting shapes where the end vertices are not coincident. Because the two shapes touch, but don't intersect, roundoff errors can give you a relatively random result.

Answering "MAYBE" may be a bit silly, but having some way of indicating that there has been a precision loss is a good idea in these sorts of applications.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:46 • by Benanov
117817 in reply to 117809
TheMagic8Ball:
#define ALL_SIGNS_POINT_TO_YES 13


Compiler produced this warning:

REPLY_HAZY_TRY_AGAIN

Re: Rarely Just TRUE or FALSE

2007-02-08 09:47 • by Unomi (unregistered)
Indeed it is somewhat philosophic or forward-compatible with quantum informatica like someone else mentioned.

While it can not be defined as TRUE, it is simply FALSE. Who doesn't try to shoot, will always miss. So negative is default here. You can't say, 'Who doesn't try to shoot, will maybe miss'. Simple not true (thus false).

MAYBE is like 'IT_DEPENDS' or coming to some inner_check_function_wisdom to be called and resulting in either TRUE, FALSE or BOTH. Japanese people could refer to a status called 'MU'..... Not typical programming (thus an anti-pattern).

CAPTCHA: ewww (indeed, to ugly to even spit on)

- Unomi -

Re: Rarely Just TRUE or FALSE

2007-02-08 09:48 • by Unomi (unregistered)
Indeed it is somewhat philosophic or forward-compatible with quantum informatica like someone else mentioned.

While it can not be defined as TRUE, it is simply FALSE. Who doesn't try to shoot, will always miss. So negative is default here. You can't say, 'Who doesn't try to shoot, will maybe miss'. Simple not true (thus false).

MAYBE is like 'IT_DEPENDS' or coming to some inner_check_function_wisdom to be called and resulting in either TRUE, FALSE or BOTH. Japanese people could refer to a status called 'MU'..... Not typical programming (thus an anti-pattern).

CAPTCHA: ewww (indeed, to ugly to even spit on)

- Unomi -

Re: Rarely Just TRUE or FALSE

2007-02-08 09:48 • by Moose (unregistered)
I don't see this as a WTF. There are many uses for multi-value logic such as an elevator system.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:49 • by Peter Antoine (unregistered)
117822 in reply to 117804
Ed Heil:
Dude should be programming Haskell!

http://www.haskell.org/onlinelibrary/maybe.html



Lightweights!

VHDL std_logic, 9 different values for a bit. Two types of maybe, '-' = dont_care and 'X' = unknown.


Re: Rarely Just TRUE or FALSE

2007-02-08 09:49 • by Moose (unregistered)
I don't see this as a WTF. There are many uses for multi-value logic such as an elevator system.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:51 • by patrickriva
No WTF here !!

Sorry guys but this is not at all a wtf. Maybe can be seen as a legitimate way to express an "unknown" state and there is at least one language (Magik, see http://en.wikipedia.org/wiki/Magik_%28programming_language%29) that has in is own libraries a 3-state boolean defined as _true, _false and _maybe, with and/or operators that can work with those values.

Checkboxes, natural choices for a yes/no selection, have 3 states, checked, unchecked and grayed to express the unknown.

What if you have a boolean property to identify if a user is member of a XYZ association? He may answer you and let you store a Yes or a No in your tables, but if he doesn't want to tell you what are you going to store ...... ? NULL, and also in this case you need the 3rd state.

MAYBE one day you'll find yourself using a MAYBE...

Re: Rarely Just TRUE or FALSE

2007-02-08 09:51 • by dustin (unregistered)
Anonymous:
MAYBE I got the first post


lol thats pretty funny

Re: Rarely Just TRUE or FALSE

2007-02-08 09:52 • by Winter (unregistered)
117827 in reply to 117813
mkb:
Winter:
Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness


Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.


3 things I've noticed and stop me from wanting to register to post here:

"FIRST POST!!11!" occurring for three quarters of the first page of any public discussion

"The REAL WTF is ____" followed by some extremely dodgy code (usually)

and then the template posts. (What no FILE_NOT_FOUND?!, Man that sounds like job for PAULA BEAN! etc etc)

captcha is stinky. Damn right!

Re: Rarely Just TRUE or FALSE

2007-02-08 09:54 • by Jeremy Bettis (unregistered)
There is a mistake in the commentary. !TRUE cannot equal MAYBE, since !1 = 0 and !2 = 0.

The right way to evaluate booleans is always if (booleanvar) or if (!booleanvar). Or if someone is feeling pedantic, they could use if (booleanvar == FALSE) and if (booleanvar != FALSE) but they must NEVER do if (booleanvar == TRUE) just in case someone was lazy at some other point and did an assignment like booleanvar = (x != 3) since it might fill in values other than 0 or 1.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:55 • by f@ (unregistered)
Thank goodness two wrongs don't make a right. But two TRUEs certainly make a MAYBE.

CAPTCHA: dreadlocks.

Re: Rarely Just TRUE or FALSE

2007-02-08 09:56 • by bobby (unregistered)
From my past as a database admin and modeler, I'd tend to cast MAYBE as NULL - no value or no state. I've always had to explain the concept of NULL to people as "it's not zero, or MAYBE - it means it has no current state or value, which is different."

MAYBE implies that it might be TRUE, might be FALSE, might be either-or, might not. That's too ambiguous. The concept of NULL - no current state - fits situations like this pretty well.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:01 • by Kevin (unregistered)
Anonymous:
MAYBE I got the first post


OMG, you did!

Re: Rarely Just TRUE or FALSE

2007-02-08 10:01 • by jo42
#define FOURTY_TWO // Fuzzy Logic

Re: Rarely Just TRUE or FALSE

2007-02-08 10:08 • by Earl Colby Pottinger (unregistered)
The WTF to me is he did not test if 'maybe' existed.

Most languages will have libraries 'true' and 'false' already defined. If you can't trust the language included defines enough that you have test whether two states exist or not, you should also not be assuming that the define 'maybe' does not already exist.

Two lines to bullet-proof is all that are needed. The authour clearly knows how and why to do this and still builds a basic assumption into their code that can affect compiling.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:10 • by bpk (unregistered)
#define YOUR_GUESS_IS_AS_GOOD_AS_MINE 666;

Re: Rarely Just TRUE or FALSE

2007-02-08 10:10 • by bpk (unregistered)
#define YOUR_GUESS_IS_AS_GOOD_AS_MINE 666;

Re: Rarely Just TRUE or FALSE

2007-02-08 10:10 • by bpk (unregistered)
#define YOUR_GUESS_IS_AS_GOOD_AS_MINE 666

Re: Rarely Just TRUE or FALSE

2007-02-08 10:14 • by Peter Antoine (unregistered)
117840 in reply to 117827
Winter:
mkb:
Winter:
Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness


Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.


3 things I've noticed and stop me from wanting to register to post here:

"FIRST POST!!11!" occurring for three quarters of the first page of any public discussion

"The REAL WTF is ____" followed by some extremely dodgy code (usually)

and then the template posts. (What no FILE_NOT_FOUND?!, Man that sounds like job for PAULA BEAN! etc etc)

captcha is stinky. Damn right!


You forgot:

1. Reading the problem in the wrong language. (i.e. C as C#)
2. It should have been written in .... (usually Ruby, Python)
3. Assuming we are all web/database programmers.

The hell with your missle

2007-02-08 10:15 • by Jno (unregistered)
Fer crissakes, it's a missile. Count the letters, and pronounce as two syllables. Miss'eyell. There. Also please refrain from throwing them at friendly military convoys. Thank you.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:15 • by foxyshadis
So what exactly does the caller do when the function just shrugs at them? Ask again? (Keep asking in a loop until the universe ends is certainly one classic failure method.) Randomly perturb the input first? Have a SecondOpinion class with alternate implementations of every function? =p

Re: Rarely Just TRUE or FALSE

2007-02-08 10:17 • by Migala (unregistered)
#define ASK_AGAIN_LATER 111;

Re: Rarely Just TRUE or FALSE

2007-02-08 10:17 • by mkb
117848 in reply to 117827
Winter:

3 things I've noticed and stop me from wanting to register to post here:

"FIRST POST!!11!" occurring for three quarters of the first page of any public discussion


Maybe if you register and post regularly we can drown out the noise.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:18 • by jonny mnemonic (unregistered)
117849 in reply to 117813
mkb:
Winter:
Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness


Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.


No quack.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:19 • by kro (unregistered)
#define's are just plain unsafe
use enums, enums, enums, enums

By the way, I have seen the values of TRUE and FALSE swapped because the code was managing data to inverted logic :)
Would like that as an enum or would you just temporarily re-define the #define's ?

Re: Rarely Just TRUE or FALSE

2007-02-08 10:20 • by mkb
117851 in reply to 117836
Earl Colby Pottinger:
Two lines to bullet-proof is all that are needed. The authour clearly knows how and why to do this and still builds a basic assumption into their code that can affect compiling.


So the build breaks and you fix it. That's not a very good WTF. It's not insidious at all.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:24 • by mkb
117854 in reply to 117850
kro:
#define's are just plain unsafe
use enums, enums, enums, enums


#defines, enums, typedefs, and consts all have their pros and cons:
1.) You can only take the address of a const
2.) enums don't have a set value. If you are using them this way (eg enum { FOO = 2, BAR, BAZ}) or casting enums to ints, STOP.
3.) consts and enums cannot be used for macros.
4.) defines don't have a type, which is more risky than const int, const short, const unsigned int64_t
5.) #define where a typedef should be used is just stupid. I've never seen this, though.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:33 • by JamesKilton
For those that don't know (obviously the OP), there ARE three values for geometric intersections when it comes to 3D math:

- Intersects
- Does not intersect
- Touches (yes, this is different than Intersects)

The WTF here is of course the lack of checking for MAYBE, besides the name of the define.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:34 • by diaphanein (unregistered)
117857 in reply to 117854
boost has a pretty nice 3-state boolean lib:

http://www.boost.org/doc/html/tribool.html

Re: Rarely Just TRUE or FALSE

2007-02-08 10:35 • by Pon (unregistered)
Hasn't anyone here heard of Fuzzy Logic?

It's one of the most useful tools in AI, robotics, and other such fields.

It's similiar to probability, just instead of events occuring, it's about membership in sets.

For example, I'd be 75% child and 50% adult.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:39 • by Kalinka (unregistered)
Not a WTF.

When doing geometric intersections you usually first test against a bounding volume (bounding box, bounding sphere) or use some other quick-check.

The values then correspond to:

TRUE = shapes definitely intersect
MAYBE = bounding volumes definitely intersect, shapes may or may not
FALSE = shapes definitely do not intersect

Can we please have WTFs posted by people who can actually spot them? So far it seems like WTFs are "what some junior-junior-newbie-temp worker doesn't understand and therefore calls a WTF with no attempt at all to understand", or general whining of the type "My stupid boss says 2+2=5, WTF!"

True WTFs are much more subtle. They are not caused by stupidity, nor by ignorance. They are when perfectly rational people do what is perfectly rational at the time - with no deadlines and stupid bosses - but which turns out to be completely wrong in retrospect.

I know, because I have at least a dozen of them to my name.

Re: Rarely Just TRUE or FALSE

2007-02-08 10:41 • by DmR (unregistered)
117863 in reply to 117833
#define FOURTY_TWO //Crappy spelling

captcha: riaa - really idiotic, always a-holes

Re: Rarely Just TRUE or FALSE

2007-02-08 10:44 • by merreborn's nemesis (unregistered)
Seriously, using #define to redefine true and false is just stupid. The programmer should just have to return true, false, or (as seems to be needed here) an enum value.

enum
{
Intersects,
Tangent,
Disjoint
};

CAPTCHA: tesla...as in shockingly bad code
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment