| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
String result = ... + insertComma(varA) + "," + insertComma(varB) + ...;
|
oeps i meant: String result = ... + insertComma(varA) + "Frist" + insertComma(varB) + ...; |
|
Seems pretty obvious to me... they're just trying to create a CSV file.
terribly. |
|
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? |
|
Gosh, I hope none of the variables used with this method have quotes in them...
|
|
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. |
|
Anyone heard of StringBueller? Anyone? Anyone?
|
Not personally... no. Heard of StringBuilder though! |
|
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!
|
Whoosh! |
|
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?
|
|
Clearly the work is unfinished. I suggest an additional function...
private String insertQuote(String src){
Syntax...String result = ... + insertQuote(insertComma(varA)) + insertQuote(insertComma(varB)) + ...; |
|
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." |
|
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.
|
Error: Variable 'varA' undefined Error: Variable 'varB' undefined Error: Not a function. FTFY |
|
Hey, at least he used a StringBuilder instead of concatenating one string. Not that that would probably make much difference in this case.
|
|
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. |
The ratio is more like 12 to 3 in my experience. |
|
comment = insertComment ("");
|
Re: Insert Comma?
2010-01-06 09:41
•
by
the beholder
(unregistered)
|
|
[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] |
|
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 ... |
Re: Insert Comma?
2010-01-06 09:47
•
by
VB Programmer
(unregistered)
|
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. |
Re: Insert Comma?
2010-01-06 09:47
•
by
Occasional Reader
(unregistered)
|
That's far too optimistic. Try 28 to 7 |
to put it in plain terms what akatherder is saying is that the ration should be about 2^32 to 2^30. |
Re: Insert Comma?
2010-01-06 09:51
•
by
highphilosopher
(unregistered)
|
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. |
Ha! I'd go as far as to say 80%. |
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). |
|
1. 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. 2. 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? 3. 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. |
|
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?? |
|
If you really must:
|
and by 80 you mean 75? |
No. Learn how to count. 4 out of 5 idiots think 75% is 80%. |
|
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.
|
|
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. |
Re: Insert Comma?
2010-01-06 10:15
•
by
Stephen
(unregistered)
|
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. |
|
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) + ...; |
Re: Insert Comma?
2010-01-06 10:25
•
by
anonymous internet wanker
(unregistered)
|
|
don't talk about midgets like that. they prefer the term "little people".
unless you prefer the term "stupid" over "math-challenged". ;-) |
|
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); |
The stupid thing is that it's highly inefficient anyway because it sends strings back and forth across a method call rather than sharing the StringBuilder over the whole outer call. The right thing would have been to present each row as an array or List of Strings (or, better yet, Objects). Then they could be assembled much more effectively to make a whole row of CSV output. |
|
Hmmmm.
Needs XML. |
|
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. |
Re: Insert Comma?
2010-01-06 10:43
•
by
Bob Granger
(unregistered)
|
If you use a String, the Java compiler uses StringBuilder under the hood. |
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. |
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. |
|
Not great code, but not as much of a WTF as you might think:
1. 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.) 2. It was probably a shortened method name: InsertCommaDelimitedCompatibleValue or some such. Verdict: Story: meh. Code: not WTF-worthy. |
Really? Huh. I guess I've been away from Java too long, it's gotten a bit rusty. |
successful troll is successful |
|
maybe its used to send the developers into a coma
|
Re: Insert Comma?
2010-01-06 11:05
•
by
alendar
(unregistered)
|
|
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.
|
Re: Insert Comma?
2010-01-06 11:16
•
by
jordanwb
(unregistered)
|
Like a supersonic jet. |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |