views:

364

answers:

11

I need to download some csv files over http from the internet, parse it and convert it to a more useful fomat. Eventually a C++ program will consume the data. A few years ago, I would be pulling out my Perl books and start writing Perl scripts to do the downloading and parsing. But now with Boost and Qt I can do the download, parsing, and throw in a GUI front end in C++ with very little effort. Last time I wrote Perl/Python was about 6 months ago. It will probably take me longer to do it in Perl/Python and my Perl/Python code will be crap. If the only tool I have is a hammer, everything looks like a nail? Or time has changed and C++ can be productive in area traditionally dominated by script languages such as Perl or Python?

A: 

Yes, that's it exactly.

dwc
+1  A: 

Well, if you have to build a house, a hammer will work just fine. But building a house using a pneumatic framing nailer is much easier.

C++ is a fine language and you can be productive in areas that are dominated by scripting languages, but all things equal, you will be more productive using perl/python for text parsing.

Alan
A: 

C++ was not specially designed to handle long strings of text. (Just look at the old C-Strings... they were a nightmare for anything serious.) By contrast, Perl was made for this sort of use.

You can probably cruft together something in C++, but a Perl solution will probably be more robust and maintainable.

Anonymous Cow
Its easy to write unmaintainable perl.
Alan
+2  A: 

Why not?

If you're code is going to be hacky because of lack of libraries/features, then C++ might not be best. If it needs to change often, then C++ might not be best. If others who know Perl/Python will maintain it, then C++ might not be best. etc.

Do you really need a GUI? Do you need the speed? Nothing has changed to make C++ a scripting language, but that doesn't mean you shouldn't use it.

If it passes common sense tests like this, than why not?

jskulski
+3  A: 

For your example it seems that you will be more productive and able to solve your problem more easily using C++ as that is what you know.

But generally I would expect that more people would use python/perl for this kind of task.

Mark
+9  A: 

What does it matter what other people might usually expect the solution to be? If you can get the work done better and faster in C++, do it in C++, end of story.

Crashworks
+2  A: 

Actually, on some of the recent (and not so recent) python versions, you can do it very easily, as it has builtin csv reading and writting support. For instance:

import csv
spamReader = csv.reader(open('eggs.csv'))
for row in spamReader:
    print ', '.join(row)

Python code can be used on C/C++ code, though you may have to import several python libs as well.

Daniel Ribeiro
urllib.urlopen probably
Jimmy
+1  A: 

The issue of productivity of C/C++ vs. python/perl seems irrelevant to me. If you want to write your parser using Qt, Boost, and any other off the shelf tool sets, do it. You didn't actually specify if the speed of parsing is an issue, but even if it was, would it even matter for your case.

Even if you think that it might be easier in language X, write it in language Y if you want to try and learn something new about that language. It sounds like a pretty easy task so just write it how you want to write it.

You also need to think about future use. If this program will need to be enhanced and extended in some way, that might dictate a specific language choice.

Mark
A: 

If you're more productive in C++ then by all means use C++. It's still a good idea to learn other languages, but sometimes you need to go with what you know to get things done.

BTW, you probably already know this, but the Boost.Tokenizer library has CSV parsing capabilities built-in through the escaped list separator.

Ferruccio
A: 

From your description, it sounds like you have other tools besides a hammer. The more tools you have, the more efficiently you can get things done. Use whatever tools you have at your disposal to get the job done, and occasionally buy (learn) more tools.

John at CashCommons
A: 

I like C++. I hate the compile, run, test, close cycle - specifically when I need to test data.

My solution: I made a small programming environment [powered by Lua] which I embed in my C++ applications and I open it at run-time and do stuff interactively. Why to stick at one programming environment or another? Use the best of both worlds.

Nick D