- 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
This kind of thing is all too common from consultants... :S
Admin
That always happens with code written by $200/hr consultants..
Captcha - populus
http://en.wikipedia.org/wiki/Populus
Admin
And I can bet they call these function via SOAP to make it more enterprisey
Admin
I wonder if Jose C's middle intial is B.
Admin
Say what you want about the first one, but at least it does something.
The use of the var keyword in the second one makes it a no-op.
Admin
Returning the parameter untouched makes it worse than a noop due to function call overhead.
Admin
The increment one isn't (necessarily) a WTF. As far as I can recall, in Javascript, a string plus a number concatenates the number to the string. Since the function calls parseInt(), it's fair to assume that input is a string. Sure, you could say parseInt() + 1 every time, but isn't that function much simpler?
[/troll]
Admin
Admin
So, if its "Enterprise Incrementation", can we shorten that to "excrementation"?
Admin
I'm pretty sure I would have put whatever consultant wrote this through a "JavaScript compiler" and converted him into "byte-code."
Admin
AssignCommentInToOut('Fail')
Admin
That's more like it. Choosing proper function names is an essential part of writing well documented code.
Admin
This explains very succinctly why dynamic typing bothers me. I'm sure there's a more graceful way to deal with it, and it's not like THIS is required, but still - having to fight with the interpreter so that it treats a value as the data-type I want defeats the point of an ultra-high level language.
Admin
Could we fall back on Newspeak and describe this as double-plus-ungood?
Admin
Admin
If that code is what I think it is, and I think it is JavaScript, then they whould have had the source anyway.
Admin
I might have been spending too long in C++land, but that second one is hilarious. Doesn't that just leak memory? At least temporarily, until the garbage collector gets around to picking it up?
Admin
What happens if the string begins with "0" - don't you need parseInt(input, 10) ???
And doesn't "increment" mean "add one" anyway. IncrementByOne is tautological...
Admin
Note that when we say documented code, we mean documented so other programmers can understand it, I don't really care if someone who can't spell 'dumb' can't understand my code.
Go back to spending your life writing pointless word documents and leave the people with brain cells to do the coding.
sigh feeding troll I know
Admin
Those functions were clearly intended to be embedded in the database as stored procedures. After all, you would want to insulate your application code from the fact that the business logic might want to morph 1 -> 2 and assignment to +=
Admin
Admin
Admin
Admin
I always hate WTF's based on "omg that's a simple function". without context I have no idea if these were meant to be the equivalent of function-pointers/functors. In such a case, you might have a "foreach x in y: if is_predicate() then a() else b();" template set up somewhere, where "is_predicate(), a(), b()" are arguments. perhaps is_predicate(), a(), or b() will end up being a simple "do nothing", increment, or comparison. In that case, "DoNothing" makes a lot of sense. The code has to call a function, nothing needs to be done, so the "DoNothing" function is used.
Admin
No, it isn't. Read method #2 closer.
Admin
Let me try this again...
No, it isn't. Read method #2 closer.
Admin
Who hasn't written something like this?
I are a consultant and should be banned from my mommy and daddy's modem.
Admin
Admin
I charge in GB pounds. The quality of my code is undefined.
Admin
... but it's the operator overloading (of +) that causes this problem, not the dynamic typing.
Using + for string concatenation is the dumb.
Admin
Using . string concatenation is the dumb.
Admin
Admin
These (or at least the first one) may be meant for callbacks. Whoever wrote this was probably using lambdas so often they decided to put it into its own function.
Of course, the fact that they return a value might make this example not work... It depends on how their callback are called.
Admin
Admin
or you could just call ++ on it?
I know I shouldn't feed, but:
even if the number (for some reason) had a '0' at the beginning, it would push it to base 8
There's no reason to FIGHT the typing of the language, work with a language, not against it.
(ECMAScript developer here, and it's a pretty nice language if you know it)
Admin
IncrementByOne is probably not a WTF. It is probably a call back for some RPC/XHR request.
Admin
IncrementByOne. One function point, 1 hour: $200.
AssignStringInToOut. Zero function points: Priceless.
Admin
function IncrementByOne(input) { var output = parseInt(input); return output + 1; }
and then call
IncrementByOne('08')
and watch the sparks ...
Admin
What does it matter if you are using the text "a.concat(b)" or "a + b"? The result is the same. The automatic cast is the problem.
Admin
More shitty consultant code, what a big surprise. You know how we have that rule that no student code is allowed? It's a fair rule, students don't know a lot about the real world and we know their code is going to be rubbish so there's not much point in laughing at the useless little buggers.
Shouldn't we have the same rule for consultants?
Admin
Everyone knows "IncrementByOne" is actually spelled std::bind2nd(std::plus<int>,1) which is much clearer.
Admin
Admin
The real issue is auto-casting, not dynamic typing. Both Javascript, which is dynamically typed, and Java, which is strongly typed, will screw you here. Java at least tells you what kind of things you're passing around though. This mostly helps the guy who shows up after you to have half a chance of understanding what you were trying to do.
Javascript: document.write( '1' + 1 ); Output is "11"
Java: System.out.println( "1" + 1 ): Output is "11"
Admin
Given any function for doing something, there must necessarily exist a less-efficient way of doing the same thing.
Thus I submit the following as a 1000 fold improvement to their design.
Admin
For $200 an hour I'd expect some WSDL files or at least some XML Serialization....you know, because that's how they do things.
CAPTCHA: consequat : The consequat of my actions were thus noted.
Admin
I see the problem. Each of these functions is missing the standard comment that we have to place at the beginning of each and every function, regardless of length. This header includes:
They removed the part where you were supposed to list all the other functions that called this function.
Admin
What is the reason to name such void function? It can be perfectly anonymous, there is no advantage of "DoNothing" over "function(){}".
Admin
Good point. Here, let me fix it:
function IncrementByOne(input) { var output = parseInt(input + ''); return output + 1; }
Perfect!
Admin
Win!
Admin
About this $200/hr, do they actually charge $200/hr for everyone in the team who wrote funny lines of code, or you just see the invoice and assume that there aren't like 5 other $20/hr programmers from another continent behind this $200/hr consultant?
Please, my question is serious. I can kind of program and I would like to go up from $20 to $200.