- 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
Holy crappola that is stupid
Admin
Stuff like this makes my head hurt.
The other WTF, assuming this is a good idea, is that it can only accept 3 arguments for any function. Not very expandable, now is it?
Admin
Wait, so this function takes a ton of arguments...only to perform several different functions in a switch/case?
What is so hard about making a simple function "create()"?
Admin
I guess arrays are out of the question.
Admin
<font size="1">omg.
I've seen this before. I worked with a guy who was asked to write a database access layer. He came back a month later with a single function that accepted a string parameter, did a massive switch/case, and executed whatever dynamic sql block the param was supposed to specify.
</font>
Admin
Truely this person must be a master of the Dark Side of the Force,
to take something good and pure and twist it into something so wrong.
Admin
<font size="1">
No, it accepts up to 9 args.
I also like that he specified Variants and Objects. I thought Variants could also hold object references. (my VB is rusty, so I could be wrong on this).
</font>
Admin
Poor Giles Olaliberries. You've certainly seen horrible things.
I think today's WTF is a GREAT example of overloading. I'm sure the whole JVM is implemented that way behind the scenes.
[:|]
Admin
So, bascially, the equivalent of
MyFunc(1,2,"Hello");
would be
ExpandableFunction("MyFunc", "HelloWorld",null, null, 1, 2, null, null, null, null);
?
Admin
What hapens when you call CInt on a String?
Admin
Matt should tell that predecessor of his about operator overloading. I shudder to think what that person would come up with for
<FONT face="Courier New">String a = "stuff ";</FONT>
<FONT face="Courier New">String b = "your face";</FONT>
<FONT face="Courier New">String ab = a + b;</FONT>
Admin
And no optional parameters? Yick.
Admin
he he .. this is too much.
OK ... Maybe he got tired of declaring variables and all those silly compile-time errors, so he turned off Option Explicit. But even after doing that, the damn compiler STILL complained ! He then realized that apparently it still wanted him to declare all the functions and procedures as well ! How annoying!
The ingenius solution (that I am sure he is quite proud of) : Make all function and procedure names TEXT STRINGS, all called through this one function, so that you NEVER get a compile time error ! And no annoying declaration statements in your code is needed ! Only 1 function name to spell correctly and remember !
In fact, with this new model, no more errors will *ever* occurr at design time OR run-time ! This might be the best code this planet has ever seen, or ever will!
Truly, a masterpiece !
Admin
If the string is numeric, the converted (& truncated if decimal) int is returned.
If it's not, an exception is thrown (whoops...VB...) it blows up.
Admin
Spot the bonus-WTF...
Admin
While the first line of the description is a little over "exposed", it does set up the horror beneath fairly well.
Admin
I'm guessing that's just a bug in Alex's transciption/anonymizer code...
Admin
Also, there's no return type for the function, so it defaults to Variant.
The caller has to know that "CREATE" (or whatever function) is supposed to return an Object (or whatever type) so it can cast it. Makes it even harder to use.
Maybe this is a misguided attempt to code anonymous methods or Lisp-style lambda functions in VB. Or maybe it's just a big, fat, steaming WTF.
ugh. Why do I keep looking at it?
Admin
I really need to get that fixed ;-)
Admin
there are legitimate times when control coupling makes sense (pick any number of GoF patterns - Factory, Command, Strategy, Decorator)...this is not one of them and this is certainly not a good way to implement it.
I now not only have to write new code to consume the function, but at a new select statement and the new function itself.
I think tomorrow we should teach this programmer about polymorphism. It'll be a duct tape moment for sure (wrap duct tape around their head so when it explodes, it keeps the pieces from flying everywhere -- we used to do the same thing for our computers during hurricaines using duct tape and garbage bags).
If you're going to reinvent the wheel, try not to make it a triangle or a rectangle.
Admin
This is brilliant! I've always wondered whether or not it would be possible to write a program that is completely recursive. I'd never thought of doing anything this crazy though! Awesome!!!
Admin
How would you pass 7 UDT's or COM objects? Can't do it. First 3 args are Strings.
Admin
Well, its in VB, which is loosely typed anyway. So i don't really see what difference it makes. [;)]
hahahahahahahaha!!!!!!!!!!!! What a knob gobbler...
Admin
I didn't say what types those 9 could be.
If you wanted to pass 6 strings and 3 objects, no problem.
Last I checked, 6+3 = 9.
Admin
You could pass 9 COM objects.
The first 3 strings would have to be ProgId's, which you would CreateObject() on.
The other 6 could be references to object instances.
Admin
Nope, it's 11...this function goes to 11...
Admin
After a sound beating with the clue bat, Matt’s predecessor becomes enlightened on the True Meaning of functions! In a 48-hour coding marathon, he rewrites the entire code to a new and much improved form! Oh, it still has Function ExpandableFunction(), but now it’s written as:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
...and so on.<o:p></o:p>
Matt reaches for the bigger clue bat.
--RA
<o:p></o:p>
"Do. Or do not. There is no try. Except in C#." –Yoda<o:p></o:p>
Admin
Talk about mudflaps, this code's got 'em....
Admin
You could pass unlimited parameters by converting them into XML and stuffing them into the first String parameter. And that would work across the network... I think I'll call that... BORAX. No... SOAP.
Admin
Granted I haven't done Basic since my Atari days. (Must not make smart comment about how much better it was than the C64) but can't he eliminate that one function with a goto somehow?
somethign like:
call = "initialize"
start:
Switch Case call
Case "initialize"
...
call = "nextWhatever"
goto start
Again, I have not used VB at all, but isn't there a syntax something like the above that would eliminate the need for even one function. Afterall if you are going to write bad code, why not go all the way?
Admin
This seems familiar somehow.
Admin
You know, the stuff I have to deal with here makes most of these posts look like nothin'.
Here is one of the BEST segments of code I have seen in this system:
<font size="2">
var test= mainStr.split("|");
for(var i=0; i<=4;i++)
{
switch (i)
{
case 0:
{
sHTML += 'Affiliation' + '="' + test[i] + '" ';
break;
}
case 1:
{
sHTML += 'Product' + '="' + test[i] + '" ';
break;
}
case 2:
{
sHTML += 'Company' + '="'+ test[i]+ '" ';
break;
}
case 3:
{
sHTML += 'CompanyGroup' + '="'+ test[i]+ '" ';
break;
}
case 4:
{
sHTML += 'Persona' + '="' + test[i] + '" ';
break;
}
break;
}
}
</font>
Obviously, this is a total wtf...why in the...
But that's nothing! Nothing I tell you.
I run into stuff like this daily Keep in mind the stuff in the CDATA sections is supposed to be perl, that the <iw_ tags="" get="" compiled="" into="" perl="" at="" runtime="" and="" eval'd="" (a="" really="" ugly="" system="" that="" comes="" from="" the="" vendor="" but="" wait="" until="" you="" see="" them="" actually="" use="" it=""><iw_iterate> is a for-each loop and "iter" is an optional index. Key word in that statement is optional. The dcr sections come from this really nasty mechanism called a "data capture record", and they are basically equivilent to records of input.
<font size="2"><iw_iterate var="scroll" list="dcr.ScrollingDisclaimer" iter="count71"></iw_iterate>
<iw_perl><!--[CDATA[</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> if ($disclaimerflag < 0 || $disclaimerflag == 0) { $disclaimerflag = 1; }</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> if (!defined $disclaimerflag || $disclaimerflag == "") { $disclaimerflag = 1; }</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> ]]--></iw_perl>
</font></iw_iterate><font size="2">
<iw_iterate var="nonscroll" list="dcr.NonScrollingDisclaimer" iter="count72"></iw_iterate>
<iw_perl><!--[CDATA[</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> if ($disclaimerflag < 0 || $disclaimerflag == 0) { $disclaimerflag = 1; }</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> if (!defined $disclaimerflag || $disclaimerflag == "") { $disclaimerflag = 1; }</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> ]]--></iw_perl>
</font></iw_><font size="2">
<iw_iterate var="scrolldisclaimer" list="dcr.ScrollingDisclaimer" iter="count79"></iw_iterate>
<iw_perl><!--[CDATA[</span><br style="font-family: courier new;"> <span style="font-family: courier new;">$disclaimer = iwpt_dcr_value("scrolldisclaimer.DisclaimerText");</span><br style="font-family: courier new;"> <span style="font-family: courier new;">if ($disclaimerflag gt "0" || $disclaimerflag != 0) {</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> iwpt_output("</span><br style="font-family: courier new;"> <span style="font-family: courier new;"><div class=\"scrolldisclaimer\">$disclaimer</div></span><br style="font-family: courier new;"> <span style="font-family: courier new;"> ");</span><br style="font-family: courier new;"> <span style="font-family: courier new;">}</span><br style="font-family: courier new;"> <span style="font-family: courier new;">]]--></iw_perl>
<iw_iterate var="nonscrolldisclaimer" list="dcr.NonScrollingDisclaimer" iter="count79"></iw_iterate>
<iw_perl><!--[CDATA[
$nondisclaimer = iwpt_dcr_value("nonscrolldisclaimer.DisclaimerText");
if ($disclaimerflag gt "0" || $disclaimerflag != 0) {
iwpt_output("
");
}
]]--></iw_perl>
</font>
And if thats not bad enough for you, at the end of the template is this...
<font size="2"><iw_perl><!--[CDATA[</span><br style="font-family: courier new;"> <span style="font-family: courier new;">if (iwpt_dcr_value("dcr.Option.PrinterFriendly") == true &&</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> iwpt_dcr_value("dcr.Option.PrinterFriendly") != false) {</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> $dcr_name = iwpt_get_dcr_name();</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> $workarea = iwpt_get_dcr_name();</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> $iw_home = TeamSite::Config::iwgethome();</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> $workarea =~ s#\\#/#g;</span><br style="font-family: courier new;"> <span style="font-family: courier new;"> $workarea =~ s#(/WORKAREA/[^/]-->
my $pt_name = iwpt_get_pt_name();
$pt_name =~ s{.tpl}{_p.tpl}g;
my @args = ('C:/Interwoven/iw-home/local/bin/generate_pfile.ipl', "$workarea", "$dcr_name", "$pfile_name", "$pt_name");
`@args`;
}
]]></iw_perl>
</font>
And I've got thousands and thousands of lines of this crap to wade through.
That's right, You remember correctly. == is a numerical comparison and there are no "true" or "false" boolean primitives in perl.
All I have to say is, thank goodness this is a contract!
Admin
You know, the stuff I have to deal with here makes most of these posts look like nothin'.
Here is one of the BEST segments of code I have seen in this system:
<font size="2">
var test= mainStr.split("|");
for(var i=0; i<=4;i++)
{
switch (i)
{
case 0:
{
sHTML += 'Affiliation' + '="' + test[i] + '" ';
break;
}
case 1:
{
sHTML += 'Product' + '="' + test[i] + '" ';
break;
}
case 2:
{
sHTML += 'Company' + '="'+ test[i]+ '" ';
break;
}
case 3:
{
sHTML += 'CompanyGroup' + '="'+ test[i]+ '" ';
break;
}
case 4:
{
sHTML += 'Persona' + '="' + test[i] + '" ';
break;
}
break;
}
}
</font>
Obviously, this is a total wtf...why in the...
But that's nothing! Nothing I tell you.
I run into stuff like this daily Keep in mind the stuff in the CDATA sections is supposed to be perl, that the <iw_ tags get compiled into perl at runtime and eval'd (A really really ugly system that comes from the vendor, but wait until you see them actually use it). <iw_iterate> is a for-each loop and "iter" is an optional index. Key word in that statement is optional. The dcr sections come from this really nasty mechanism called a "data capture record", and they are basically equivilent to records of input.
<font size="2"><iw_iterate var="scroll" list="dcr.ScrollingDisclaimer" iter="count71">
<iw_perl><![CDATA[
if ($disclaimerflag < 0 || $disclaimerflag == 0) { $disclaimerflag = 1; }
if (!defined $disclaimerflag || $disclaimerflag == "") { $disclaimerflag = 1; }
]]></iw_perl>
</iw_iterate>
<iw_iterate var="nonscroll" list="dcr.NonScrollingDisclaimer" iter="count72">
<iw_perl><![CDATA[
if ($disclaimerflag < 0 || $disclaimerflag == 0) { $disclaimerflag = 1; }
if (!defined $disclaimerflag || $disclaimerflag == "") { $disclaimerflag = 1; }
]]></iw_perl>
</iw_iterate>
<iw_iterate var="scrolldisclaimer" list="dcr.ScrollingDisclaimer" iter="count79">
<iw_perl><![CDATA[
$disclaimer = iwpt_dcr_value("scrolldisclaimer.DisclaimerText");
if ($disclaimerflag gt "0" || $disclaimerflag != 0) {
iwpt_output("
<div class="scrolldisclaimer">$disclaimer</div>
");
}
]]>
</iw_perl>
</iw_iterate>
<iw_iterate var="nonscrolldisclaimer" list="dcr.NonScrollingDisclaimer" iter="count79">
<iw_perl><![CDATA[
$nondisclaimer = iwpt_dcr_value("nonscrolldisclaimer.DisclaimerText");
if ($disclaimerflag gt "0" || $disclaimerflag != 0) {
iwpt_output("
<div class="nonscrolldisclaimer">$nondisclaimer</div>
");
}
]]>
</iw_perl>
</iw_iterate>
</font>
And if thats not bad enough for you, at the end of the template is this...
<font size="2"><iw_perl><![CDATA[
if (iwpt_dcr_value("dcr.Option.PrinterFriendly") == true &&
iwpt_dcr_value("dcr.Option.PrinterFriendly") != false) {
$dcr_name = iwpt_get_dcr_name();
$workarea = iwpt_get_dcr_name();
$iw_home = TeamSite::Config::iwgethome();
$workarea =~ s#\\#/#g;
$workarea =~ s#(/WORKAREA/[^/]+)/.*#$1#; # Strip off anything after "/WORKAREA/$WAName"
my $pt_name = iwpt_get_pt_name();
$pt_name =~ s{.tpl}{_p.tpl}g;
my @args = ('C:/Interwoven/iw-home/local/bin/generate_pfile.ipl', "$workarea", "$dcr_name", "$pfile_name", "$pt_name");
`@args`;
}
]]></iw_perl>
</font>
That's right, You remember correctly. == is a numerical comparison and there are no "true" or "false" boolean primitives in perl.
Admin
You mean dynamically typed.
Admin
You guys are morons, this is a part of a scripting engine.
It takes a function with tokenized parameters.
Lamers, bashing without a clue.
Admin
Uhh... guys... I've got a brilliant idea for how to re-implement this!
OK, here goes:
There you go! No need for complicated dependencies! It actually makes your program compile faster, because changing the set of exported functions doesn't break existing binary objects so they don't have to be recompiled... because you just add a new call to the dispatch... wait... they wouldn't be recompiled anyway because they're already exported... I mean... wait... screw it I can't defend it, but... IT USES JAVASCRIPT AND XML SO IT MUST BE GOOD!!!
;)
Admin
What about the fact every parameter is passed by REFERENCE !!!!!!!!
Admin
"this is a part of a scripting engine."
That was the first thing i thought of, infact i started ti write something like that (i knew it was bad but i couldnt find any other way), then i came across the brilliant CallByName function which made it a lot nicer.
Admin
>You guys are morons, this is a part of a scripting engine.
>It takes a function with tokenized parameters.
>Lamers, bashing without a clue.
Maybe us morons and lamers have heard of Eval before ?
T.
Admin
sure, but that could potentially lead to serious security holes.
Admin
I always wondered how you can do aspect oriented programming in VB... now I know the answer ;-)
Admin
This is great! It's like that time when the Adam West Batman poured alphabet soup unto the Bat Computer to solve The Riddler's riddle!
Admin
The linux kernel code for socketcall() looks remarkably like this. Just why they didn't implement one system call per socket function is beyond me.
Fun,
Sten
Admin
But you did anyway, didn't you? There is nothing better than a C64. Up to today, the Information Technology industry is struggling to make a system as innovating as our beloved Commodore 64.
Admin
Been there, called that; with XML documents passed as strings for bonus points.
It was a CORBA server (also in a COM edition); the excuse for inflicting users a single method interface was reducing coupling and binary dependencies.
Admin
Just look at IDispatch::Invoke in COM. Any function you like called through that.
But that is an early-bound function enabling a late-bound interface, so it's got good reasons for its existence.
Admin
How un-fecking-believable...Really...
....Must go sit in my quiet place now....
Admin
I think you made a slight spelling mistake
s/Commodore 64/BBC Micro/
s/C64/Beeb/
There - all better now!
Admin
Incorrect. If the string is not numeric, CInt returns a 0.
Admin
At least it's only ONE function.
The SQL DB I inherited uses the same "logic" in all the stored procedures, only using a passed in "function" parameter instead of the strFunctionName and a series of IF statements in the SP. The same set of additional parameters is used in every stored procedure.
Each proc can return various result sets and/or perform various updates to the database. And every proc is called exactly the same as every other except for the name of the proc.
Maintenance is a NIGHTMARE!
But at least I'm not the only one to have to deal with this madness - as today's WTF shows...