- 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
There's no row 65536 in Excel .. it stops at 65535 (2^16-1)
Admin
yes there is, Excel is 1-based
Admin
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)
Admin
I think most people here get it, but we're just trying to squeeze as much fun from that function as possible :)
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!
Admin
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.
Admin
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?
Admin
The excel sum() ignores non-numric values, although it does propogate error values.
Admin
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!)
Admin
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.
Admin
I certainly hope it's a joke... it would be so much better written as:
Admin
Of course it's a joke, 90% of the comments are a joke! your code is shorter, means you are less productive!
Admin
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!
Admin
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...
Admin
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>Admin
<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>
Admin
totally fake
Admin
Cool. That means there's column WTF in there!
Admin
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
Admin
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.
Admin
It took me a minute to realize that those were... gulp... parameters.
wtf doesn't begin to describe this.
Admin
Admin
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?
Admin
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?
Admin
I actually said "What. The. Fuck." out loud. Multiple times. Screaming.
I may have trouble sleeping tonight.
Admin
<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>Admin
<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.
Admin
> 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.
Admin
Admin
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, ...
Admin
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.
Admin
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?
Admin
The real WTF is that it uses only one statement, and copies the variables, wasting memory. Everybody knows accumulation is faster.
<font size="2">public long addUpAllExcelColumns(It should be
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>
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
C# don't support default parameters, see Why doesn't C# support default parameters?
Admin
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.
Admin
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.
Admin
/* 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?
Admin
Admin
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!
Admin
I clicked 'Report Abuse' after reading this.
Admin
a good WTF too is that you don't have ZZ columns in Excel... only up to IV...
or is it a fake WTF?
Admin
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.
Admin
You aren't even sure if you THINK you know what's going? WTF?!?
Admin
XL2008 worksheets will goto column WTF!
Admin