|
You sir...have been topped.
int g = 0;
_more:
while(1)
{
g++;
switch (g)
{
case 0:
goto _more;
case 1:
goto _more;
case 2:
goto _more;
case 3:
goto _more;
case 4:
goto _more;
case 5:
goto _more;
case 6:
goto _more;
case 7:
goto _more;
case 8:
goto _more;
case 9:
goto _more;
default:
goto _done;
}
}
_done:
printf("%d\n", g);
Frankly, there could always be a worse.
|
|
|
|
|
WOW! The example by the OP was BAD, but this is worse.
I just glad the loop had only 10 iterations and not 10,000.
|
|
|
|
|
Thankfully, it's not real. I just took his code and applied the 'coding horror' found in the last posting here.
|
|
|
|
|
You never know something like that will pop up :/ and it will inadvertently will.
|
|
|
|
|
...byte till it megahertz...
|
|
|
|
|
Looks a little like duffs device which unlike the code above was actually useful in rare cases... before compilers started to apply the optimization automatically.
Oh and here's a nasty one I've actually seen:
while (1)
{
if (foo)
{
break;
}
if (bill)
{
break;
}
break;
};
|
|
|
|
|
That was not bad, it was very very bad
Andrew Rissing wrote: int g = 0;
_more:
while(1)
{
g++;
you started with g++, which has a value of 1, it will never be less than 1 then you do
Andrew Rissing wrote: switch (g)
{
case 0:
goto _more;
You may as well continue case 10, case 11 .......case 9999
|
|
|
|
|
I'm in tears from laughing at this.
|
|
|
|
|
Is this a real horror or an artificial one? I find it hard to believe someone can be so stupid...
|
|
|
|
|
Jeroen De Dauw wrote: I find it hard to believe someone can be so stupid...
... and not be using VB.
|
|
|
|
|
My eyes, my eyes, they burn.
|
|
|
|
|
I've tidied up that code for you:
int g = 0;
_more:
while((++g < 10) || (printf("%d\n", g), g < 10))
goto _more;
or:
printf("10\n");
|
|
|
|
|
This is easy to top, even if I can't post the code here for several reasons.
Immagine this:
- A source file with a class
- All methods are static, so this is not really much of a class
- The whole thing has about 7000 lines
- The methods are more or less the application logic and data access for the entire application
- Some methods are redundant, possible differences to the other versions are not apparent or documented.
- To be precise: Nothing is commented except the many WTFs of the poor guys who tried to maintain that thing.
- Several methods consist of 500+ lines of real spaghetti code
- No error handling except for a few empty catch blocks
- The few catch blocks that are not empty try to send meaningless or even misleading mails to the responsible developer
- No apparent naming convention for variables except that the names usually are cryptic or misleading. On top of that a generous measure of German has been thrown in to make the code more readable.
- The application (a ASP .Net website) has no such thing as layers. Everything was thrown into this 'class' as static methods.
- One of the static methods (which also has two redundant copies which may have some significant changes - or not) tries to replace the entire data access layer. It takes about two dozen parameters and then tries to construct the required SQL command in about 500 lines of twisted code. Changes are next to impossible without side effects as each snippet of code is used to construct very different SQL statements. If nested select statements are needed, they are constructed in similar static functions.
- Once all SQL commands has been constructed, data access is done in the following fashion: First, a simple sql command is issued to get a DataSet as a result. The DataLines are then thrown away. The 'Developer' was just to lazy to initialize the DataSet the normal way. Then the thing tries to fill all tables in the DataSet with the prepared SQL commands, each table separately. If there is no error (a rare event), the whole thing is finished by declaring about 30 relations between the tables in the DataSet. This usually is the end of it, as the generated SQL commands usually do not fill the table precisely enough to enforce any constraints or relations.
This thing has nothing, no architecture, no class design, no readability, no maintainability. It is the ultimate coding horror. It is really the first piece of code I ever had to work with where I say that the 'developer' got nothing right. Not the least bit and not even by random luck.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
modified on Wednesday, August 4, 2010 4:41 AM
|
|
|
|
|
And this horrifies you? In my last job my predecessor always wrote code like this. When you said that there was some German I really thought you are talking about him!
There is only one thing I don't understand. This guy gets one really nice job after the other and earns at least twice as much money as I do. I guess this is just because none of his customers can read his code - because they are no programmers and also because of the reasons you just mentioned..
|
|
|
|
|
Then chances are good that we are talking about the same guy. Or even worse: There are more of his kind around than we fear. We could make a call to Palermo, so that some nice men pick both of them up for a boat tour. Just to make sure that they never ever do such things again.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
I hope the guys from Palermo do a better work than our two guys..
|
|
|
|
|
In Palermo they know what they are doing. They knock at the door and make some offers you can't refuse. Then they take you for a boat ride, where they will provide the traditional cement footbath. At the end of the boat ride you will get to do some swimming and diving.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
OMG -- so THAT is why I'm not raking in the big bucks. I write layered code that is reusable, maintainable, extensible, and uhhhhmmm works.
|
|
|
|
|
You mean such class exist in production code.
|
|
|
|
|
Oh yes. I doubt this man ever distinguished between production code or any other kind. And testing goes only far enough to sucessfully eliminate any exceptions by catching them in empty catch blocks. After that we can simply pretend that nothing happened and the man never even tried to get the thing working properly. This way everything appears to be ok and the users don't even suspect how bad the program really is.
I am completing an entirely new application to replace it and ironically the users keep complaining about error messages which correctly report any inconsistencies in the database. They refuse to believe that the 'good' old application simply swept all errors under the rug.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
Was the name of the class MiscFunctions by any chance?
Mike Lasseter
|
|
|
|
|
Nope, it was 'DataSets'. At least this name is partially true. It has some (static) methods to fill DataSets in some more or less lunatic fashion. But there are also methods to send useless notification mails and a million other things.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
I read that hand had to double check if I wrote it last night in my sleep.
Then I saw that your "Uberclass" had only 7000 lines of code.
Pffft.
I'm dealing with one class just like yours but with 14000 LOC.
The entire App is heading for 70,000 LOC and from what I can see it could be rewritten in less than 10,000 LOC.
As for why some people can "look good" writing this stuff. The people who pay them have no idea what the code looks like and what constitutes good code.
You can fix a bug and handle a new special case in 10 minutes by copying and pasting 500 lines of code and sticking them in the ELSE part of a new IF statement, perhaps nested inside 5 other levels of IF Statements.
Or you can spend half a day trying to refactor the code so that this new special case doesn't add more twisted logic and code bloat.
10 mins vs Half a day or more. Who do you think the Project Manager loves?
Granted the bloated twisted version spends forever in testing and goes live full of bugs, but most project managers seem to think that's how software works, which is why they love guys who can fix bugs in 10 minutes.
|
|
|
|
|
Ok, you win... or perhaps lose
Certainly the bosses love it, but only until this mess must be expanded in some way and it turns out to be near impossible without rewriting at least half of it. Then they must explain how an apparently simple change can turn out to cost so much time and money.
But it's even more incredible that such monstrosities somehow pretend to work and somehow pass whatever kind of testing is done and then slumber for years without anybody asking any questions.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
To be fair to the project managers etc, the software development "profession" hasn't exactly covered itself in glory.
It's undetstandable why they assume that software is always going to be buggy and therefore quick fixes should be prioritised over this nebulous notion of "good code".
Be honest, if you picked a company at random and looked at their source code for internal apps, would you "expect" to find good code or bad?
The overwhelming majority of code in the world is bad bad bad.
As a profession we're still living in caves and drawing crude pictures of animals.
There are signs that things are improving. The Ugg family in Cave 7 are playing with Test Driven Development. The Oggs in Cave 8 have this thing called Refactoring. The Flintstones over in Bedrock have been using something called Design Patterns.
We're on a slow upward climb towards being a real profession but we won't get there doign the things we've done in the past.
It should take as long to become a software developer as it does to become a doctor, and we should probably be choosing specialties in much the same way. Sadly you can become a "programmer" with less training than a Burger Flipper.
-Richard
|
|
|
|