- 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
um, no it doesn't. At least not in the version I'm programming in. Nice try, though.
Admin
When I started my current job 9 months ago, I inherited a load of perl code, along with some shell stuff. I still do stuff like "my $a = 0;" even though perl will happily recast that "int" to a string if you assign a string to it or whatever. In fact, having just "my $a;" is perfectly fine as well for that same reason, though I have been in the habit of initializing variables according to what their role is (as well as adding comments about what they are supposed to be used for).
Anyway, the guy whose code I inherited didn't do any of that. Sometimes he didn't even lexically scope things. That sort of thing I change when I come across it (found a couple bugs along the way, too), but I have a hard time with the plain old non-initialized variables. If I add a var to a piece of code, do I go back and initialize the rest of the bare ones? And what do I initialize them to? Should I spend time searching through the code to see whether they are an int, string, hashref, whatnot? Because if I initialize, I'd like to set it to what it'll actually be used as so that some other guy a year from now will be able to tell that $tcnt is actually a numeric counting variable or whatever and is explicitly set to 0 because of that.
It's a lot of work and takes time from other stuff, but it makes future maintenance easier. I'm having a hard time justifying it, though. But it looks really awkward to have one initialized variable next to a bunch that aren't. I'm conflicted.
(And before you wags come off with "The real WTF is perl..." or some inanity, perl actually is the right tool for the job in this case. Though python would have been fine as well, and I kinda would have preferred it since it's generally easier to maintain unless the perl is very well written. But life is what it is.)
Admin
Admin
Can't oneself just do this, to truly replace the function... I'm assuming its in Java of course.
public long addUpAllExcelColumns(int... xs) { long sum = 0;
}
Admin
Your prowess astounds and amazes sir or madam! Why, I'll bet nobody here could have figured out a more efficient way to do this until you posted!
Admin
[quote user="wee"][quote user="jimlangrunner"]... unless the perl is very well written. ...)[/quote]
Still laughing at that one. Let me know if you ever find:
Admin
I daresay such could be said of some Igor Pro code I wrote, to automate the loading, plotting and analysis of a bunch of data. Hideous code, but works, and better than doing the same thing 3 hundred times over by hand.
Admin
It's nice to know there's worse code out there than the shit I just (hopefully) finished dealing with. 200+ lines to display the built-in keyboard. <____<
Admin
Admin
Well, there are 26*26=676 elements in original parameter list. He wants all overloads of that, so he wants to have 676 functions: a function of one argument, a function of two arguments, ..., a function of 676 arguments.
Let's assume that he's okay with using just a single type for float-point numbers (long double) and a single type for ints (long long).
Also, I assume that C# supports the idea where if the caller supplies the first n parameters, then the remaining parameters can take on default values. If that's the case, then the programmer can just write the versions of the function that take 676 parameters, and specify a default value of zero for all parameters. Of course, each of those 676 parameters must be either a (long long) or a (long double), so he'd still need to write 2^676 versions of that function.
In base 10, that's means he'd have to write this many functions: 313528531882069915964662425689704934689422834087799421518938595239444503444259215719322355763768461419760165742407930953086580768238532773442734168210737755891992072530296122920016274326105279759841755136
Which is a 204 digit number.
Admin
This shit can't be real...
Admin
Its a common n00bism.
Admin
Its a common n00bism.
Admin
"I don't understand programming at all. It's like the compiler is completely ignoring my comments."
Admin
TRWTF is that they didn't use VB. It has optional parameters!
Admin
Admin
It is a ValueType so it is initialized...implicitly. I challenge you to instantiate a ValueType that isn't initialized. ;->
Admin
answer = addUpAllExcelColumns(1,2,3,...);
or
answer = 1+2+3+...;
22 less keystrokes... why would you even have a function for this?
Admin
Admin
it's called casting lolz
hard working + dumb = segmentation fault
Admin
Best post!!
Admin
Someone should teach the "Business owner" of this system how to write Excel formulas.
=SUM(A1:ZZ1)
Admin
The real question is... how fast is his "algorithm". If speed is more important than code size, this could be an ideal solution.
Admin
C++ ey...
template <typename T> class detail { T addUpAllExcelColumns(T... arguments);
T addUpAllExcelColumns(T first, T... arguments) { return first + addUpAllExcelColumns(arguments...); }
T addUpAllExcelColumns() { return 0; } };
Made it generic too; you can now add 702 dates too! And more! And less!
Admin
I don't think there's any excuse for that function to exist at all. If I got myself into a position requiring that kind of solution my brain would be screaming bad design at me...
Admin
When I wrote this function, I wanted to be efficient. This will actually execute faster on the low level than using several conditional branches. This is assuming that your machine actually has this many registers. We, of course, have employed 20 CEs and EEs to make this happen.
Admin
This is nothing to worry about. It looks like it can be rewritten in one minute or two. What strikes me is that the original programmer didn't stopped coding and started to wonder what he was doing after one or two days of adding parameters....
Admin
Laziness is the foundation of efficiency, thus the desireable quadrant really is the top right.
Admin
So who's calling this function that would rather call one of the overloads like this:
sum = addUpAllExcelColumns(a, b, c, d, e);
instead of
sum = a + b + c + d + e;
Admin
Why "_as"?
Admin
Admin
Admin
Admin
Admin
Admin
We need column C to accept decimal values (but the return value has to remain long), and for the function to output the result as the last argument. Additionally, we want to populate a global variable. Also, in order to access the data from VBA, we need you to deserialize a comma-separated list of values we outputted from Excel to system environmental variables. Due to restrictions on how much data they can hold, we have devised a clever plan that names them as follows (xcelCount, xcelData1, xcelData2, xcelData, etc) (only 100 bytes are stored in each environmental variable, because we standardized on base 10). Please have this done before you leave.
Admin
Or even smaller =SUM(A:ZZ)
Admin
http://en.wikiquote.org/wiki/Kurt_von_Hammerstein-Equord
Admin
http://msdn.microsoft.com/en-us/library/s1ax56ch(VS.80).aspx
"Local variables in C# must be initialized before being used." I don't think its a warning by that statement.
Admin
lol. I wonder if rule 34 applies too. :-)
Admin
Admin
What problems did the programmers have with 600 params? for(int i=0;i<600;++i) { __asm{push 0} }
Admin
Its future-proof!
Admin
just wait for C# 4.0, and use optional parameters <grin>
Admin
Job security get.
Admin
Yes, it is true that ints default to 0, but you should still initialize.