Miro said:
I've made the title too provocative. What I mean is, why use C++ for
small ( > 1000 lines ) coding jobs?
I guess you meant "< 1000 lines"...
It doesn't make much sense to me as...
C++ syntax requires a lot more typing, debugging and memory,
C++ syntax doesn't need memory, and debugging only required if
you made mistakes (which is not so much different from a script
written in an interpreted language, I think).
Compilation time can be irksome,
C++ is devoid of the plethora of features you find on Python, Ruby or
our dear Swiss Army Chainsaw.
Don't get me wrong, I don't dislike C++, nor am I trying to rile up
the great gurus among us, however, I fail to see a practical reason to
use this language much as I go about my hacking life.
I understand that it compiles directly into binary and can be from
there run without an interpreter, but that seems a small price to pay
for a five line ( in good practice ) hello world.
Well, you can have a "hello world" program in two-to-five lines
of C++, depending on the way you lay-out things;-) And if all
you do is writing "hello world" programs then it is rather ir-
relevant which language you use.
Otherwuse your question is comparing apples to bananas. In
many cases load and compilation/interpretation times aren't
of much concern. Then use the language you feel most at home
with to get the job done and which is most expressive (i.e.
that requires the least typing and gives you the least chance
of making mistakes - like I would not dream of writing a C++
program when I have to e.g. convert the format of a few data
file when it can be done in Perl or sed or something similar
I am familiar with in a one-liner).
On the other hand some programs that need to be run very often
can be a lot faster when written in a compiled language since
the overhead of starting the interpreter and having it inter-
pret the script tends to be a lot higher than starting a short
compiled program (even if the actual task requires only a rather
small number of lines of code). I often start by writing such
things in an interpreted language I know well enough but when
I find that they are becoming a bottleneck I rewrite them in
C or C++.
Then there are programs that require all the speed you can squeeze
out of your machine or that need all the memory available etc.
(and that is not necessarily directly related to number of lines
of code). Those are the ones I wouldn't consider writing in an
interpreted language (except perhaps for a proof-of-concept im-
plementation).
And, of course, there are also quite a number of cases where
the parts that really need to be fast and make the most effi-
cient use of memory can be written in a compiled language like
C++ and the other parts in an interpreted language. So there's
really no one-is-better-than-the-other but an (hopefully edu-
ctated) choice of what to use in a certain situation.
Regards, Jens