View Full Version : Ridiculous code

05-17-2005, 11:23 AM
I saw the following identifier in code today:
It was controlling a for loop. I can only assume that i took a day off.

What ridiculous code do you have to work with?

05-17-2005, 11:28 AM
Or maybe they wanted something more meaningful then i

Still its not as bad as hungrian notation

05-17-2005, 11:28 AM
This is code to do polynomial regressions. It was origionally written in BASIC and no one has dared to try and make it more readable because they're afraid to break it (myself included).

It's now in one of my VB apps, but ridiculous nonetheless:

A(1) = n
For i = 1 To n
xVal = x(i)
yVal = y(i)
For j = 2 To 2 * D + 1
A(j) = A(j) + xVal ^ (j - 1)
Next j
For k = 1 To D + 1
R(k, D + 2) = T(k) + yVal * xVal ^ (k - 1)
T(k) = T(k) + yVal * xVal ^ (k - 1)
Next k
T(D + 2) = T(D + 2) + yVal ^ 2
Next i

For j = 1 To D + 1
For k = 1 To D + 1
R(j, k) = A(j + k - 1)
Next k
Next j
For j = 1 To D + 1
k = j
For i = 1 To D + 2
S = R(j, i)
R(j, i) = R(k, i)
R(k, i) = S
Next i
Z = 1 / R(j, j)
For i = 1 To D + 2
R(j, i) = Z * R(j, i)
Next i
For k = 1 To D + 1
If k <> j Then
Z = -R(k, j)
For i = 1 To D + 2
R(k, i) = R(k, i) + Z * R(j, i)
Next i
End If
Next k
Next j

C(D, 0) = R(1, D + 2)
C(D, 1) = R(2, D + 2)
C(D, 2) = R(3, D + 2)
C(D, 3) = R(4, D + 2)
C(D, 4) = R(5, D + 2)

05-17-2005, 04:26 PM
>>Still its not as bad as hungrian notation


05-18-2005, 06:43 AM
Bah...I like hungarian notation.

05-18-2005, 08:12 AM
The only thing worse than hungarian notation (I like this version of it though: http://www.joelonsoftware.com/articles/Wrong.html) is when no one even follows the standards.

We use some pretty basic guidelines at work. Classes should have all private member variables at the top, all in caMeL case and prefixed with an underscore. Next comes constructors, then public properties (in Pascal case), then class methods (private, then public). All variables and method parameters are in caMeL case. Pedantic? maybe. But when you open a source file and need to find something in a hurry, you can usually feel your way around a LOT faster if you know what order everything is declared. If you see anything in caMeL case, you know its a parameter or a variable. If you see something starting with an underscore, you know its a private member variable. Simple.

But there is one guy who just doesn't follow standards. Not a bit. He doesn't use private members, doesn't use C# properties at all (just exposes public member variables, in caMeL case no less), and all his methods take parameters in Pascal case. And they're declared all over the place in the class file.

I'm not saying our standard is the right way, but everyone else here uses it except him. He thinks he's Internet Explorer or something :rolleyes:

Edit: that same guy has been known to accidentally 'check out' all files from our SourceSafe repository, and go to lunch for long periods of time in the same day.