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


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

  • Noam Samuel (unregistered)

    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

  • (cs)

    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.

  • (cs) in reply to badwiring
    Anonymous:
    <font face="Courier New">WorksheetFunction.Sum(Range("A1:Z99"))</font>


    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:
    /* 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.
    * 20060717 - DPL - v3.0 - Enhanced with Excel Object Model.
    */

    public long addUpAllExcelColumns(int row)
    {
    Select Case row
    Case 1
    return <font face="Courier New">WorksheetFunction.Sum(Range("1:1"));
    Case 2
    return </font><font face="Courier New">WorksheetFunction.Sum(Range("2:2"));
    Case 3
    </font><font face="Courier New"> return </font><font face="Courier New">WorksheetFunction.Sum(Range("3:3"));

    /* Snip 131068 lines.</font> */

    Case 65535
    <font face="Courier New"> return </font><font face="Courier New">WorksheetFunction.Sum(Range("65535:65535"));</font> Case 65536
    <font face="Courier New"> return </font><font face="Courier New">WorksheetFunction.Sum(Range("65536:65536"));
    Else Case
    return 'brillant'
    End Select</font>
    }
  • Steve (unregistered)

    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!

  • The Jailor (unregistered)

    .. and then returns the result as a long! Double arrgh!

  • Mars the Infomage (unregistered) in reply to yet another Alex
    Anonymous:
    Fortunately there are no triple-letter columns in Excel (at least for now). This puts a natural limit of sorts on this.


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

    Apparently the entire company never heard of sum().

    A function for every number of parameters would be about 2.8mb of text.

  • (cs) in reply to Jeff S

    Jeff S:
    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?


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

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

  • (cs) in reply to Noam Samuel

    I think its supposed to be

     

    <FONT size=2>

    </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>
  • Daruku (unregistered)

    Is that patented?

  • Dale Williams (unregistered)

    Obviously, this person was paid by the variable declared.  In that case, brillant!

  • rien (unregistered)

    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

  • (cs)

    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.

  • (cs) in reply to Kemayo
    Kemayo:
    Anonymous:
    <font face="Courier New">WorksheetFunction.Sum(Range("A1:Z99"))</font>


    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:
    /* 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.
    * 20060717 - DPL - v3.0 - Enhanced with Excel Object Model.
    */

    public long addUpAllExcelColumns(int row)
    {
    Select Case row
    Case 1
    return <font face="Courier New">WorksheetFunction.Sum(Range("1:1"));
    Case 2
    return </font><font face="Courier New">WorksheetFunction.Sum(Range("2:2"));
    Case 3
    </font><font face="Courier New"> return </font><font face="Courier New">WorksheetFunction.Sum(Range("3:3"));

    /* Snip 131068 lines.</font> */

    Case 65535
    <font face="Courier New"> return </font><font face="Courier New">WorksheetFunction.Sum(Range("65535:65535"));</font> Case 65536
    <font face="Courier New"> return </font><font face="Courier New">WorksheetFunction.Sum(Range("65536:65536"));
    Else Case
    return 'brillant'
    End Select</font>
    }


    You're joking with the SELECT CASE, right ??  just making sure ....
  • th0mas (unregistered) in reply to Jeff S

    I don't know about the rest of you, but today I shed a small tear for the poor poor stack on that application.

  • NateB2 (unregistered) in reply to Stumo

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

    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.

  • A. F. (unregistered) in reply to The Jailor

    The Jailor:

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

    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.

  • (cs) in reply to JBL
    JBL:
    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.

    No reason you should delete the existing code.  Just add your code and return before the craptasticness hits. :)

  • (cs) in reply to A. F.
    Anonymous:
    The Jailor:
    "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?!?"

    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.


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

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

  • Mike Montana (unregistered) in reply to radiantmatrix

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

  • John (unregistered)
    That's just NOT right.
     
    I don't care what you say, how you say it...that is not right.
  • mat (unregistered) in reply to Boostaholic

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

  • (cs)

    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.

  • (cs) in reply to JBL

    I can't imagine what the code calling this monstrosity would look like

  • The Jailor (unregistered) in reply to A. F.

    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.

  • (cs)

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

  • (cs)

    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!

  • (cs) in reply to mat
    Anonymous:
    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 :-)

    Plus it makes us white belt coders feel bad...wtf is an int array?

  • (cs) in reply to radiantmatrix
    Anonymous:

    <font face="Courier New" size="2"></font>Whoever thought this was the right approach should be drawn and quartered.

    <font size="5">'E</font>re now, 'angin' too good for 'em.

  • (cs) in reply to Jeff S
    Jeff S:
    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?


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

    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.

  • jefffurry (unregistered) in reply to JBL
    JBL:
    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.


    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*?)
  • mikeyd (unregistered) in reply to The Jailor

    The real wtf is that C-derived languages do arithmetic as narrow integers at all.

  • My Name (unregistered) in reply to iii
    Anonymous:
    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.



    You are talking about the automatic build system, right?

  • (cs) in reply to mat
    Anonymous:
    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 :-)



    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!


  • Astaedus (unregistered) in reply to Jojosh_the_Pi
    Jojosh_the_Pi:
    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.

    How about the ink for the function name & the brackets?
  • Mike (unregistered)

    I'm hoping the next WTF will be the addUpAllExcelRows() function from the same project ;)

  • (cs) in reply to John Bigboote
    John Bigboote:

    Normally, writing and using library functions is supposed to REDUCE the amount of code you have to write.

    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.
  • My Name (unregistered) in reply to nsimeonov
    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?


    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?
  • (cs) in reply to Mike
    Anonymous:
    I'm hoping the next WTF will be the addUpAllExcelRows() function from the same project ;)


    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;
    };

  • (cs)

    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.

  • My Name (unregistered) in reply to SpasticWeasel
    SpasticWeasel:
    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.


    Uuuuh, I know a lot of C&P-Programmers who do a lot of extra-hours to get things like this done.
  • Richard Johnson (unregistered) in reply to ParkinT

    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

  • Anonymous (unregistered) in reply to iii
    Anonymous:
    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.



    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.

  • thedude (unregistered)

    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?

    public long addUpAllExcelColumns(
    int a, int b, int c, int d, int e, int f, int g, int h,
    int i, int j, int k, int l, int m, int n, int o, int p,
    /* snip /

    case when a = 1 and b = 0 and c = 0 /
    snip /
    return 1
    when a = 1 and b = 1 and c = 0 /snip/
    return 2
    /
    snip */

    end case
     

  • Happy as Larry (unregistered)

    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

  • lw (unregistered) in reply to Anonymous
    Anonymous:
    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!



    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.

  • Foo (unregistered)

    It's so beautiful! I'm crying! No wait, that's blood.

  • (cs)
    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.
     */
    public long addUpAllExcelColumns(
      int a,  int b,  int c,  int d,  int e,  int f,  int g,  int h,
    Anytime you may have the need to write code to write your code, you must be doing something wrong!
     

Leave a comment on “A Function to Quit For ”

Log In or post as a guest

Replying to comment #:

« Return to Article