• (cs) in reply to Kemayo
    Kemayo:


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

    There's no row 65536 in Excel .. it stops at 65535 (2^16-1)

  • anon (unregistered)

    yes there is, Excel is 1-based

  • anon (unregistered) in reply to anon

    And you can pass an int representing the row number to get the range referring to the row, e.g.

    Worksheet.Rows(1),

    Worksheet.Rows(1234)

  • The Jailor (unregistered) in reply to lw

    lw:

    I suppose it's understandable that many comments here (excepting the one I'm quoting) miss the biggest WTF completely... there is simply no need whatever for this function

    I think most people here get it, but we're just trying to squeeze as much fun from that function as possible :)
    lw:

    They're not "developers" if they're using this function.

    Wouldn't it just be hilarious if the company coding standard mandated that all summing over Excel rows be performed using this "dedicated" function, haha. That would really make it a function to quit for!

    This editor is way too powerful!

  • (cs) in reply to anon

    Anonymous:
    yes there is, Excel is 1-based

    Holy crapola ... you're right!

    That's the real WTF!  That's makes no sense ... if you loaded rows into an array, you would have to consider that the array is 0 based and the R1C1 is 1 based.

     

  • teambanana (unregistered) in reply to yet another Alex

    XL2003 worksheets can goto 256 columns - that is column IV.

    XL2007 worksheets can goto 65536 columns - that is column XFD!

    Which makes you wonder why they goto column ZZ? 

  • teambanana (unregistered) in reply to Richard Johnson

    The excel sum() ignores non-numric values, although it does propogate error values.

  • (cs) in reply to Richard Johnson
    Anonymous:

    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



    Actually, Excel (at least Excel 11) is smart enough that the SUM() function only sums the numerical data in the range specified as the argument.

    EDIT: Bah! Tears for slow page updates when the post above mine says the same thing! (and by slow, I mean through a proxy that manages to not show me something 13 minutes old!)
  • XMLord (unregistered)

    This is stupid in so many ways.

    Forget about the obvious large number of parameters, which could have been replaced with some kind of array.
    Forget about the fact that the usage of this function is longer than the actual action, so why even call it.
     What I like most is that it's called addUpAllExcelColumns. You know, All as in every single column. All as in there is no need to actually send the columns.

    Any way, this is nothing to quit about. All you need to do is change the function to something human and than make sure everybody understands why you did that.

  • Kehvarl (unregistered) in reply to Jeff S
    Jeff S:
    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 ....


    I certainly hope it's a joke...  it would be so much better written as:
    /* 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.

    * 20060717 - ALC - v4.0 - Removed artifical Row limit of 65536 */
    public long addUpAllExcelColumns(int row)
    {
    return WorksheetFunction.Sum(Range( row & ":" & row));
    }

    //Captcha: Perfection

  • BigFatCowSayingMooo (unregistered) in reply to Kehvarl
    Anonymous:
    Jeff S:
    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 ....


    I certainly hope it's a joke...  it would be so much better written as:
    /* 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.

    * 20060717 - ALC - v4.0 - Removed artifical Row limit of 65536 */
    public long addUpAllExcelColumns(int row)
    {
    return WorksheetFunction.Sum(Range( row & ":" & row));
    }

    //Captcha: Perfection



    Of course it's a joke, 90% of the comments are a joke! your code is shorter, means you are less productive!
  • Asztal (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?

    Well, obviously it's to allow for changes in the future! What if, for example, they wanted to change addUpAllExcelColumns to take the standard deviation of them?

    On the plus side, this amounts to about 59832 lines of code, for all 702 overloads! Productivity at its best!

  • (cs) in reply to XMLord

    Anonymous:

    Any way, this is nothing to quit about. All you need to do is change the function to something human and than make sure everybody understands why you did that.

    I think you might have a hard time convincing those people that your code is better, given the fact that this guy actually got the assignment to overload this function a few hundred times...

  • Maarten (unregistered) in reply to Kehvarl

    In a next release, they could introduce an optimized version of this function that only adds the specified rows from "first" to "last". Utilizing the "for-switch paradigm", this would result in:

    <FONT face="Courier New">public long addUpAllExcelColumns(int first, int last)
    {
    int sum = 0;</FONT>

    <FONT face="Courier New">for (int row = first; row <= last; row++) {

    </FONT>

    <FONT face="Courier New">   Select Case row
        Case 1
       sum += WorksheetFunction.Sum(Range("1:1"));
        Case 2
       sum += WorksheetFunction.Sum(Range("2:2"));
        Case 3
       sum += WorksheetFunction.Sum(Range("3:3"));
     
        /* Snip 131068 lines. */
       
        Case 65535
       sum += WorksheetFunction.Sum(Range("65535:65535"));
        Case 65536
       sum += WorksheetFunction.Sum(Range("65536:65536"));
        Else Case
       sum += 'brillant'
       End Select
    }
    }</FONT>

    <FONT face="Courier New">return sum;

    </FONT>
  • (cs)

    <font face="Arial">Why oh why do so many people insist on using Excel as a data capture device?  Why not just write your own interface code and hook it up to a friggin' database?

    Always bringing a towel when Hitchhicking the Galaxy makes more sense than using Excel for data acquisition.</font>

  • fake spotter (unregistered)

    totally fake

  • (cs) in reply to teambanana
    Anonymous:

    XL2003 worksheets can goto 256 columns - that is column IV.

    XL2007 worksheets can goto 65536 columns - that is column XFD!

    Which makes you wonder why they goto column ZZ? 

    Cool. That means there's column WTF in there!

  • Asztal (unregistered)

    In Excel 2007, with its 65536 columns, you'd have 495,850,424 lines of code. Each line averages roughly 50 characters, giving 24,792,521,200 bytes (23GB) as the resultant file size. O_o

  • (cs) in reply to Maarten
    Anonymous:

    <FONT face="Courier New">public long addUpAllExcelColumns(int first, int last)
    </FONT>

    <FONT face="Courier New">return sum;

    </FONT>

    And what's the deal with the expression 'Add Up'.  Have you ever heard of anyone 'Adding Down'?

    I think 'XLRowSum' would be a better name then addUpAllExcelColumns. 

     

     

  • verbatim (unregistered)

    It took me a minute to realize that those were... gulp... parameters.

    wtf doesn't begin to describe this.

  • (cs)
    function printf(char* format, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6, void* arg7, void* arg8 ................ void* arg255) {
        <snip recurse='100' />
    }
  • anonny (unregistered) in reply to GoatCheez
    GoatCheez:
    I am left wondering though, why do some of the parameters have a _ prefixing them?
    They munged the name to avoid reserved words like 'do'.

    captcha=java.

    The daily WTF is, why is the TDWTF title bar blinking 'loading' like a strobe light?  And why is it eating my messages?
  • Anonymous Squirrel (unregistered) in reply to JBL
    JBL:
    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!")


    Surely that's what God invented Excel Spreadsheets and Word Mail Merge for?

    Does no-one else have word processors and spreadsheets write their code? No?
  • (cs)

    I actually said "What.  The.  Fuck." out loud.  Multiple times.  Screaming.

     

    I may have trouble sleeping tonight.

  • Shoe (unregistered)

    <FONT face=Verdana size=2>Create your own fun with the following program that creates the wtf function as well as a sample call to the function:</FONT>

    <FONT face="Courier New" size=1>#include <stdio.h></FONT>

    <FONT face="Courier New" size=1>#define BRILLANT 0
    int main()
    {
        unsigned int count = 1;
        char letter, firstLetter, secondLetter;</FONT>

    <FONT face="Courier New" size=1>    printf("#include <stdio.h>\n");
        printf("long addUpAllExcelColumns(\n");</FONT>

    <FONT face="Courier New" size=1>    printf("int a");
        for( letter = 'b'; letter <= 'z'; ++letter )
        {
            ++count;
            printf(", int %c", letter);
        }</FONT>

    <FONT face="Courier New" size=1>    for( firstLetter = 'a'; firstLetter <= 'z'; ++firstLetter )
        {
            for( secondLetter = 'a'; secondLetter <= 'z'; ++secondLetter )
            {
                printf(", int _%c%c", firstLetter, secondLetter);
                ++count;
            }
        }</FONT>

    <FONT face="Courier New" size=1>    printf(") {\nreturn a");</FONT>

    <FONT face="Courier New" size=1>    for( letter = 'b'; letter <= 'z'; ++letter )
            printf("+%c", letter);</FONT>

    <FONT face="Courier New" size=1>    for( firstLetter = 'a'; firstLetter <= 'z'; ++firstLetter )
            for( secondLetter = 'a'; secondLetter <= 'z'; ++secondLetter )
                printf("+_%c%c", firstLetter, secondLetter);</FONT>

    <FONT face="Courier New" size=1>    printf(";\n }\n");</FONT>

    <FONT face="Courier New" size=1>    printf("// only %u args!\n", count);
        printf("int main() {");
        printf("printf(\"sample call: %ld\\n\", addUpAllExcelColumns(");</FONT>

    <FONT face="Courier New" size=1>    printf("1");
        for( ; count > 1; --count )
            printf(",1");</FONT>

    <FONT face="Courier New" size=1>    printf("));\nreturn 0;}\n");</FONT>

    <FONT face="Courier New" size=1>    return BRILLANT;
    }
    </FONT>

    <FONT face=Verdana size=2>Run with the following command sequence (assuming you've saved the file as generator.c).</FONT>

    <FONT face="Courier New" size=1>[temp]$ make generator
    cc     generator.c   -o generator
    [temp]$ ./generator | indent > brillant.c</FONT><FONT face="Courier New" size=1>
    [temp]$ make brillant
    cc     brillant.c   -o brillant
    [temp]$ ./brillant
    sample call: 702
    [temp]$</FONT>

    <FONT face="Courier New" size=1> 

    </FONT>
  • (cs) in reply to Bus Raker
    Bus Raker:
    Anonymous:
    yes there is, Excel is 1-based

    Holy crapola ... you're right!

    That's the real WTF!  That's makes no sense ... if you loaded rows into an array, you would have to consider that the array is 0 based and the R1C1 is 1 based.

    No, VBA (and VB6 and earlier) have 1-based arrays.... sorta. Well, let me show you:

    <FONT face="Courier New">Dim Penguins(5) as String</FONT>

    actually gives you a 6-element array, indexes of 0 to 5. Most vb programmers ignore the 0 index and use 1-5, therefore treating it as a 1-based array.

    Yes, its warped my brain. I still get lots of off-by-one bugs. And no, VB.Net doesn't have this same quirk.

  • mrputter (unregistered) in reply to BradC

    > actually gives you a 6-element array, indexes of 0 to 5.

    Well... maybe. The full declaration would be:

    <font face="Courier New" size="2"><font color="#000080">Dim</font> Penguins<font color="#000080">(</font>0 <font color="#000080">to</font> 5<font color="#000080">)</font> <font color="#000080">As</font> String</font>

    If the lower bound is omitted then it defaults to whatever is specified by the <font color="#000080" face="Courier New" size="2">Option Base</font> statement (e.g.: <font face="Courier New" size="2"><font color="#000080">Option Base</font> 0</font>, <font face="Courier New" size="2"><font color="#000080">Option Base</font> 1</font>, etc.). If this is not present, then the default lower bound is 0.

  • Ash Moollan (unregistered)
    If I had to call this method, I'd use some nifty reflection on the 702-parameter method and dynamically create the method call. Looks like the way to go!
     
    Or I could just use the sum() fucntion, but then:
    1. That would be too easy
    2. It would reduce all the hard work of developing this function to nothing.
     
    Some people, sometimes ...
     
    Captcha: awesomeness
    (describes this wtf absolutely)
  • (cs) in reply to lw
    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.

    I really was just about to post this. It took me 10 minutes to lift my jaw up off the floor before I realized the biggest WTF.

    Imagine yourself, and your boss just asking you to write a function to allow people to add fewer than 600 integers without typing out zeros.

    Ugh, I have to add three and four again ... there goes the afternoon.

    Add(3, 4, 0, 0, 0, 0, ...

  • rob_squared (unregistered) in reply to Stas
    Anonymous:
    That's weird - it's all I could say too: "Wow..."


    First thing I thought was, "stupid people aren't always lazy."  Which in this case, is a bad thing.

    PS: This is the programmatic equivalent of a kick to the nuts.
  • foxyshadis (unregistered) in reply to GoatCheez
    GoatCheez:
    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...

    psst, goatcheez, English is not C. If you want to make a damned bit of sense, stop nesting parentheses and take 20 seconds to restructure your thoughts. I hope your code isn't as mesy as your thought process. And stop making up stupid abbreviations, you might as well acronymize your entire reply.

    I believe type promotion occurs only when the return statement acts on the final calculated expression. However, throwing a single (long) on the first into would force everything to be promoted to long.

    I wonder if the callers line up their calls just like a spreadsheet in order to keep some semblace of sanity to the calls?
  • Boaz (unregistered) in reply to foxyshadis

    The real WTF is that it uses only one statement, and copies the variables, wasting memory. Everybody knows accumulation is faster.
    It should be

    /* 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 - BEH - v3.0 - Optimized addition algorithm
    /

    <font size="2">public long addUpAllExcelColumns(
      ref int a,  ref int b,  ref int c,  ref int d,  ref int e,  ref int f,  ref int g,  ref int h, 
      ref int i,  ref int j,  ref int k,  ref int l,  ref int m,  ref int n,  ref int o,  ref int p, 
      ref int q,  ref int r,  ref int s,  ref int t,  ref int u,  ref int v,  ref int w,  ref int x, 
      ref int y,  ref int z,
     
      ref int aa, ref int ab, ref int ac, ref int ad, ref int ae, ref int af, ref int ag, ref int ah,
      ref int ai, ref int aj, ref int ak, ref int al, ref int am, ref int an, ref int ao, ref int ap,
      ref int aq, ref int ar, ref int _as, ref int at, ref int au, ref int av, ref int aw, ref int ax,
      ref int ay, ref int az,

      ref int ba, ref int bb, ref int bc, ref int bd, ref int be, ref int bf, ref int bg, ref int bh,
      ref int bi, ref int bj, ref int bk, ref int bl, ref int bm, ref int bn, ref int bo, ref int bp,
      ref int bq, ref int br, ref int bs, ref int bt, ref int bu, ref int bv, ref int bw, ref int bx,
      ref int by, ref int bz,
     
      ref int ca, ref int cb, ref int cc, ref int cd, ref int ce, ref int cf, ref int cg, ref int ch,
      ref int ci, ref int cj, ref int ck, ref int cl, ref int cm, ref int cn, ref int co, ref int cp,
      ref int cq, ref int cr, ref int cs, ref int ct, ref int cu, ref int cv, ref int cw, ref int cx,
      ref int cy, ref int cz,
     
      ref int da, ref int db, ref int dc, ref int dd, ref int de, ref int df, ref int dg, ref int dh,
      ref int di, ref int dj, ref int dk, ref int dl, ref int dm, ref int dn, ref int _do, ref int dp,
      ref int dq, ref int dr, ref int ds, ref int dt, ref int du, ref int dv, ref int dw, ref int dx,
      ref int dy, ref int dz,

      /
    Snip 100 lines */
     
      ref int ya, ref int yb, ref int yc, ref int yd, ref int ye, ref int yf, ref int yg, ref int yh,
      ref int yi, ref int yj, ref int yk, ref int yl, ref int ym, ref int yn, ref int yo, ref int yp,
      ref int yq, ref int yr, ref int ys, ref int yt, ref int yu, ref int yv, ref int yw, ref int yx,
      ref int yy, ref int yz,

      ref int za, ref int zb, ref int zc, ref int zd, ref int ze, ref int zf, ref int zg, ref int zh,
      ref int zi, ref int zj, ref int zk, ref int zl, ref int zm, ref int zn, ref int zo, ref int zp,
      ref int zq, ref int zr, ref int zs, ref int zt, ref int zu, ref int zv, ref int zw, ref int zx,
      ref int zy, ref int zz)
    {
        b += a;
        c += b;
        d += c;
        e += d;
        f += e;
        g += f;
        <snip>
        zz += zy;
    }

    Clearly this is much more readable and efficient than the original version. It also leads to more reusable code (since you can't pass in constants)

    String foo = ...;
    int a = ..., b=...., c=....., .......;
    addUpAllExcelColumns(a, b, c,.....)
    doSomethingWith(zz, foo)
    //a, b, c, ... can now be reused

    Notice how this code also has the advantage of being much more readable than
    doSomethingWith(addUpAllExcelColumns(4,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...........................................................................................................................), foo);

    I mean, you can't even see the foo in the second code snippet.

    Captcha: bedtime. Seriously, I am soooo tired and I am wasting time writing quality code for the daily WTF, where people will probably just mock me because they are unaware of the principles of good design.
    </font>

  • (cs) in reply to BradC
    BradC:
    Bus Raker:
    Anonymous:
    yes there is, Excel is 1-based

    Holy crapola ... you're right!

    That's the real WTF!  That's makes no sense ... if you loaded rows into an array, you would have to consider that the array is 0 based and the R1C1 is 1 based.

    No, VBA (and VB6 and earlier) have 1-based arrays.... sorta. Well, let me show you:

    <FONT face="Courier New">Dim Penguins(5) as String</FONT>

    actually gives you a 6-element array, indexes of 0 to 5. Most vb programmers ignore the 0 index and use 1-5, therefore treating it as a 1-based array.

    Yes, its warped my brain. I still get lots of off-by-one bugs. And no, VB.Net doesn't have this same quirk.


    VB.Net certainly does have the same quirk.  It gets me all the time as I often switch back and forth between C# and VB.Net.  Even stranger is that VB.Net always starts arrays at 0, changing the base is no longer supported, yet there is an Array.GetLowerBound method in the framework.

  • A. Dude (unregistered) 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)?


    I thought the current theory was to count the removal of bad/unnecessary LOC as positive (or at least ignore it), especially if moving code into common functions.

    Removing this should count as double.
  • NateB2 (unregistered) in reply to Albatross

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

    Done.

    rowSum = addUpAllExcelColumns(a,b,c,d,e,f,g,h,I,j,k,l,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,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,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,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,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,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,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,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,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,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,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,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,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,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,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)

    (should be 702 calls - 26 + 26^2)

    And I thought the macros I have to maintain are bad...

    I am *still* trying to figure out *why* someone would write such a function; I can add Excel values without resorting to the above monstrosity (arrays and loops come to mind). VBA will gladly add any value that looks like a number without expressly identifying it as such.

  • (cs) in reply to JBL

    public long addUpAllExcelColumns(
      int a=0,  int b=0,  int c=0,  int d=0,  int e=0,  int f=0,  int g=0,  int h=0,  
      int i=0,  int j=0,  int k=0,  int l=0,  int m=0,  int n=0,  int o=0,  int p=0,  
      int q=0,  int r=0,  int s=0,  int t=0,  int u=0,  int v=0,  int w=0,  int x=0,  
      int y=0,  int z=0,
     
      int aa=0, int ab=0, int ac=0, int ad=0, int ae=0, int af=0, int ag=0, int ah=0,
      int ai=0, int aj=0, int ak=0, int al=0, int am=0, int an=0, int ao=0, int ap=0,
      int aq=0, int ar=0, int _as=0, int at=0, int au=0, int av=0, int aw=0, int ax=0,
      int ay=0, int az=0,

      int ba=0, int bb=0, int bc=0, int bd=0, int be=0, int bf=0, int bg=0, int bh=0,
      int bi=0, int bj=0, int bk=0, int bl=0, int bm=0, int bn=0, int bo=0, int bp=0,
      int bq=0, int br=0, int bs=0, int bt=0, int bu=0, int bv=0, int bw=0, int bx=0,
      int by=0, int bz=0,
     
      int ca=0, int cb=0, int cc=0, int cd=0, int ce=0, int cf=0, int cg=0, int ch=0,
      int ci=0, int cj=0, int ck=0, int cl=0, int cm=0, int cn=0, int co=0, int cp=0,
      int cq=0, int cr=0, int cs=0, int ct=0, int cu=0, int cv=0, int cw=0, int cx=0,
      int cy=0, int cz=0,
     
      int da=0, int db=0, int dc=0, int dd=0, int de=0, int df=0, int dg=0, int dh=0,
      int di=0, int dj=0, int dk=0, int dl=0, int dm=0, int dn=0, int _do=0, int dp=0,
      int dq=0, int dr=0, int ds=0, int dt=0, int du=0, int dv=0, int dw=0, int dx=0,
      int dy=0, int dz=0,

      /* Snip 100 lines /
     
      int ya=0, int yb=0, int yc=0, int yd=0, int ye=0, int yf=0, int yg=0, int yh=0,
      int yi=0, int yj=0, int yk=0, int yl=0, int ym=0, int yn=0, int yo=0, int yp=0,
      int yq=0, int yr=0, int ys=0, int yt=0, int yu=0, int yv=0, int yw=0, int yx=0,
      int yy=0, int yz=0,

      int za=0, int zb=0, int zc=0, int zd=0, int ze=0, int zf=0, int zg=0, int zh=0,
      int zi=0, int zj=0, int zk=0, int zl=0, int zm=0, int zn=0, int zo=0, int zp=0,
      int zq=0, int zr=0, int zs=0, int zt=0, int zu=0, int zv=0, int zw=0, int zx=0,
      int zy=0, int zz=0)
    {
        return
          a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z+
          aa+ab+ac+ad+ae+af+ag+ah+ai+aj+ak+al+am+an+ao+ap+aq+ar+_as+at+au+av+aw+ax+ay+az+
          ba+bb+bc+bd+be+bf+bg+bh+bi+bj+bk+bl+bm+bn+bo+bp+bq+br+bs+bt+bu+bv+bw+bx+by+bz+
          ca+cb+cc+cd+ce+cf+cg+ch+ci+cj+ck+cl+cm+cn+co+cp+cq+cr+cs+ct+cu+cv+cw+cx+cy+cz+
          da+db+dc+dd+de+df+dg+dh+di+dj+dk+dl+dm+dn+_do+dp+dq+dr+ds+dt+du+dv+dw+dx+dy+dz+
          /
    Snip 20 lines */
          ya+yb+yc+yd+ye+yf+yg+yh+yi+yj+yk+yl+ym+yn+yo+yp+yq+yr+ys+yt+yu+yv+yw+yx+yy+yz+
          za+zb+zc+zd+ze+zf+zg+zh+zi+zj+zk+zl+zm+zn+zo+zp+zq+zr+zs+zt+zu+zv+zw+zx+zy+zz;
    }

    Took me all of 30 seconds.

  • joe (unregistered) in reply to Bus Raker
    Bus Raker:
    Anytime you may have the need to write code to write your code, you must be doing something wrong!

    I totally disagree with the blanket statement.  Code generators such as OR Mappers and Codesmith Templates are valid development tools.  In fact I have a few friends who would say you must be doing something wrong if you aren't using OR Mappers.

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


    Good thing Visual Studio has Intellisense! Don't know how useful is though when you have 600+ overloads, may take a while to step through them all before you find the one you interested in.
  • (cs) in reply to akrotkov
    akrotkov:
    public long addUpAllExcelColumns(
      int a=0,  int b=0,  int c=0,  int d=0,  int e=0,  int f=0,  int g=0,  int h=0,  
     
      /* Snip the rest of this crap*/
       
    Took me all of 30 seconds.



    C# don't support default parameters, see Why doesn't C# support default parameters?
  • (cs) in reply to JBL

    I wonder how they could not notice that in every book about programming ever written in every language everywhere in the universe there is an example about how to use a loop to add several numbers together.

  • Martijn (unregistered)

    There must be atleast as many ways to do this better as there are arguments in the function call.

    I especially like how this remind me of a WTF of a few days ago which read somewhat like "long add(int a, int b) { return a + b; }". This WTF is roughly 300 times worse.

     

  • (cs)

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

    Just a question - doesn't Excel (I have 2003) only go up to column IV?

     

  • Kooky Koder (unregistered)
    public long addUpAllExcelentColumns(int D, int U, int M, int B) { ...


  • NifT (unregistered) in reply to NaPoLeAn

    This is totally unrelated to the present topic...whatever happened to Gopher?

    I've been out of the country, living in a small village in Southeast Asia since 1996. I have since returned to the US and am just now getting accustomed to this new "world wide web"...which apparently people now call "the internet".

    In any case, what happened to Gopher? That was my favorite!

  • Gerben Rampaart (unregistered)

    I clicked 'Report Abuse' after reading this.

  • GB (unregistered)

    a good WTF too is that you don't have ZZ columns in Excel... only up to IV...
    or is it a fake WTF?


  • PinkFloyd43 (unregistered)

    Never, repeat Never, Never, Never take a job w/o doing research into their existing code. Ask to sit with a developer and check out the code, if they won't let ya don't work there, never, ever will I ever work for someone who does not allow me to know WTF I am getting into.

     

  • asdqwe (unregistered) in reply to GoatCheez
    GoatCheez:

    IITIKWGO == If I think I know what's going on...


    You aren't even sure if you THINK you know what's going? WTF?!?
  • (cs) in reply to teambanana
    Anonymous:

    XL2003 worksheets can goto 256 columns - that is column IV.

    XL2007 worksheets can goto 65536 columns - that is column XFD!

    Which makes you wonder why they goto column ZZ? 

    XL2008 worksheets will goto column WTF!

  • Buh Foon (unregistered) in reply to asdqwe
    Anonymous:
    GoatCheez:

    IITIKWGO == If I think I know what's going on...


    You aren't even sure if you THINK you know what's going? WTF?!?
    We don't pay you to think!

Leave a comment on “A Function to Quit For ”

Log In or post as a guest

Replying to comment #:

« Return to Article