|
A couple of years back I had a chap working in my team who knew various .Net specifics but didn't really seem to understand programming at all. He produced various pieces of "interesting" code but this was his finest hour:
bool moreThanOneModelTypes = (vehicle.PossibleTypes.Length > 1);
switch (moreThanOneModelTypes)
{
case true:
this.ddlVehicleFullModelType.Items.Add(new ListItem("- - - please select - - -", "-1"));
goto default;
case false:
goto default;
default:
foreach (VehicleType vehicleType in vehicle.PossibleTypes)
{
this.ddlVehicleFullModelType.Items.Add(new ListItem(vehicleType.DisplayName, vehicleType.Id));
}
_fullVehicleModelTypeReload = false;
break;
}
So that's a single-line if statement replaced with a multi-line switch, plus some gotos for good measure all because he got bored of if..else.
|
|
|
|
|
The default in this is surely a marsterwork par excellance. I must have been misinformed, boolean=true|false|maybe.
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
You should applaud the genius for holding into account quantum mechanics!
|
|
|
|
|
|
Is this guy in his 50's, bald, close-set eyes? If it is, I used to work with him :shudder:.
|
|
|
|
|
one half of me is LMAO, the other half is straight faced and the rest is thinking if that can be incorporated in my own code.
...byte till it megahertz...
|
|
|
|
|
LOL @ three halves
Before .NET 4.0,
object Universe = NULL;
|
|
|
|
|
I have to ask - was there ever a case in which the default clause executed? Did the author honestly expect it to?
Bear in mind that Boole's wife was also a mathematician, and in her algebra there were three states: "true", "false", and "it depends..."
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Just found
Is it GPLed ?
Can I use this portion of code?
|
|
|
|
|
While that code snippet may indeed produce the desired effect it is one of the most convoluted ways I have seen of doing a simple task. See my sig.
You should tell that guy about the International Obfuscated C Code Contest (IOCCC[^])
Just because the code works, it doesn't mean that it is good code.
modified on Wednesday, August 25, 2010 2:40 PM
|
|
|
|
|
Okay, hello Coding Horrors!!! A while ago I stumbled upon this delightful piece of code, which appears in a much larger monster that is (thankfully) obsolete. This loop also has a number of shorter variants covering the case of 7, 6, 5, 4 etc cameras. It cracked me up in any case, and I'd like to share it. To this day, I haven't worked out whether the person who wrote it was a fool, a genius, or both!
Enjoy =)
if (pairCount>=28)
{
errBounce = FLOAT_MAX;
for (i1=0; i1<pairCount-14; i1++)
{
for (i2=i1+1; i2<pairCount-13; i2++)
{
for (i3=i2+1; i3<pairCount-12; i3++)
{
for (i4=i3+1; i4<pairCount-11; i4++)
{
for (i5=i4+1; i5<pairCount-10; i5++)
{
for (i6=i5+1; i6<pairCount-9; i6++)
{
for (i7=i6+1; i7<pairCount-8; i7++)
{
for (i8=i7+1; i8<pairCount-7; i8++)
{
for (i9=i8+1; i9<pairCount-6; i9++)
{
for (i10=i9+1; i10<pairCount-5; i10++)
{
for (i11=i10+1; i11<pairCount-4; i11++)
{
for (i12=i11+1; i12<pairCount-3; i12++)
{
for (i13=i12+1; i13<pairCount-2; i13++)
{
for (i14=i13+1; i14<pairCount-1; i14++)
{
for (i15=i14+1; i15<pairCount; i15++)
{
centroid[0] = (estBounce[i1][0] + estBounce[i2][0] + estBounce[i3][0] + estBounce[i4][0] + estBounce[i5][0] +
estBounce[i6][0] + estBounce[i7][0] + estBounce[i8][0] + estBounce[i9][0] + estBounce[i10][0] +
estBounce[i11][0] + estBounce[i12][0] + estBounce[i13][0] + estBounce[i14][0] + estBounce[i15][0])/15.0;
centroid[1] = (estBounce[i1][1] + estBounce[i2][1] + estBounce[i3][1] + estBounce[i4][1] + estBounce[i5][1] +
estBounce[i6][1] + estBounce[i7][1] + estBounce[i8][1] + estBounce[i9][1] + estBounce[i10][1] +
estBounce[i11][1] + estBounce[i12][1] + estBounce[i13][1] + estBounce[i14][1] + estBounce[i15][1])/15.0;
centroid[2] = (estBounce[i1][2] + estBounce[i2][2] + estBounce[i3][2] + estBounce[i4][2] + estBounce[i5][2] +
estBounce[i6][2] + estBounce[i7][2] + estBounce[i8][2] + estBounce[i9][2] + estBounce[i10][2] +
estBounce[i11][2] + estBounce[i12][2] + estBounce[i13][2] + estBounce[i14][2] + estBounce[i15][2])/15.0;
dis1 = PointDistance(centroid, estBounce[i1]);
dis2 = PointDistance(centroid, estBounce[i2]);
dis3 = PointDistance(centroid, estBounce[i3]);
dis4 = PointDistance(centroid, estBounce[i4]);
dis5 = PointDistance(centroid, estBounce[i5]);
dis6 = PointDistance(centroid, estBounce[i6]);
dis7 = PointDistance(centroid, estBounce[i7]);
dis8 = PointDistance(centroid, estBounce[i8]);
dis9 = PointDistance(centroid, estBounce[i9]);
dis10= PointDistance(centroid, estBounce[i10]);
dis11= PointDistance(centroid, estBounce[i11]);
dis12= PointDistance(centroid, estBounce[i12]);
dis13= PointDistance(centroid, estBounce[i13]);
dis14= PointDistance(centroid, estBounce[i14]);
dis15= PointDistance(centroid, estBounce[i15]);
dis = dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15;
if (dis<errBounce)
{
w1 = (dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w2 = (dis1+dis3+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w3 = (dis1+dis2+dis4+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w4 = (dis1+dis2+dis3+dis5+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w5 = (dis1+dis2+dis3+dis4+dis6+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w6 = (dis1+dis2+dis3+dis4+dis5+dis7+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w7 = (dis1+dis2+dis3+dis4+dis5+dis6+dis8+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w8 = (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis9+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w9 = (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis10+dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w10= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis11+dis12+dis13+dis14+dis15)/(dis*14.0);
w11= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis12+dis13+dis14+dis15)/(dis*14.0);
w12= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis13+dis14+dis15)/(dis*14.0);
w13= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis12+dis14+dis15)/(dis*14.0);
w14= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis12+dis13+dis15)/(dis*14.0);
w15= (dis1+dis2+dis3+dis4+dis5+dis6+dis7+dis8+dis9 +dis10+dis11+dis12+dis13+dis14)/(dis*14.0);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
errBounce /= 15;
}
|
|
|
|
|
Geoff Bolton wrote: To this day, I haven't worked out whether the person who wrote it was a fool, a genius, or both
Granted I only glanced at the code for, like, 1 minute, but I haven't figured it either!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I dont think that code will terminate
|
|
|
|
|
I'd like to see how this guy would create software to manage a global system. How many TiB would the source be?
|
|
|
|
|
The for() loops seem a rather verbose way of generating all 37,442,160 combinations of 15 pairs chosen from 28, but I wouldn't say they're necessarily horrible. If it is indeed necessary to enumerate all the combinations, nested 'for' loops seem a verbose but time-efficient way to do it. The w1..w15 calculations seem icky, though. Much better to compute the sum of dis1..dis15, and subtract one item from that computation.
|
|
|
|
|
Seems like a classic case for recursion to me...but I'm too tired to both trying to code it now...
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Auch! It is terrible. I'm sure this can be reduced to a O(n^2) complexity with a smart algorithm and some precalculations/caching. If not, a simple recursive method can do it.
Greetings - Jacek
|
|
|
|
|
My God. It looks like some of the old stuff lying around at my company.
|
|
|
|
|
Below is an HTML file. Try to guess which DIV will be invisible in IE, then scroll down to see why...
<html>
<head>
<title>WTF</title>
<style type="text/css">
div
{
filter: alpha(opacity = 100);
border-color: Green;
border-style: solid;
border-width: 1px;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div style="background-color: #020509;"></div>
<div style="background-color: #02050A;"></div>
<div style="background-color: #02050B;"></div>
</body>
</html>
The middle DIV will be transparent because any element with the color #02050A that also has the filter set to an opacity (even if fully opaque) will appear transparent in IE8 (and probably other versions of IE).
|
|
|
|
|
Quite a feature.
This[^] seems to suggest one is in trouble as soon as some pixel in an image has that particular color!?
|
|
|
|
|
Quite right; that's actually one of the links I came across when Googling this issue. I am using jQuery to fade between images for a slideshow. Only problem is that some of the pixels would appear white during the fade transition. Turns out this IE bug is the reason why that's happening. The fix we decided on was to put a black image behind the images so that the transparent pixels will appear to be black. We could have also edited each image so the pixels weren't that specific color, but that's a bit hard to do when JPEG compression can alter colors... and I don't think the artists would appreciate having to edit a certain color out of all their images.
|
|
|
|
|
The real fix is to not use IE at all (not really an option, of course)
|
|
|
|
|
aspdotnetdev wrote: The fix we decided on was to put a black image behind the images so that the transparent pixels will appear to be black.
Could you use a background color that was 1 RGB value from from the transparent color? (e.g. #02050B instead of black) I think the difference wouldn't even be perceptible at that point.
Before .NET 4.0,
object Universe = NULL;
|
|
|
|
|
That's basically what we did, but we chose black, which is close enough to the color that the difference is imperceptible.
|
|
|
|
|
Oh, do you mean change the color of the ORIGINAL image, rather than the image behind it? As I explained in the post you replied to, that would be extra work for the designers and, due to JPEG compression, would be troublesome.
|
|
|
|