- 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
String result = ... + insertComma(varA) + "," + insertComma(varB) + ...;
Admin
oeps i meant: String result = ... + insertComma(varA) + "Frist" + insertComma(varB) + ...;
Admin
Seems pretty obvious to me... they're just trying to create a CSV file.
terribly.
Admin
On a related note, the percentage of VB programmers that don't know how to escape quotes is scary, even considering the sample population is VB programmers.
In all fairness, I do find it kind of counter-intuitive. Why are backslashes too scary for basic?
Admin
Gosh, I hope none of the variables used with this method have quotes in them...
Admin
Now now, at least they used a StringBuffer... Sure, you might argue that they didn’t use it outside of that method, but hey, it’s a start.
Admin
Anyone heard of StringBueller? Anyone? Anyone?
Admin
Not personally... no. Heard of StringBuilder though!
Admin
A stretch, but in the UK, quote marks (") are sometimes called inverted commas. So maybe insertComma was supposed to be insertInvertedCommas but, as we all know, shorter function names are more efficient!
Admin
Whoosh!
Admin
Ha. I find that code very funny. Funny as in the most useless and pointless and CPU consuming from time sharing hardworking operating system way. Luckily for us, people who write those kinds of code exist in every line of industry or life and generally have ratio of 8 to 2 thus keeping life interesting. Who's up for a drink to talk about good looking famous people?
Admin
Clearly the work is unfinished. I suggest an additional function...
Syntax...Admin
The failure to use sensible naming conventions would suggest that the coder is a celebrity parent.
"We considered James, but in the end we thought that Sage Moonblood would be more appropriate."
Admin
The function name is clearly off, apart from that I don't see anything but normal not-that-well-written code. It's not like the performance or readability otherwise is worse than a lot of other code.
Admin
Error: Variable 'varA' undefined Error: Variable 'varB' undefined Error: Not a function.
FTFY
Admin
Hey, at least he used a StringBuilder instead of concatenating one string. Not that that would probably make much difference in this case.
Admin
I don't see the WTF.(Except for the function name).
I have seen code written by a major database company that has exactly the same functionality. They were doing this for creating dynamic SQL Strings and instead of writing '''' many many times, they preferred creating a java function for it.
Admin
The ratio is more like 12 to 3 in my experience.
Admin
comment = insertComment ("");
Admin
[comma user="Pragmatopian"]The failure to use sensible naming conventions would suggest that the coder is a celebrity parent.
"We considered James, but in the end we thought that Sage Moonblood would be more appropriate."[/comma]
Hey that's my sorcerer elf's name too!
[2]
Admin
This is what you get when you outsource development to countries where English is not well understood.
comma, quote, period, yaa yaa, whatever, just go insert it. Guys probably tried different values for the char d part till they got it working ...
Admin
Why does all code, regardless of what it was written in, become another problem with VB programmers. Second, vb.net doesn't support the " escape character as far as I know, you need to use "" to represent a dbl quote in a string. I would have used string.format("""{0}"",""{1}""",vara,varb). So we're not afraid of backslashes, we don't need to use them.
Admin
That's far too optimistic. Try 28 to 7
Admin
to put it in plain terms what akatherder is saying is that the ration should be about 2^32 to 2^30.
Admin
Mr. eBusiness, what you've just said is one of the most insanely idiotic things I have ever heard. At no point in your rambling, incoherent response were you even close to anything that could be considered a rational thought. Everyone in this thread is now dumber for having listened to it. I award you no points, and may God have mercy on your soul.
Sorry, I've always wanted to use that quote. The function name is off, but nothing else matters. Not naming function names somewhat close to what they're supposed to do is one of the worst heresies in the programming realm. It's comparable to building an airplane, and calling it a car. Every other person of the same language will get really mad at you. You went against a well-known-labeling scheme, and nothing bothers people more than when you mess with their labels.
Admin
Ha! I'd go as far as to say 80%.
Admin
Please tell us which database company, so I can avoid their products (I suspect it's Oracle - their C++ was shite back when I had to use their API and I doubt their Java's much better).
Admin
What is the try/catch for? Sure you wouldn't expect StringBuffer.append to throw an exception unless you are running out of memory or something, but a try/catch that rarely (if ever) actually throws an exception probably has little performance impact.
Why is the delimiter not a class variable or a parameter? If all you ever need to do is enclose a string in quotes, why write a (not much) more complicated general purpose function that takes an extra parameter or worse hide the delimiter as a class variable which I would argue would be less readable?
What the $§%& does the method name to do with the content? If the function had a sensible name (like quoteString) it would be better. So TRWTF is that they gave the method a name which doesn't describe what the method does.
Admin
I think it's worth noting that in Java the plus operator actually uses a StringBuffer behind the scenes anyway, so constructing your own in this simple case just adds needless wordiness.
Also, I hate these terrible catch blocks. Do you really want to return an empty string when there's an error? REALLY??
Admin
If you really must:
Admin
and by 80 you mean 75?
Admin
Admin
now now, it could have been a teensy bit worse. At least they did not make a separate stringbuffer for the quote, and they factored out the quote instead of using the literal twice. So give them two small pluses, among the dozen minuses.
Admin
For those complaining about the method name and its content... From its usage it probably use to insert a comma.
Ok the person was a little too lazy at the min a comment should of been added.
At the most this item gets a quick rolling of the eyes and when you get around to it a copy of the method and renaming it and all the calling locations.
Admin
It does not matter. Had he just concatenated the strings, the compiler would have used a StringBuilder anyway.
If there is no loop, method call, or variable modification involved in concatenating strings, just concatenate them. The bytecode will be identical and the code will be easier to read.
Admin
I think the method was originally meant to be used like this:
String result = '"' + varA + insertComma(",") + varB + insertComma(",") + varC + '"';
And was then subverted by later developers to be used like mention in the post:
String result = ... + insertComma(varA) + "," + insertComma(varB) + ...;
Admin
don't talk about midgets like that. they prefer the term "little people".
unless you prefer the term "stupid" over "math-challenged". ;-)
Admin
If you must use a function to do your dirty work, then at least use a variadic function and let it handle the +","+ as well. It will look cleaner and make you look less silly.
String resultA = commaJoin(argA, argB, argC); String resultB = commaJoin(argB, argC);
Admin
Admin
Hmmmm.
Needs XML.
Admin
On a related note, I am a VB programmer. I do know how to escape quotes, and backslashes are not too scary, it was just decided that the string parsing subroutines would be quicker if they did not need to check for control codes to be converted into the proper ASCII values.
On the other hand, the code above is C# and not VB (hint: VB doesn't use semi-colons and curly braces).
Addendum (2010-01-06 10:46): The above code could be Java. It's simple enough to be either, though from other comments, it would seem that Java has the types used built-in.
Admin
If you use a String, the Java compiler uses StringBuilder under the hood.
Admin
Try again, .NET doesn't have a StringBuffer, it has a StringBuilder. You must be a VB 6 programmer or you'd know that. The camel casing suggests Java.
Admin
If you're using a BASIC dialect like that I'm pretty sure performance isn't your biggest concern. Unless it starts showing up in a profiler, I think clarity, ease of use, and ease of implementation should be your biggest concerns in these situations. Who knows, maybe they're using it in a high use area? It just doesn't seem like it would be a very big issue.
Admin
Not great code, but not as much of a WTF as you might think:
Anybody who has done database exports and imports of large data sets knows that memory (and memory limitation errors) is a persistently nagging problem. Catching it as it occurs as a quick-hack way of knowing how long your string can be (perhaps to show that information to the user, e.g., do not export anything beyond the sales records for Ohio) is not a bad idea if you can't afford to double-parse your data set (once to count and pre-allocate the required amount of memory without going hog-wild on multiples, once to directly set the strings in place without using stack- or heap-costly concatenation.)
It was probably a shortened method name: InsertCommaDelimitedCompatibleValue or some such.
Verdict: Story: meh. Code: not WTF-worthy.
Admin
Really? Huh. I guess I've been away from Java too long, it's gotten a bit rusty.
Admin
successful troll is successful
Admin
maybe its used to send the developers into a coma
Admin
That's a good solution. I did not know you could have a variable number of parameters in Java. I would name it "prepForCSV" or something that describes the most likely business use of the function. The function also needs to scan the strings for quotes and escape them, but that depends on the client that would be reading the CSV, which makes it troublesome. Still, it should be escaped so at least its apparent that a miscreant quotation is present. Or replace it with a single tick.
Admin
Like a supersonic jet.