- 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
Is the first one Java? That would just be:
String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
C# probably have a similar construct. And I can't remember if C++ does. WTF!
Admin
>>Shudder<<
That second block of code reminds me of a project I used to work on at a previous employer. The code was littered with non-sensical varaible names, while loops that included the comma operator in the conditional statement, and a big for loop that looked exactly like this.
Admin
Exhibit A is just dumb but doesn't cause much headache. I would send the developer to some training. Exihibit B is much more worse because probably the whole application is tangled in this for-switch-***. I never would allow the developer of this beast to write one line of code anymore until he has undergone some kind of Cobol exorcism.
Admin
Classic examples of people overcomplicating really simple things.
Admin
Thats what happens when you pay people 'by the line'.
I assume theIdea [I] is in place of the [i], is that supposed to be there or a bug?But a real moocher would of thrown in some useless comments
Admin
The second one looks almost like a state machine but what's the deal with:
case 1: break;
Why bother putting that in there? Must have been maintained by someone who thought "I'm not messing with this piece of ***."
Admin
<FONT face="Courier New">for( int i = 0; i < 7; i++ ) {
switch(i) {
default:
case 0:
</FONT>
It's good that the developer included the <FONT face="Courier New">default:</FONT> in case the <FONT face="Courier New">for</FONT> loop went crazy and decided to go outside its bounds... [;)]
Admin
The real WTF here is that he didn't unroll that loop. It should have been like this:
etc.
Admin
Actually, this would be a great idea for creating a code bloating script. Just turn any set of sequential statements into a for/switch. CA$H UP THE A$$
Admin
Dude, even C has a way of setting all of the variables! I typically type it all the way out, for readability (when you're up late at night, sometimes you can do very weird things in code).
Think char ** argv in the "main" of a C program.
argv[1]="Monday"; argv[2]="Tuesday"..
Admin
are you retarded? That would be the most code bloat I've ever seen. I hope you were being sarcastic...
Admin
Has anyone ever really paid people 'by the line' of code? The concept keeps getting mentioned (I assume facetiously) but I've never heard of it in real life.
Admin
Bustaz, you beat me to it. As I read this thread, the same exact thought crossed my mind. I'm curious about that also.
Admin
I've know that a lot of managment types think it's a reliable way to measure developer productivity. More code == bigger raises and more clout. It might explain all the copy / paste code I see.
Admin
I sure as hell hope not, will prolly make for useless and bloated code :S
Admin
I give you bulk rate on code! Very cheap! Free <FONT color=#000000>Viagr</FONT>@ too!
Admin
You have to look at this code in context. By using a loop, the developer is multi-threading the process, resulting in a more performant and scalable solution. Another advantage of Exhibit B is it allows new steps to be inserted into the process by simply creating another number in the case statement. Personally I would have numbered the steps 10, 20, 30, and so on. That way if you need to put a new step in you could use 25 for example. Its all about writing maintainable code.
Admin
Yes in C you can do:
char *szDaysArray[] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
and in pure C++ using the STL you have to use an itermediate array because you can't directly initialize a vector. So in C++ it would be:
std::string daysArray[] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
std::vector<std::string> vStr(daysArray,daysArray+7);
I'm not sure what C# has either but this is a definite WTF in just about every language I've ever used. It's a shame it seems to be such common practice.
</std::string>
Admin
I recognize this too as sarcasm. Perhaps I can develop the ability to recognize it after all! There IS hope for me yet!
Admin
And I can now quote people in FireFox! YAAAAAAY!
Admin
This makes me think of Duff's Device:
http://www.lysator.liu.se/c/duffs-device.html
I suppose the "For-Case" paradigm is something like the opposite of Duff's Device.
Admin
Ah, that takes me back to my Apple ][ days. Programs in BASIC used line numbers, because there was no file editor, just a command line, and each line typed in was inserted by its line number. By convention, line numbers went in steps of 10, so you could add more lines later on. If you wanted to add more than 9 lines between two old lines . . . Why would anybody want to ever do that?
Admin
Duff's device has to be one of the coolest abuses of C of all time. I use it for copying buffers of data from one file to another. This For-Case thing is something I've never seen in any real life code but from all the examples people post somebody is obviously writing this stuff. What is even more amazing is that they actually continue having jobs that involve writing code. Cross your fingers and hope they were some first year analyst fresh out of college that was instructed as to the correct way of doing these things and not some ten year VB veteran coding in the cube next to you.
Admin
This is probably the best way yet to reinvent line numbers and stuff them into a reasonably modern programming language.
Admin
If you want to see something awesome, check out Duff's Device:
http://catb.org/~esr/jargon/html/D/Duffs-device.html
An awesome piece of c hackery on top of it, implementing coroutines:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
And then protothreads, better than sharks with laser beams on their heads:
http://www.sics.se/~adam/pt/
Admin
It's not shown in this example but it's also a way to simulate gotos in languages that do not support them.
Admin
This is without a doubt the most idiotic piece of code I've ever seen.
Please please please tell me this is a joke.
Admin
show me how, and maybe I'll believe you.
Admin
:S Ug. Makes me want to upchuck seeing this kind of code.
Admin
Grrrr... Should be able to edit the posts... The Emoticon does not work for me... Could be Firefox? Have to try in (gulp) IE.
Admin
<font size="2">With regards to sample A, it's not a joke, it is Java, and the problem was largely due to the fact the developer had just been sent on training. He'd apparently just seen how "useful" case statements could be, and decided that maybe he should be using more of them...
Thankfully I worked for that company 4 years ago, and haven't seen anyone do this since.</font>
Admin
C# syntax is the same as java....
-Andy<FONT size=2>
</FONT>Admin
You might not believe me even if I show you how?
for (int i = 0; i < 100; i +=10; i++){
switch (i) {
default:
break;
case 0:
doSomething();
break;
case 10:
doSomthingElse();
break;
case 20:
if (doSomethingMore()) {
i = 9; // goto 10
}
break;
case 30:
if (isFoo()) {
i = 19; // goto 20
}
break;
}
}
Admin
That's terrible, but it made me smile. :-) Is modifying the iterator count during a switch even allowed/documented in C?
But, I believe you. Even so, I don't know of any language that does a C-like switch (and no exceptions), and doesn't have a goto, which would make it completely useless except for really pathological cases.
Admin
<FONT face="Arial Unicode MS">Exhibit B doesn't even make sense! The programmer knows enough to procedurlize (sp?) their code, and knows how to use a for loop and a switch statement....so WhyTF would they do this?! is it so that there is a slight - and I mean bloody slight - pause between the calling of the individual procs? That would explain the:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT>
<FONT face="Arial Unicode MS">case 1:
break;<o:p></o:p></FONT>
<FONT face="Arial Unicode MS">This code just makes me cry. [:'(]<o:p></o:p></FONT>
<o:p></o:p>
Admin
The problem with that thread is: looks like you all here has nothing else to do but to demonstrate how stupid others are.
I'm not new in programming and trust me put alot of stupid things in my code and was paid "by lines" and/or "by time" and/or "by output" and/or "by speed" and etc. during my career.
I understand the reason you may laugh at presented samples, but trust me -- your laugh has nothing to do with the real "brush fire extinquishing" you have to deal with sometimes in your everyday programming life. So, kindly excuse me, but there is no reason to joke about somebodies bad programming practices.
On the other hand and being serious here: whatever language you choose -- I agreee you saved somespace in not typing that "laughable" switch statement and not confusing others, but instead used specific language/compiler feature and just use declarative approach -- end result is still the same: "During runtime equivalent of that long case was executed"... So, what exactly are you laughing about?!...
Admin
Of course it's allowed. Is it a good idea? Not usually -- it's normally a side-effect of something else (generally using assignment "=" instead of equality comparator "=="), but I'd be willing to bet that just about everybody has modified an iterator variable in a loop in every language that has 'em at one time or another.
Admin
Are you the author of Exhibit B?
Admin
Yeah, hit a nerve I think.
Admin
You can do what I have shown in Java, which has no goto (goto is reserved but cannot be used.)
This is actually a technique that was once suggested (seriously) to someone who wished to convert a large amount of goto filled code to Java.
Admin
My main concern was that a for loop in C is such an "interesting" mix of actions, it would qualify as a WTF itself.
I'm not all that surprised that it's allowed in C, but on the other hand, I would not be terribly surprised if a compiler translated
for (i=0; i <10;i++) {
i++;
}
to (pseudocode):
int i=0;
LOOP:
if (++i < 10) {
int some_var = i;
some_var++;
goto LOOP;
}
either.
god I hate the "rich-text" editor in this forum software.
</snip>
Admin
Apparently you equate 'brush fire estinguishing' with garbage code. The code given was clearly not a fix. It takes planning and a lot of work to construct such a foolish construct.
The complete incompentence of the developer(s) who wote this. I spend a lot of time fixing code that is as screwed up as this or worse. I get to vent some frustration. Sorry you feel threatened by this. It kind of makes you look like an incompetent.
Admin
Sure we've all done stupid sh!t in our code. I hate going back and looking at code I wrote when I first started, it's embarrasing. We all start somewhere. However roasting bad code in public forums does serve a purpose. People can come and laugh and also learn what not to do. I like coming here and seeing mistakes(especially non-obvious ones) in languages that I don't know well. So when I do use those languages I don't make the same mistakes.
Admin
Ok, but who the hell would use GOTOs for that kind of code? I mean, OK, if you don't have exceptions, by all means use gotos if you need to break out of a stack, but jeez, even if you don't have a goto, there's still break and continue in java...
Admin
The only reason I've replyed was that as I undertsood the original joke placed at the beginning of the thread was to show that government workers are on break 7 days a week. Now, somehow thread moved into discussion of "programming practices".
Now, in your next responce you may name me not just being incompetent, but rather "being incompetent government worker". And I'm not threatened by this. Please, continue.
As to whether I'm really competent or not: It's not you who decides. What matters is how much we are making and are we really happy. You frustration obviously shows that you are not.
Admin
I realized that (it seems) nobody has congratulated Alex on the excellent name for today's post. Good job. [:)]
Admin
I'm happy about somethings and not about others. I'm rather unhappy that the MO for IT managment these days is to outsource (offshore and onshore) major developement to incompetent developers and then make full time developers maintain it.
Admin
No argument here.
Admin
Here I agree -- MO screews everything.
However, your criticism an claim that original code was stupid hypothetically may not be the case. In fact it may not be as stupid as it looks like.
Just imagine that String class is not really string class as we understand it -- maybe it's more complicated then just string and which is more important it just can't be initialized by just "" object (let's assume it's a structure having 100 members that are filled based on time of day passed).
Or, In addition -- that class could be implemented just as a singleton (or maybe it just a proxy to singleton) -- So, any declarative initialization described as a "proper solution" will initialize real singleton to "Sunday"? Isn't that what we want?
So, my point is: it's always much efffortless to criticize -- this criticizm doesn't pay your bills though.
Admin
Here's a nice one in CORBA:
IDL:
server-side:
client side:
at least it's both Y2K and Y10K compliant.