Comment On A Function to Quit For

It's easy to understand how Mike Hartnagel got himself into the classic "should I quit after three days?" dilemma. Who would have guessed that a single bullet point on the job description -- "utilizing some Excel Interoperability" -- actually described the architecture of the system: a horrid amalgamation of Excel spreadsheets interacting with C# interacting with other spreadsheets. Who would have thought that all other bullet points -- from "multi-tiered architecture using remoting" to "automated/integrated build process" -- were actually features they'd like to have at some point in the distant future. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: A Function to Quit For

2006-07-17 13:32 • by lkt
...wow.

Re: A Function to Quit For

2006-07-17 13:32 • by TGnat
NFW?

Re: A Function to Quit For

2006-07-17 13:32 • by Stas
81933 in reply to 81931
That's weird - it's all I could say too: "Wow..."

Re: A Function to Quit For

2006-07-17 13:32 • by JBL
Wow.



Who typed it all in the first time? The next patient over in the Carpal Tunnel Ward?

Re: A Function to Quit For

2006-07-17 13:33 • by Jonathan Allen

Easy, just rewrite it in VB with optional parameters.


Then start the long hard road to building it right.


Jonathan

Re: A Function to Quit For

2006-07-17 13:34 • by Jonathan Allen
81936 in reply to 81935
Or I guess you could just use param arrays.

Re: A Function to Quit For

2006-07-17 13:36 • by The Jailor
FIST!

Ooooh my good, that's just so exceptionally horrendous I can't feel the need to run manically around on the street screaming! Didn't they hear of the "params" keyword? And what even made them *think* of such a function in the first place?!?

Re: A Function to Quit For

2006-07-17 13:36 • by mol
Alex Papadimoulis:
/* adds up all the column values for a specific row from an excel file.

* 20050823 - BSR - v1.0 - Adds only columns a to z.
* 20050909 - BSR - v2.0 - Added support for adding columns aa to zz.


* 20060718 - Mike - v3.0 - Added support for adding columns aaa to zzz.
*/

Re: A Function to Quit For

2006-07-17 13:37 • by JBL
81940 in reply to 81935
Anonymous:

Easy, just rewrite it in VB with optional parameters.


Then start the long hard road to building it right.


Jonathan

How about a Perl script to generate all 600+ variants? Think of the productivity! ("I wrote over 15000 lines of code in one day!")

Re: A Function to Quit For

2006-07-17 13:39 • by W
I can only see one possible solution:

Step one: rm -fr /
Step two: "Hey, boss... I quit"

Re: A Function to Quit For

2006-07-17 13:39 • by Jeremy Morton
"The goggles..."

Re: A Function to Quit For

2006-07-17 13:39 • by yet another Alex
81943 in reply to 81939
Fortunately there are no triple-letter columns in Excel (at least for now). This puts a natural limit of sorts on this.

Re: A Function to Quit For

2006-07-17 13:39 • by JBL
81944 in reply to 81938
Anonymous:
FIST!

Ooooh my good, that's just so exceptionally horrendous I can't feel the need to run manically around on the street screaming! Didn't they hear of the "params" keyword? And what even made them *think* of such a function in the first place?!?
This sort of says "intern" to me. (And yes, there are good ones too.)

Re: A Function to Quit For

2006-07-17 13:40 • by Matt

This is completely insane!  I would say that I would have to take over design, or quit.

Re: A Function to Quit For

2006-07-17 13:40 • by Tim
81946 in reply to 81936
The "right" way to do it (in C, C++, or Objective C) would be make it variadic. For ten lines you could fix everything.

Re: A Function to Quit For

2006-07-17 13:40 • by Jeff S
A classic.  Wow.  speechless.  A WTF on so many levels. 

What is really funny is that in order to call this function, someone must have learned how to use the Excel object model to get the values from the worksheet .... but aparently they learned only the absolute minimum to get the job done  (probably the Worksheet.Cells(x,y) method which can return a single-cell Range from a row/column).  

Re: A Function to Quit For

2006-07-17 13:41 • by apparition
81948 in reply to 81942

Aaaaaaiiiiiiiiiiiiiiiiiiiiiiiieeeeeeeeeeeeeeeeeeeeeeeeegggggggggggggggghhhhhhhhhhhhhhhhh !


Wait for it - add additional overloads to add all permutations of cells for all permutations of multiple rows

Re: A Function to Quit For

2006-07-17 13:42 • by Jeff S
81950 in reply to 81946
Anonymous:
The "right" way to do it (in C, C++, or Objective C) would be make it variadic. For ten lines you could fix everything.


I sure hope that's a joke ... the "right" way to do it (in *any* language that supports COM) is to pass in a single Range object and to enumerate the Cells and add them up ... or a worksheet object and a row # ...   Or, just use a simple Excel function to do the math !!   I hear that the latest versions of Excel support formulas!

Re: A Function to Quit For

2006-07-17 13:43 • by iii
seems like it'd be a trivial matter to write a perl script to generate all the functions you need.

i'd do that, and *then* quit.

Re: A Function to Quit For

2006-07-17 13:44 • by neven
So, what's everybody's favorite part of this? Mine is,

/* adds up all the column values for a specific row from an excel file.

No. No it does not. It adds up 600+ integers typed in by another hamsterwheel employee. It does nothing with any Excel file.

Re: A Function to Quit For

2006-07-17 13:45 • by Eric Wise
They appear to just be storing column values as ints.  Why not just chop this bad boy down and use a hashtable?  Iterate it in the method and handle things accordingly.  It's still one ugly mofo, but that would be a step in the right direction.

Re: A Function to Quit For

2006-07-17 13:47 • by Jeff S
81956 in reply to 81955
Anonymous:
They appear to just be storing column values as ints.  Why not just chop this bad boy down and use a hashtable?  Iterate it in the method and handle things accordingly.  It's still one ugly mofo, but that would be a step in the right direction.


Or, just use the Excel object model ????  Or would that be too easy?

Re: A Function to Quit For

2006-07-17 13:52 • by Benanov
I personally love the reserved word escaping:

_as
_do
_is

Thankfully pi isn't one--it's System.Math.PI

And params arrays are probably the best bet for fixing the original problem, but that's just a stopgap.  I can't really think of a better way because I haven't done Excel Interop (and now I just jinxed myself, sigh)

Re: A Function to Quit For

2006-07-17 13:55 • by Dave Markle
This code is NSFW.

Re: A Function to Quit For

2006-07-17 13:57 • by SadBugKiller
3"Hm, I wonder what is that 'array' thing I keep hearing about..."

By the way, I think this is the first time when the cries about something (this thing doesn't even deserve to be called 'code') being generated might be true 3

Re: A Function to Quit For

2006-07-17 13:57 • by Dave
create overloads for the following function so that developers don't
need use zeros if they don't need all of the 600+ parameters ..

I can see intellisense just crapping itself over this one.

Re: A Function to Quit For

2006-07-17 13:58 • by Volmarias
81964 in reply to 81961
When I saw this, my response was, literally,

D:


hint: (tilt your head 90 degrees clockwise)

Re: A Function to Quit For

2006-07-17 13:59 • by Debbus

Alex Papadimoulis:


/* adds up all the column values for a specific row from an excel file.


I totally agree with this. You can't trust Excel to calculate the numbers of a single row... What does Excel even know about math! Better to do it yourself...

Re: A Function to Quit For

2006-07-17 14:00 • by Pyromancer
81966 in reply to 81955

Anonymous:
They appear to just be storing column values as ints.  Why not just chop this bad boy down and use a hashtable?  Iterate it in the method and handle things accordingly.  It's still one ugly mofo, but that would be a step in the right direction.


I'd say from my experience that in C# you can get a DataTable from excel file in umm 3 lines and then add it up in 2 more lines :) Thus cutting over 100 lines of this craptastic solution to mere 5 lines :)

Re: A Function to Quit For

2006-07-17 14:01 • by Jeff S
81967 in reply to 81966
Anonymous:

Anonymous:
They appear to just be storing column values as ints.  Why not just chop this bad boy down and use a hashtable?  Iterate it in the method and handle things accordingly.  It's still one ugly mofo, but that would be a step in the right direction.


I'd say from my experience that in C# you can get a DataTable from excel file in umm 3 lines and then add it up in 2 more lines :) Thus cutting over 100 lines of this craptastic solution to mere 5 lines :)



And thus, you have created your own WTF.  Congratulations!

MOAWTFs!

2006-07-17 14:01 • by BAReFOOt
Oh my... GOD... it's BURNING... ...my... my EYES... *STUMBLE* ... it's SO... oh MY... AAAAHHHGGGHHH... i can't... no... this is... this is not... real... no... NO... NOOO..*VOMIT*ON*FLOOR* ... *heavy*breathing* *CRY*

Re: A Function to Quit For

2006-07-17 14:01 • by radiantmatrix

/* adds up all the column values for a specific row from an excel file.


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.

Re: A Function to Quit For

2006-07-17 14:02 • by MaGnA
int _as
int _do

At least he has avoided keyword ambiguity!

Re: A Function to Quit For

2006-07-17 14:03 • by zip
I've been reading this site for over a year now and that might be the most appalling wtf I have seen.

Re: A Function to Quit For

2006-07-17 14:04 • by Doug
Alex Papadimoulis:

...create overloads for the following function so that developers don't need use zeros if they don't need all of the 600+ parameters ...




I thought Excel was restricted to 256 columns (IV, or 2^8) and 65536 rows (or 2^16) per workbook.  I'm not sure what the workbook limitation is.

At least that's the way it is in Excel 2002, from what I can tell.

Would that be the real WTF, perchance?


doug.

CAPTCHA == 'hacker'
# Sweet!

Re: A Function to Quit For

2006-07-17 14:04 • by Scott B.
Alex Papadimoulis:
/* adds up all the column values for a specific row from an excel file.

* 20050823 - BSR - v1.0 - Adds only columns a to z.
* 20050909 - BSR - v2.0 - Added support for adding columns aa to zz.


* 20060710 - BSR - v*.0 - So tierd of copy-paste-edit for the parameters that I'm not going to update the comment any more.

Re: A Function to Quit For

2006-07-17 14:05 • by Jozef Izso
81974 in reply to 81960
Benanov:
I personally love the reserved word escaping:

_as
_do
_is

Thankfully pi isn't one--it's System.Math.PI

And params arrays are probably the best bet for fixing the original problem, but that's just a stopgap.  I can't really think of a better way because I haven't done Excel Interop (and now I just jinxed myself, sigh)


I've wondered: The real WTF is: Why they have _as. ?
Now I'm wondering: Why they don't used variable name @as. ?

Re: A Function to Quit For

2006-07-17 14:08 • by Stumo
Unless I'm very much mistaken, Excel has a SUM(...) function - surely anyone who could write this would know that...

Re: A Function to Quit For

2006-07-17 14:09 • by aaron
81976 in reply to 81969
The substitue nulls thing would work, assuming there were no non-null cells they wanted to exclude.

Re: A Function to Quit For

2006-07-17 14:13 • by Einmaliger
Honestly, this is the first WTF that I believe to be fake.

Re: A Function to Quit For

2006-07-17 14:15 • by Phil the ruler of heck
81978 in reply to 81934

JBL:
Who typed it all in the first time? The next patient over in the Carpal Tunnel Ward?


Maybe they were clever enough to make a copy of the "int aa" through "int az" block, then instructing their text editor to replace "int a" with "int b"?  All that computing power sitting on your desk must be good for something, after all...

Re: A Function to Quit For

2006-07-17 14:19 • by badwiring
WorksheetFunction.Sum(Range("A1:Z99"))

Re: A Function to Quit For

2006-07-17 14:22 • by The Jailor
Alex Papadimoulis:



public long addUpAllExcelColumns(
int a, int b, int c, int d, int e, int f, int g, int h, // snip
int zy, int zz)
{
return
a+b+c+d+e+f+g+h // snip
+zy+zz;
}

Okay, I'm not a 100% sure about this (only 99), but isn't there a second WTF here? The method takes around seven hundred 32-bit integers and is supposed to return their sum as 64-bit long, but it actually does 32-bit integer addition all the way, thereby potentially discarding the most significant bits?!?

Re: A Function to Quit For

2006-07-17 14:22 • by Uncoolperson

why not use


excel.worksheetfunction.sum()

Re: A Function to Quit For

2006-07-17 14:25 • by Phil the ruler of heck
81985 in reply to 81966

Pyromancer:
I'd say from my experience that in C# you can get a DataTable from excel file in umm 3 lines and then add it up in 2 more lines :) Thus cutting over 100 lines of this craptastic solution to mere 5 lines :)


So how many lines of code did you write today?  Minus 95?


So is this "a function to quit for," or "a function to get yourself fired for" on account of extremely unsactisfactory output (in terms of lines of code)?

Re: A Function to Quit For

2006-07-17 14:26 • by SantaC311

Amazing people have not discovered the simplicity of arrays as parameters...


public long addUpAllExcelColumns(int[] Columns)
{
   //do whatever
}


-jeff

Re: A Function to Quit For

2006-07-17 14:26 • by nsimeonov
Writing a small program to generate the functions won't be hard ... and in 10 min you're ready with so much source code... it's a whole other thema that the design seems to be f***ed up from the beginning... why should one have a function to sum up integers (really, why only integers?) when it's easier to type "+" instead of calling a function?

Re: A Function to Quit For

2006-07-17 14:27 • by JBL
81988 in reply to 81978
Phil the ruler of heck:

JBL:
Who typed it all in the first time? The next patient over in the Carpal Tunnel Ward?


Maybe they were clever enough to make a copy of the "int aa" through "int az" block, then instructing their text editor to replace "int a" with "int b"?  All that computing power sitting on your desk must be good for something, after all...

Um, yes. That gain in efficiency would be well-suited to the original "programmer."

Re: A Function to Quit For

2006-07-17 14:28 • by JBL
81989 in reply to 81985
Phil the ruler of heck:

Pyromancer:
I'd say from my experience that in C# you can get a DataTable from excel file in umm 3 lines and then add it up in 2 more lines :) Thus cutting over 100 lines of this craptastic solution to mere 5 lines :)


So how many lines of code did you write today?  Minus 95?


So is this "a function to quit for," or "a function to get yourself fired for" on account of extremely unsactisfactory output (in terms of lines of code)?

Better to advertise the increase in performance in such a case.

Re: A Function to Quit For

2006-07-17 14:30 • by mike g
81990 in reply to 81984
c# actually has something called a "params" array..   using it for this would be an abuse of its design (as if the current design isn't already), but it might make maintenance easier

public long addUpAllExcelColumns(params int[] columnVals)
{
//todo: validate

int sum = 0;
foreach (int i in columnVals) {
sum += i;
}
return sum;
}

then you could call it with however many parameters you want (a-z, aa-zz, aaaaa-zzzzz)


« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment