- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
When Visceral Baysuck has reached sufficient mass to have a periodic table of operators, it shall have achieved Perlesque coolness.
Admin
It's actually quite consistent with the rest of the language and philosophy of the language. I think it's better than the C-splat version where you have the opaqueness of overloading that depends on the type of the references. I imagine that the Java way produces more confusion up-front but the C-splat version causes unexpected gotchas in seemingly simple code. In other words, the C-splat way might seem more simple but it's actually more complicated as it has more syntax rules.
Admin
Eventually, you'll be able to execute an empty script with Perl and it will do anything and everything.
Admin
Your comment is sufficiently opaque for me not to understand.
Admin
You both need to learn to use Google.
That's like me saying "It's C99", and you responding, "How could you say its not GCC?", and then following up, "I think C99 is some sort of official name for Borland Turbo C". (Well not quite, JavaScript actually does support basically all of the ECMA-262.pdf specification whereas Turbo C does not support the ISO/IEC 9899:1999 standard, but you get the idea).
C'mon people.
Admin
You're kidding, right??! Special syntax for short-circuiting boolean operations??? Now I've seen everything.
-dZ.
Admin
Amen to that.
Admin
I some how managed to forget java doesn't have operator overloading, as its Too Confusing ™
Admin
The answer: ECMA [ European Computer Manufacturers Association ], upon publishing the standard in collaboration with both Netscape® and Microsoft®, elected to name it after themselves as to avoid any trademark issues.
Honestly I think the US Justice Department should have taken Microsoft® to town for using the name JScript which was clearly an attempt to snag the term JavaScript ™ from Netscape.
Admin
Admin
if ((typec!="20") && (typec!="13") && (typec!="5") && (typec!="4"))
-dZ.
Admin
sorry for the post*2, but the site script crashed on me the first time :(
-dZ.
Admin
I wonder if VB.Net allows open-ended threatening commands in its syntax, like to avoid exceptions at all costs. Something like:
If (theLordCommandsThee) Then
sacrificeYourFirstBorn() OrElse
End If
-dZ.
Admin
I must be incredibly fortunate to be working with people who are all excellent at what they do. How sad for the rest of y'all.
Admin
Even in VB6 or VBScript, short-circuiting was possible with another construct: SELECT CASE.
Select Case True
Case var1 = "This", var2 = "That", func3() = "The Other"
' do stuff ...
End Select
(Ross turns his head while all the fanatical non-VB users retch at the "abuse" of the case statement. Dammit, it works. 90% of what you call "WTF" I call "RTFM".)
Admin
I, too, work with people who are all excellent at what they do, though I don't consider myself fortunate. The problem is that what these pepole do is mostly goof off, surf the web, chat in IM, or at best mediocre work -- but they all excell at this!
-dZ.
Admin
Admin
Don't Forget Pascal
Admin
I like how ONE is an int but FOUR is a string :)
Admin
> Don't Forget Pascal
True, Pascal has an "in" operator, but it only works on sets which can only be groups of ordinal values. You can't have a set of strings. If typec was an integer, then you could do:
if (typec in [4,5,13,20]) then ...;
or if typec was a character, you could do
if (typec in [#4,#5,#13,#20]) then ...;
Of course neither of these use nearly enough resources. In Delphi what you could do is something like this for a start:
sl := TStringList.Create;
sl.CommaText := '4,5,13,20'; // split string into substrings
nIndex := sl.IndexOf(typec); // look up typec
if nIndex = -1 then ...; // typec not found in list
Why just use boring old integers when you can bring all of this other excellent technology to bear on the problem?
Admin
Every good programmer knows that 4, 5, 13 and 20 are the four unluckiest integers.
Admin
Actually, there is no reason why it couldn't be C. Who says typec couldn't be a pointer to characters? Then the performing the type conversion would be a terrible waste of time....
(Not that I think it is actually C.)
Admin
Lucio - Pascal has sets, irritatingly limited to a one-byte range and slightly hampered by its stupid decisions on operator precedence, but in this case they'd work. You'd do something like this:
if (Temp < 0) or (Temp > 255) or not (Temp in [20,13,5,4]) then
DoStuff;
Note the error checking: if you're converting a string to an integer, presumably you could run into a case where the string isn't a valid number, so StrToIntDef will solve that for you. Then, of course, you have to deal with the byte limit.
A better solution from the programmer's POV is the PHPish
DoStuff();
}
... which requires less fiddling. Rasmus is much less anally retentive than Niklaus, obviously.
Admin
Yeeeeeeeeeees... that would raise the WTF to a hole 'nother level... perhaps the line above is
char *typec = &"20";
and perhaps the runtime stores constant strings in space-saving fashion a-la-Java...
Perhaps...
Admin
Just for grins, COBOL would say
if code not 4 and 5 and 13 and 20
do something
I always loved that syntax. It's a macro-like shortcut for
if code not 4 and code not 5 and code not 13 and code not 20
Admin
In Smalltalk one could do:
(#('20' '13' '5' '4') includes: typec)
ifFalse: [self doStuff].
Admin
I think the problem with that when read as an English sentence it means something other than what it does.
Admin
Yup - #define nor and
if code not 4 nor 5 nor 13 nor 20
(aah)
Admin
VB's Select Case does basically that.
Admin
Even if it was VB 6 (which it plainly isn't), that would be no excuse. VB 6 has Select Case which supports lazy evaluation - that would have been used instead of the style shown in this WTF.
Admin
Obviously it is possible, somehow and it keeps this site chock-full-o-laffs. Perhaps the hiring is done by a non-technical manager or HR person without consulting a tech person (mistake!) or maybe a manager doesn't want to terminate someone who should be terminated (mistake!) or there may be a hiring freeze (mistake!).
Admin
To stop you all embarassing yourself further, the fact is that And and Or in VB 6 are not boolean operators. Never have been, never will be. They are bitwise operators.
Admin
The thing is, Microsoft originally wanted to make that change to VB.NET, so that the And/Or/Not became logical operators and short-circuited. But all the people maintaining legacy VB6 applications complained, so they changed it back:
http://archive.devx.com/free/newsletters/vb/ednote040601.asp
This can only mean that some VB6 programmers were actually relying on the non-short circuiting behavior of these operators to make their programs work. And there had to be a lot of them, for MS to feel the pressure and make this change to VB.NET. There must be a lot of scary, scary WTF code out there.
The good news is, this site could keep going for decades.
Admin
Admin
In keeping with the new VB.Net operators, I think C++ should add an OrElse operator.
Except, its use would be a bit different:
a = func(b) orelse;
More like a threat. It could, you know, ignore exceptoins.
try {
Class *c;
c = 0x00;
c->op() orelse; // This wouldn't throw an exception, just silently fail.
} catch(...) {
}
Admin
Now now, don't be misleading folks. No operator overloading, sigh... '+', when used for 1 + 1 returns the sum of the two ints, or 2. When used for "foo" + "bar" it returns the first string, elongated by the second string, or "foobar." That's most certainly an overloaded operator. At the risk of being nitpicky, I just thought I'd provide the lesson in word choice. Besides, who doesn't love having the easily accessed ability to compare either the references to two strings or the strings themselves? ;)
Admin
(java, of course)
Admin
I'm not going to go into all the why's, but early returns are a Good Thing (tm) ! Return early, return often !!
Admin
Ding Ding Ding, we have a winner! The last one is not correct but hey, 2 out of 3 is pretty good.
Admin
sure you didn't mean :
<font face="Courier New">switch(typec)
{
case 20:
case 13:
case 5:
case 4:
break;
default:
SelectType("ALLOC");
break;
}</font>
Admin
Maybe this site should have a section where people can have a go a bad code and make it worse.
Admin
And to embarass you a bit, here's a little factlet:
http://msdn.microsoft.com/library/en-us/script56/html/vsoprand.asp
From that article, I extracted the following statements:
"AND Operator - Performs a logical conjunction on two expressions."
Is that's "logical", as in "boolean"?
"The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result..."
Wow, that's the first time I've ever seen the word "also" to mean "exclusively"!
Here's the VB.6 reference, it says the same thing:
http://msdn.microsoft.com/library/en-us/vbenlr98/html/vaoprand.asp
BTW, I am not a VB coder (thank Gawd for that!), so I do not attempt to defend, promote, or condone the language -- I am merely a google user.
dZ.
Admin
I'd go for that!
dZ.
Admin
>> the fact is that And and Or in VB 6 are not boolean operators.
>> Never have been, never will be. They are bitwise operators.
> From that article, I extracted the following statements:
> "AND Operator - Performs a logical conjunction on two expressions."
> Is that's "logical", as in "boolean"?
If you write some code in VB.NET using And, AndAlso, Or, OrElse, compile it to IL and then use Reflector (http://www.aisto.com/roeder/dotnet/) to view the IL as C# you find that
And in VB.NET is & in C#
Or in VB.NET is | in C#
AndAlso in VB.NET is && in C#
OrElse in VB.NET is || in C#
Hence And/Or are bitwise and AndAlso/OrElse are boolean.
Admin
Your logic is flawed.
Admin
Meh.
#!/usr/bin/perl
use Quantum::Superpositions;
SelectType("ALLOC"), return if $typec != any(20,13,5,4);
see http://search.cpan.org/~lembark/Quantum-Superpositions-2.02/lib/Quantum/Superpositions.pm
Admin
in java (afaik) doing: String a = "thisString"; creates a new object, and the variable 'a' is actually a pointer, you just never see the pointer. When you compare, using == or whatever, you are actually comparing the pointers So, doing: if (a=="thisString") { something(); }
is doing: if (pointer)a is exactly equal to (pointer)[new String] then do something().
now, afaik, something() will never happen, because the second pointer (the new String) cannot be the same as the pointer stored in 'a'
Admin
"I wonder if VB.Net allows open-ended threatening commands in its syntax ..."
It'd have to go a bit before it achieves the classic bluntness of Perl's idiomatic:
DoIt() or die;
Admin
Wrong! The C# *interpretation* of And/Or from VB.Net might be a bitwise comparison -- but it says nothing about how it works in its original form.
Besides, what Mathew said was that "And and Or in VB 6 are not boolean operators..." (emphasis mine). I have no idea if Microsoft changed the behaviour in VB.Net to make the And/Or operators exclusively bitwise, but I seriously doubt it, as it would work against their goal of separating short-circuit from non-shortcircuit boolean operators, for backwards compatibility's sake -- which was their point to begin with.
Unless, of course, you are suggesting that what MSDN documentation means by "logical operations" is actually "bitwise operations", and that "boolean" and "bitwise" are one and the same in VB 6's operational context -- which would make this whole argument moot, as the point of Mathew's pedantic post was that we were all fools to consider that VB 6's And/Or operators were boolean instead of bitwise.
-dZ.
Admin
Actually I think in this case a == "thisString" is actually true because all occurences of a String literal become the same String object. if it was for example a string you got from the command line then it would be false.
I really didn't get this for a good while. the problem was when I was learning java I was told there were no pointers. In fact pointers are fundamental in java and every non-primitive variable is really a pointer.
As for doing the "in" operator in java you could do:
if (Arrays.asList(new String []{"12", "34", "3"}).contains(test))
{
}
Beautiful no? :P