|
Very prosaic.
P.S. And only counts as one statement anyway.
modified on Monday, December 29, 2008 2:07 PM
|
|
|
|
|
Interesting.
Not a word that comes to mind when reading that.
|
|
|
|
|
this seems to be one of the most common horrors' posted here and also one of the most common I come across...
|
|
|
|
|
Yeah, most so calld horrors are just verbose code that wouldn't even get optimized for speed by writing it in less lines.
I mean it's fine to write in fewer ines but this isn't actually wrong...
|
|
|
|
|
don't waste unnecessary assignment cycles, especially when you get payed by the line:
if (x == 0)
{
if (y != 0)
{
y = 0;
}
}
else
{
if (y != x)
{
y = x;
}
}
|
|
|
|
|
There are some seriously twisted people on here.
Larry Miller
|
|
|
|
|
If x and y are simple variables of matching type, the code is pretty nonsensical. There are some situations, however, where such code could save a tiny bit of time, and others where its behavior could be slightly different from 'y=x'.
For example of the former situation, suppose that 'x' is an integer and 'y' is a double, and 99.9% of the time 'x' will equal zero. If one were to code 'y=x' the computer would always perform a library call to do the integer-to-double promotion. Even if the library routine did an early-exit check for a value of zero, calling the library in the first place would still add overhead which the above code would eliminate.
As for the second situation, if 'x' and 'y' are of a numeric type where two variables may both test equal to zero and yet not have identical representations (true of some floating-point implementations), code like the above may be useful to ensure that only one form of zero is used. For example, consider the following, on an implementation that features positive and negative zero, and positive and negative infinity:
{
double x1,x2,z1,z2;
x1= 1e-30/1e30;
x2=-1e-30/1e30;
z1=1/x1;
z2=1/x2;
}
Note that x1==0 and x2==0, but (1/x1)!=(1/x2). Forcing x1 and x2 to the same zero would ensure that (1/x1)==(1/x2).
|
|
|
|
|
I always do ...
switch (x)
{
case 0 : y = 0; break;
case 1 : y = 1; break;
case 2 : y = 2; break;
...
...
}
... for Int32
|
|
|
|
|
u r jerk
Ravie Busie
Coding is my birth-right and bugs are part of feature my code has!
|
|
|
|
|
Rauhotz wrote: I always do ...
switch (x)
{
case 0 : y = 0; break;
case 1 : y = 1; break;
case 2 : y = 2; break;
...
...
}
At last you forgot to write default case.
default: y = x;
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
I found this in JS:
function toggleDiv(divName)
{
$(divName).toggle();
}
So using the shortcut: toggleDiv('foo'); , we would end up with 17 characters.
Using the unusual long version: $('foo').toggle(); , we would end up with 18 characters.
|
|
|
|
|
perhaps the coder has a non-functioning $ key? :P
|
|
|
|
|
That's very considerate of you!
|
|
|
|
|
It's sad, but I've seen those kind of things so many times I hardly consider them horrible anymore.
|
|
|
|
|
Does user hate to see so many '$' on the screen ?
|
|
|
|
|
Unfortunately you have to use the function nearly 50 times before it actually saves any keystrokes...
|
|
|
|
|
Was this a remnant of moving from the standard 'getElementById' to using a library such as jQuery that provides the '$' shortcut?
Maybe it's not terrible after all. Maybe doing it this way
a) saved many, many characters in the initial form
b) allowed a very quick and safe way of transitioning to the new syntax
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Could be, only the project is very new (1 month old) and this function is used on 1 page only (so it was not much work to do a Search & Replace on 1 page).
|
|
|
|
|
appreciate ur guts to write these lines of code
Ravie Busie
Coding is my birth-right and bugs are part of feature my code has!
|
|
|
|
|
...so he would have to use the function at least 60 times just to make up for the fixed cost of the function definition...
|
|
|
|
|
Shortly before my co-worker left for vacation today, he wrote something like this:
strNew.Replace("%20", " ");
strNew.Replace("%21", "!");
strNew.Replace("%22", """);
strNew.Replace("%23", "#");
strNew.Replace("%24", "$");
strNew.Replace("%25", "%");
strNew.Replace("%26", "&");
strNew.Replace("%27", "'");
strNew.Replace("%28", "(");
strNew.Replace("%29", ")");
strNew.Replace("%2A", "*");
strNew.Replace("%2B", "+");
strNew.Replace("%2C", ",");
strNew.Replace("%2D", "-");
strNew.Replace("%2E", ".");
strNew.Replace("%2F", "/");
strNew.Replace("%2a", "*");
strNew.Replace("%2b", "+");
strNew.Replace("%2c", ",");
strNew.Replace("%2d", "-");
strNew.Replace("%2e", ".");
strNew.Replace("%2f", "/");
strNew.Replace("%3A", ":");
strNew.Replace("%3B", ";");
strNew.Replace("%3C", "<");
strNew.Replace("%3D", "=");
strNew.Replace("%3E", ">");
strNew.Replace("%3F", "?");
strNew.Replace("%3a", ":");
strNew.Replace("%3b", ";");
strNew.Replace("%3c", "<");
strNew.Replace("%3d", "=");
strNew.Replace("%3e", ">");
strNew.Replace("%3f", "?");
strNew.Replace("%40", "@");
strNew.Replace("%5B", "[");
strNew.Replace("%5C", "\\");
strNew.Replace("%5D", "]");
strNew.Replace("%5E", "^");
strNew.Replace("%5F", "_");
strNew.Replace("%5b", "[");
strNew.Replace("%5c", "\\");
strNew.Replace("%5d", "]");
strNew.Replace("%5e", "^");
strNew.Replace("%5f", "_");
strNew.Replace("%60", "`");
strNew.Replace("%7B", "{");
strNew.Replace("%7C", "|");
strNew.Replace("%7D", "}");
strNew.Replace("%7E", "~");
strNew.Replace("%7b", "{");
strNew.Replace("%7c", "|");
strNew.Replace("%7d", "}");
strNew.Replace("%7e", "~");
|
|
|
|
|
|
At first I thought he was smart to use Excel to generate code using ="strNew.Replace(""%" & DEC2HEX(A1) & """, """ & CHAR(A1) & """);" to save typing of boring code that anybody can type.
But then I noticed case sensitive replacements that as possible to generate using following VB.NET code:
For i As Integer = 32 To 126
Dim ch As Char = Chr(i)
If Not Char.IsLetterOrDigit(ch) Then
Console.WriteLine("strNew.Replace(""%{0:X2}"", ""{1}"");", i, ch)
If i Mod 16 > 9 Then
Console.WriteLine("strNew.Replace(""%{0:x2}"", ""{1}"");", i, ch)
End If
End If
Next i
It's still less typing than traditional way to do stuff. Genius!
|
|
|
|
|
Your coworker is a genius.
strNew.Replace("%7E", "~");
...
strNew.Replace("%7e", "~");
This one adds another wtf to the thing. You should probably send to to the dailywtf.com.
|
|
|
|
|
Apart from the fact that it's a horror code, it will just won't work as he needs to assign value returned by Replace to strnew
strNew = strNew.Replace("%20", " ");
|
|
|
|
|