• lkt (unregistered)

    ...wow.

  • TGnat (unregistered)

    NFW?

  • Stas (unregistered) in reply to lkt

    That's weird - it's all I could say too: "Wow..."

  • (cs)

    Wow.

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

  • Jonathan Allen (unregistered)

    Easy, just rewrite it in VB with optional parameters.

    Then start the long hard road to building it right.

    Jonathan

  • Jonathan Allen (unregistered) in reply to Jonathan Allen

    Or I guess you could just use param arrays.

  • The Jailor (unregistered)

    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?!?

  • mol (unregistered)
    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.


    <font color="#008000" face="Courier New" size="2">* 20060718 - Mike - v3.0 - Added support for adding columns aaa to zzz.
    */</font>
  • (cs) in reply to Jonathan Allen
    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!")
  • W (unregistered)

    I can only see one possible solution:

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

  • (cs)

    "The goggles..."

  • yet another Alex (unregistered) in reply to mol

    Fortunately there are no triple-letter columns in Excel (at least for now). This puts a natural limit of sorts on this.

  • (cs) in reply to The Jailor
    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.)
  • Matt (unregistered)

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

  • Tim (unregistered) in reply to Jonathan Allen

    The "right" way to do it (in C, C++, or Objective C) would be make it variadic. For ten lines you could fix everything.

  • (cs)

    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).  

  • (cs) in reply to Jeremy Morton

    Aaaaaaiiiiiiiiiiiiiiiiiiiiiiiieeeeeeeeeeeeeeeeeeeeeeeeegggggggggggggggghhhhhhhhhhhhhhhhh !

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

  • (cs) in reply to Tim
    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!
  • iii (unregistered)

    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.

  • (cs)

    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.

  • Eric Wise (unregistered)

    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.

  • (cs) in reply to Eric Wise
    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?
  • (cs)

    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)

  • Dave Markle (unregistered)

    This code is NSFW.

  • SadBugKiller (unregistered)

    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

  • Dave (unregistered)
    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.
  • (cs) in reply to Dave Markle

    When I saw this, my response was, literally,

    D:

    hint: (tilt your head 90 degrees clockwise)
  • Debbus (unregistered)

    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...

  • Pyromancer (unregistered) in reply to Eric Wise

    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 :)

  • (cs) in reply to Pyromancer
    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!

  • BAReFOOt (unregistered)

    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..VOMITONFLOOR ... heavybreathing* CRY

  • radiantmatrix (unregistered)

    <font face="Courier New" size="2">/* adds up all the column values for a specific row from an excel file.</font>


    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.
  • (cs)

    int _as
    int _do

    At least he has avoided keyword ambiguity!

  • zip (unregistered)

    I've been reading this site for over a year now and that might be the most appalling wtf I have seen.

  • Doug (unregistered)
    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!
  • Scott B. (unregistered)
    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.
  • Stumo (unregistered)

    Unless I'm very much mistaken, Excel has a SUM(...) function - surely anyone who could write this would know that...

  • aaron (unregistered) in reply to radiantmatrix

    The substitue nulls thing would work, assuming there were no non-null cells they wanted to exclude.

  • Einmaliger (unregistered)

    Honestly, this is the first WTF that I believe to be fake.

  • (cs) in reply to JBL

    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...

  • badwiring (unregistered)

    <FONT face="Courier New">WorksheetFunction.Sum(Range("A1:Z99"))</FONT>

  • The Jailor (unregistered)
    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?!?
  • (cs)

    why not use

    excel.worksheetfunction.sum()

  • (cs) in reply to Pyromancer

    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)?

  • SantaC311 (unregistered)

    <FONT face=Arial size=2>Amazing people have not discovered the simplicity of arrays as parameters...</FONT>

    <FONT face="Courier New"><FONT color=#008000><FONT size=2>public long addUpAllExcelColumns(int[] Columns)
    {
       //do whatever
    }</FONT></FONT></FONT>

    <FONT face=Arial size=2>-jeff</FONT>

  • (cs)

    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?

  • (cs) in reply to Phil the ruler of heck
    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."
  • (cs) in reply to Phil the ruler of heck
    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.
  • mike g (unregistered) in reply to Uncoolperson

    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)


  • Anonymous (unregistered)

    This function is so stupid that it surprisingly allows a magical solution!

    Create another function with just one parameter and tell the other programmers to use the symbol "+" instead of "," as parameter separator... and return the valued passed in.

    Done! Your bosses will be amazed!

Leave a comment on “A Function to Quit For ”

Log In or post as a guest

Replying to comment #81933:

« Return to Article