Darren Winsper ([info]dwinsper) wrote,
@ 2006-11-28 10:21:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Testing, testing
Here's a test for you. If I execute the following VB.Net code:
Dim retarded As Object = Nothing

System.Console.WriteLine("VB.Net is " & IIf(Not retarded Is Nothing, retarded.ToString(), "not retarded"))

What is the output? Answer in a few hours.

P.S. Kendrick can't take part as he already knows the answer :P



(7 comments) - (Post a new comment)


[info]newsbot3
2006-11-28 10:37 am UTC (link)
is this a wtf? moment?

(Reply to this)


[info]erunamo
2006-11-28 01:12 pm UTC (link)
Having not really done any VB I'm guessing this is equivalent to:

void *retarded = NULL;
printf("VB.Net is %s", ((!(retarded==NULL)) ? "retarded" : "not retarded")));

which should produce "VB.Net is not retarded" however I'm guessing that it in fact produces "VB.Net is retarded"

(Reply to this) (Thread)


[info]dwinsper
2006-11-28 02:12 pm UTC (link)
Try again ;)

(Reply to this) (Parent)


[info]andrew_j_w
2006-11-28 04:05 pm UTC (link)
Presumably it parses Not retarded is Nothing as (Not (retarded is Nothing)) causing it to print the string representation of Nothing, whatever that is.

If this is the problem then in Python they get around it by writing 'retarded is not None'

(Reply to this) (Thread)


[info]dwinsper
2006-11-28 05:05 pm UTC (link)
(Not (retarded is Nothing)) evaluates to False, though.

(Reply to this) (Parent)(Thread)


[info]andrew_j_w
2006-11-28 05:14 pm UTC (link)
Oh, whoops. Then I guess ((Not retarted) is Nothing). Which really makes no sense, but I guess that's the point...

(Reply to this) (Parent)

Testing, testing
(Anonymous)
2007-02-19 08:38 am UTC (link)
The problem is the eager evaluation of each of the arguments to the Iff function. All three of the expressions, including "retarded.ToString()", are always evaluated before the call to Iff. This will cause an attempt to dereference a null reference, which I'm sure everyone will agree is extremely retarded. ;)

BTW this (mis)behaviour has been with VB since the very early versions. Yikes!

Jonathan

(Reply to this)


(7 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…