# True or False?

•  I discovered this working out some logic bugs in some IDL code. This isn't the same IDL that you might have heard of. This is Interactive Data Language, a propietary language used primarily by astronomers and astrophycisists. In IDL, ~ is the logical not operator.

if (a || ~a) then print, "WTF"

if (a) then print, "WTF"
else if (~a) then print, "WTF"

Although these 2 pieces of code are logically equivilant, the first will always print "WTF" but the second will sometimes fail. (This example is not based on actual code, I just came up with this to test out the WTFs of the language.)

• @tOmcOlins said:

but the second will sometimes fail

In what way?  For example, does the computer sit there and pick it's nose?

Also, when you say sometimes.. Is that, perhaps, when "a" is null?

• When I say "fail," I mean the code inside the if...else blocks is not executed. So when the if statements fails, I have no idea what the hell the computer is doing.

When a is null is one of the times when both codes execute properly.

Most of the people here have experience in C(++) and it's assumed when they're hired that they'll pick up the IDL as they go. I've found a ton of cases where assuming IDL works like C will burn you.

• @tOmcOlins said:

if (a) then print, "WTF"
else if (~a) then print, "WTF"

if 'a' really is a boolean, then it should be sufficient to write

if (a) then print, "WTF"
else print, "WTF"

There's no need to evaluate 'a'as well as '~a'. Does that work reliably? Is the language interpreted or compiled? Can you check out the generated machine instructions?

Is it possible for the value of 'a' to change between the first and second time it's evaluated?

• @Nandurius said:

Is it possible for the value of 'a' to change between the first and second time it's evaluated?

That was my first thought, but then I realized that you'd have to experience the mother of all side-effects. Or that the boolean or operator is just a complete and utter joke.

• Wow, not THAT is a blast from the past... IDL...

Early on in my career (80s) I was sales engineer/product specialist for a package called PV-WAVE, effectively a commercial version of IDL with a GUI 'n'stuff. Ran on MicroVAXen, IIRC, and SunOS.

Loved working with it, especially at trade shows where I would take nifty astronomical images and do all kinds of stuff with them.

Now, it's been forever but wasn't one of the things about IDL that you could do operations like the one you list on just about anything? I mean anything, including having "a" be a 500MB 3-dimensional array of environmental data? Which could come from just about any source.

So, is "a" a scalar? Or some vector data in a form such that mathematically a != ~(~a) ?

Ah, memories... now THERE was a WTF company if there ever was.

I remember when they flew the entire international staff to the US HQ for a "world sales meeting" with parties and what not. Two days after they had laid off 50% of US staff. So, we were told in effect, to party hard only when it was international staff members and act subdued while interacting with US team members.

That's only a slight exageration - see, the products were selling well outside the US, or rather still had a good sales pipeline in the cycle, so all the outside-US sale droids had made quota and then some. But, the US market was in recession, they had had a string of bad products that failed (but hadn't entered the international market yet anyway), and the company was being mis-managed into the ground. Same old, same old, in other words.

The one product that was doing pretty well everywhere was bought from the outside - above-mentioned PV-WAVE. Or I think it did - I bailed a short time later, with the writing on the wall.

•  @tOmcOlins said:

When a is null is one of the times when both codes execute properly.

Com'on, code has no plural form when referring to programming. Or at the very least, use codez.

• A boolean that can be null ?

I have to update my bool enum then...

<FONT color=#0000ff size=2>enum</FONT><FONT size=2> BOOL</FONT></FONT><FONT size=2>

{

TRUE,

FALSE,

FILE_NOT_FOUND,

NULL

};

Case closed

</FONT>

• @Manos said:

<font color="#0000ff" size="2">enum</font><font size="2"> BOOL</font><font size="2">

{

TRUE,

FALSE,

FILE_NOT_FOUND,

NULL

};

</font>

What about the NOT_ASSIGNED value? That's different from null, because null is an actual value of bool, while NOT_ASSIGNED means that the variable wasn't initialized. You definitely lack of knowledge of proper boolean data structures.

• @derula said:

@Manos said:
<FONT color=#0000ff size=2>enum</FONT><FONT size=2> BOOL</FONT><FONT size=2> </FONT><FONT size=2>

{

TRUE,

FALSE,

FILE_NOT_FOUND,

NULL

};

</FONT>

What about the NOT_ASSIGNED value? That's different from null, because null is an actual value of bool, while NOT_ASSIGNED means that the variable wasn't initialized. You definitely lack of knowledge of proper boolean data structures.

You are right of course, but you forgot the all important DONT_CARE (X), and the HALF_WAY_THROUGH_INITIALISATION.

George Boole has nothing on me.

<FONT color=#0000ff>enum</FONT><FONT size=2> BOOL</FONT><FONT size=2> </FONT><FONT size=2>

{

TRUE,

FALSE,

FILE_NOT_FOUND,

NULL,

NOT_ASSIGNED,

DONT_CARE,

HALF_WAY_THROUGH_INITIALISATION

};

</FONT>

All I need now is to redefined Karnaugh maps to use my new enum.

• @Manos said:

```<font color="#0000ff">enum</font> BOOL {      TRUE, FALSE, FILE_NOT_FOUND, NULL, NOT_ASSIGNED, DONT_CARE, HALF_WAY_THROUGH_INITIALISATION };```

You forgot the holy grail of some programmers, RESERVED:
```<font color="#0000ff">enum</font> BOOL {      TRUE, FALSE, FILE_NOT_FOUND, NULL, NOT_ASSIGNED, DONT_CARE, HALF_WAY_THROUGH_INITIALISATION, RESERVED };```

• IDL is an interpretted language (slow as hell too) with no built in bool type. After a little experimenting and reading, I've found out that IDL evaluates the following as true:

non-null pointers and arrays, non-zero floating point numbers, odd integers

and the following as false:

null pointers and arrays, zero valued floating point numbers and even integers

Even worse: the not operator ~ still works just like it does in the C family (!), so 4 would be evaluated as false, but ~4 is which is still false! You might be able to get around this by exploiting the even/odd wtf using the bitwise NOT operator, since bitwise negation on an integer changes the parity. (Though this might be platform dependant)

I could probably fill up the entire forum with IDL WTFs, but I think this is great:

In IDL, everything (absolutely everything) is passed by reference. Presumably to save memory.  It also has what I think is called weak typing. If I write a function that expects an integer arguement, somebody can pass a double, string or even a 500x500x500 array to the function and IDL won't complain. In addition, there is nothing like const, or any way to guarentee than a function won't modify your data, or even turn your 500x500x500 array into a char. To get around this, IDL reccomends that you make a copy of it before passing it into a function.

• @tOmcOlins said:

It also has what I think is called weak typing. If I write a function that expects an integer arguement, somebody can pass a double, string or even a 500x500x500 array to the function and IDL won't complain. In addition, there is nothing like const, or any way to guarentee than a function won't modify your data, or even turn your 500x500x500 array into a char.

A good deal of languages have this same feature.  Amazingly, the world doesn't implode because the code is tested prior to being deployed.  So it's not a WTF at all, although it's funny to hear you talk about dynamic languages as if they were some strange invention of a deranged mind.  The rest of IDL sounds pretty sick, though.

• Yes, I know a quite a few languages have this so called "feature," and even a couple of good languages have it. You can probably tell that I have little experience in dynamic languages (a couple of python hacks) and a much stronger background in compiled C-family languages. Most preliminary testing is done in interactive mode, so it's very annoying if I make a typo or mix up the order of arguements which causes my data to be destroyed and not even be notified.

• But in order to be <FONT face="Courier New">HALF_WAY_THROUGH_INITIALISATION, it must first be QUARTER_WAY_THROUGH_INITIALISATION, and before that... </FONT>

<FONT face="Courier New">namespace ZENO { enum BOOL { NOT_ASSIGNED } };</FONT>

• @tOmcOlins said:

Yes, I know a quite a few languages have this so called "feature," and even a couple of good languages have it. You can probably tell that I have little experience in dynamic languages (a couple of python hacks) and a much stronger background in compiled C-family languages. Most preliminary testing is done in interactive mode, so it's very annoying if I make a typo or mix up the order of arguements which causes my data to be destroyed and not even be notified.

So you need the compiler to protect you from typos and calling functions incorrectly?  What do you do about logic errors?  Oh, nevermind...

Also: lern2quote

• @morbiuswilters said:

So you need the compiler to protect you from typos and calling functions incorrectly?

Yes.

I can take care of memory all by myself though!

• @DrJokepu said:

@Manos said:

```<font color="#0000ff">enum</font> BOOL {      TRUE, FALSE, FILE_NOT_FOUND, NULL, NOT_ASSIGNED, DONT_CARE, HALF_WAY_THROUGH_INITIALISATION };```

You forgot the holy grail of some programmers, RESERVED:
```<font color="#0000ff">enum</font> BOOL {      TRUE, FALSE, FILE_NOT_FOUND, NULL, NOT_ASSIGNED, DONT_CARE, HALF_WAY_THROUGH_INITIALISATION, RESERVED };```

You still missed one -- MAYBE

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.