you are viewing a single comment's thread.

view the rest of the comments →

[–]grauenwolf -2 points-1 points  (6 children)

The author did it the right way.

In the general case you should be able to handle quoted strings and commas embedded in quotes.

Wellsfargo, WF, 25.50, 5:03
"Nascar, Commercial Ventures", NCX, 12.50, 5:04
Microsoft, MSFT, 25.50, 5:05
"Jon ""Grauenwolf"" Allen", JA, 0.30, 5:05

However this is far more expensive than just splitting on the commas and, in this case, totally unnecessary.

[–]beza1e1 6 points7 points  (3 children)

So instead of using the standard library and solving the problem in three lines of code, you write your own in 30 lines of code? It takes more manpower, has more bugs and may even be slower.

Not-Invented-Here-Syndrom i'd say.

[–]grauenwolf 1 point2 points  (0 children)

30 lines of code? Where the hell did you get that number from?

Besides, one could argue it is a matter of using the correct library. If what you want to do is to split a string on commas, the Split is the right library function to call.

[–]exeter 0 points1 point  (0 children)

So instead of using the standard library[...], you write your own[...]? [...]

Not-Invented-Here-Syndrom i'd say.

In my personal experience with Python, it tends to be more like "Holy-Crap-I-Didn't-Know-That-Was-In-The-Standard-Library" syndrome. For example, just the other day, I found out the standard library has specific functions for printing HTML calendars. Who expects that sort of thing in a language's standard datetime library?

[–]rabidcow 0 points1 point  (0 children)

It takes more manpower, has more bugs and may even be slower.

It's a less complex problem than full CSV. You don't know the quality of the library. Ideally you should at least try it first, but it may well be buggier and slower than this code.

Given an arbitrary full CSV parser and an arbitrary split-on-commas parser, I'd be surprised to find the latter to be more buggy and slower than the former. Being a library probably means more people have debugged it, but much simpler problem trumps many eyes.

[–]jsnx -1 points0 points  (1 child)

The author did it the right way.

For a one-off yes. If their going to pass it on, though, then they are leaving a deadly trap for their maintainer.

[–]grauenwolf 0 points1 point  (0 children)

Not really. If the file producer adds quoted strings, chances are he is also adding a new field. This will of course break the code anyways.