- 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
You need to step back further ... the issue is not that a function was written to sum integers ... it is that someone is writing code to convert all of these excel values to integers, one by one, so that they can call this function!
using code generation to create overloads and/or using an array as a parameter does *not* solve the issue here. replacing the function call with a huge expression using + with 256 numbers is not the solution and it is no better!
It is amazing how many people are not getting this ....
Admin
Of course, he could have used
[code]
public long AddUpColumns(int col[])
{
long sum;
sum=0;
for (int x=0; x < len(col); x++) sum=sum+col[x];
return sum;
}
[code]
but that would mean he would be writing less lines of code, and was thus less productive.
//captcha == 1337
//5w337
Admin
Lol. I love the comments. Those are definitely the icing. I am left wondering though, why do some of the parameters have a _ prefixing them? Also, couldn't this have been replaced with a simple function in C#?
public long AddUpAllValues(int[] values)
{
long ret = 0;
foreach (int val in values)
ret += val;
return ret;
}
Definitely one of the dumber things I've ever seen done. It makes me wonder what kind of thought process determined that the best solution to add a bunch of integers together is to create a function with as many parameters as the maximum amount of integers to be added. Stupidity at it's finest.
Admin
That's not quite what they want, though. This, however...
<font face="Courier New">WorksheetFunction.Sum(Range("1:1"))
</font>That would add up everything in row 1. This is easy to extrapolate to:
Admin
usually a lot of these dont make my eyes bleed bc i am not that clever enough to know what is going on but this is the exception, i got an appointment with my eye doctor later this afternoon!
Admin
.. and then returns the result as a long! Double arrgh!
Admin
bad news - Excel 12 has a 1M rows x 16K columns grid, requiring 3-letter column names :)
*crack fingers, start typing...*
btw, for those of you who never did this - typing? write a 2-line base26 converter and use it to generate the list :)
but can a function even TAKE 600+ parameters? seems fake, after all...
Admin
Apparently the entire company never heard of sum().
A function for every number of parameters would be about 2.8mb of text.
Admin
I think everyone realizes it. It was a black humor on my side to "shine" by writing a code generator (and hide it from the boss) so you can do a 3-day work in 10 minutes :)
I believe the original programmer was one of those kids, who put a square block into a round hole using a big hammer. I had a couple of guys like this working for me and I was always amazed how they never stop for a moment to think if there's something really wrong in the approach, but instead they keep working and working until something terrible like this comes to me (proudly presenting their work finally done). Tell me what's the best approach to explain how wrong this is. I usually try a couple of times politely but after explaining about similar repetetive code over 3 times I can't hold myself and there was a lady that pissed me so bad that I yelled at her for about 30 minutes... wrong but... oh well...
Admin
I think its supposed to be
</FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>long</FONT><FONT size=2> addUpAllExcelColumns(</FONT><FONT color=#0000ff size=2>params</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2>[] Arguments)
{
</FONT><FONT color=#0000ff size=2>long</FONT><FONT size=2> Result = 0;
</FONT><FONT color=#0000ff size=2>foreach</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> I </FONT><FONT color=#0000ff size=2>in</FONT><FONT size=2> Arguments)
{
Result += I;
}
</FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> (Result);
}
</FONT>Admin
Is that patented?
Admin
Obviously, this person was paid by the variable declared. In that case, brillant!
Admin
I am pretty sure the guy who "invented" this WTF never used a decent text editor supporting macros, and typed every character of this function with his fingers...
--
rien
Admin
This one has got to be fake. Nobody would be that stupid. In fact, this is so stupid, that they probably typed this mess out by hand instead of writing the 10 or so lines of code it would take to do it for them.
Admin
You're joking with the SELECT CASE, right ?? just making sure ....
Admin
I don't know about the rest of you, but today I shed a small tear for the poor poor stack on that application.
Admin
Actually that function was removed in the latest version - something about users wanting to substitute VB code instead. :-)
I am still wondering *why* anyone would make a totally useless function like this. Excel has formulas to sum numbers, and it is *really* easy to create a function to add all the values in VB for a row.
Admin
The Jailor:
0xffffffff + 0xffffffff (2* the largest unsigned 32-bit integer value) is a 33-bit integer. If you do that 702 times (for a-z, aa-zz), you get a 42-bit integer, which is still a long way below the 64 bit boundary.
Admin
No reason you should delete the existing code. Just add your code and return before the craptasticness hits. :)
Admin
I think he was trying to point out that the fact that the integers weren't cast to long values limited the ability for the long return value to ever exceed 32 bits. IITIKWGO, then each integer would need it's own cast in the return statement. Otherwise, when the + operator is called, and both ints are 0xffffffff, the resulting addition is 0xffffffff (assuming all of this was unsigned, which it wasn't i know, just using it for simplicity's sake (although I think it would be the same if signed.... not sure... don't know how the sign is treated in .net (and even then, I haven't though about it enough to really give a definitive answer))). When you think about it deeper, each int (even though it's a value type) is an object. the object has the + operator overloaded. The + operator being used here is the one that takes a 32bit integer, and returns a 32bit integer. So, it only makes sense that it would be limited to 32bit unless all the integers were cast first. In my code-paste, I used a long return type. This would allow for the full value.
IITIKWGO == If I think I know what's going on...
Admin
This is the first WTF that actually made me say "Oh... my.... God..." out loud.
I think this is fake. Or at least, I really, really, really hope it's fake. If it's real....
My eyes, the goggles, you know...
Admin
"Um. Wow. Dear gods, why would anyone write a function to do this that requires each value to be a parameter? Can't they just pass the row they want and iterate through, accumulating the total, and substituting a zero when there's a null/empty-string value?
Whoever thought this was the right approach should be drawn and quartered."
Even simpler: in excel, instead of calling to the C# function, how about "=SUM(A1:ZZ:1)"
Admin
Admin
The comments here really make this one for me.
Everyone is showing off their black belt coding skills by showing how they can sum an int array and think this is the fix to this wtf!
classic :-)
Admin
Wow. I will be dipped in dung.
Normally, writing and using library functions is supposed to REDUCE the amount of code you have to write.
But look on the bright side; the cute foosball chick has regained top sponsor position.
Admin
I can't imagine what the code calling this monstrosity would look like
Admin
Yes, but the thing is that it uses 32-bit addition, potentially truncating the result or something similarly nasty for all all 701 additions (because they are all 32-bit integer additions, and adding two 32-bit integers still only gives a 32-bit integer result). Then, only at the very end, it expands the truncated 32-bit value by adding 32 zero bits in order to return a long.
Admin
<FONT face=Arial>There is quite definitely SUM THING wrong with this!</FONT>
<FONT face=Arial></FONT>
<FONT face=Arial><FONT size=2>I had to be the first to get in the pun</FONT> :-)</FONT>
Admin
The post did say it was Mike's first assignment... it may of course have been a delibrate 'wtf' assignment just to check his initiative... I.e. if he blindly did the assignment without question then perhaps he isn't quite the developer they are looking for. However, if he did suggest a better solution, then instant payrise and promotion from Trainee to Junior programmer!
Admin
Plus it makes us white belt coders feel bad...wtf is an int array?
Admin
<font size="5">'E</font>re now, 'angin' too good for 'em.
Admin
Indeed, + takes more than twice the ink of ,. Printing out the code wastes more precious resources, making the Earth weep with how callously we treat it.
Admin
The real increase is in developer performance. All that pounding-of-head-against-desk activity can't be helping things, no matter how good it feels when you realize you can't read that ghodawful code any more!
(captcha: "enterprisey"? Designed to screen out people who can *spell*?)
Admin
The real wtf is that C-derived languages do arithmetic as narrow integers at all.
Admin
You are talking about the automatic build system, right?
Admin
Exactly ...
A disturbing number of posts here are people trying to figure out how to deal with the side effects of the horrible code, and as opposed to simply fixing the horrible code itself.
That is a true WTF in its own right, and it is how many of these WTF's are created!
Admin
How about the ink for the function name & the brackets?
Admin
I'm hoping the next WTF will be the addUpAllExcelRows() function from the same project ;)
Admin
That little statement is more insightful than all the comments on all the WTFs of the past week.
If only people who fancy their library functions "helpful" would give that more thought. Libraries should make things easier, not harder, for other developers. Or, worded another way: just because a function took someone a lot of effort to write doesn't automatically make it helpful.
Admin
Maybe some day mathematicians find out that "addUp" has a comletely different meaning. How fix your code if you have all the +-singns spreaded across the application?
Admin
I'd rather it be pullDataFromExcelSpreadsheet(). It's my guess that either that function uses 700+ ref variables, or assigns to 700+ member variables. gawd... I can see it now lol...
public class ExcelData
{
public int m_a;
public int m_b;
public int m_c;
//... and so on for 700 more lines lol
public int m_zzz;
};
Admin
To sum it up?
WTF #1: Integer overflow.
WTF #2: Stack issues.
WTF #3: Naming the function, comments, and parameters after what we claim the use is, but absolutely no dependencies on the Excel namespace (people keep quoting Excel.WorksheetFunction.Sum() here)
WTF #4: You didn't think of your downstream (something my upstream does daily!) oh yes, because sum(2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...,0,0,0) is just the best method call ever.
Your BOFH called, Visual Source Strafe server is out of disk space, and guess whose fault it is....
WTF #5: Thinking that an underscore before C# reserved words such as AS, IN, IS, DO is a good idea and isn't confusing at all because the IDE recognizes that it's not the same! The letters are black instead of blue!
WTF #6: The fact that you need 702 explicit, required parameters to any function.
If you don't want to break anyone's code, just use a params int[] method call; that's the quick/dirty method...
Really, it looks like a fun bit of rip and replace.
Admin
Uuuuh, I know a lot of C&P-Programmers who do a lot of extra-hours to get things like this done.
Admin
I aint no Excel junkie, and thought of the "sum()" thing too. In our shining wtf, we have a clue what happens when some user puts a datae or string into a cell -- the whole thing blows up. What happens in Excel (isung a sum()) when someone drops in anything at all other than an int?
--
RJ
Admin
The thing I like the most about this, is then we would get to hear about this WTF again ... when some other poor developer gets hired on, and finds himself crying in the corner.
Admin
Oh - I know what will make this better:
The true WTF is that if you don't trust excel to do the sum for you, why should you trust the compiler?
Admin
I gotta say thanks :)
Got to work this morning dreading workign on a painful project with developers who don't think past morning tea time, read this, wet myself laughing and realised that I have it better than most.
Brilliant WTF - made my day
Admin
I suppose it's understandable that many comments here (excepting the one I'm quoting) miss the biggest WTF completely. It's just too big to grasp at first.
To restate: there is simply no need whatever for this function, nor would there ever have been. It doesn't access Excel, handle overflow, or do anything except add, and much less efficiently than '+'.
So commenters can be forgiven for missing this after 10 minutes. But what about Mike's (ertswhile) co-workers: "...create overloads for the following function so that developers don't need use zeros if they don't need all of the 600+ parameters".
No. They're not "developers" if they're using this function.
Admin
It's so beautiful! I'm crying! No wait, that's blood.
Admin