SV: Python Productivity over C++
Neurocrat
neurocrat at one.net.au
Tue Jun 13 18:55:44 EDT 2000
David Bolen <db3l at fitlinxx.com> writes:
[ compile time errors]
> This does raise an interesting question. Of the total set of errors
> (which "most" you receive during compilation), how many of them are
> related to syntactic or language overhead versus algorithmic issues.
>
> It seems to me that the former does not necessarily represent a
> benefit to C++ over Python, because in my experience C++ has more
> syntactic "sugar" that can increase errors in that respect, so the
> fact that you get more of them during compilation isn't something that
> translates over to Python anyway.
>
> Some amount of such errors (say errors in type declarations or other
> issues related to the strong, static typing of C++) can certainly
> point to algorithm issues during compilation. But again, many of
> those issues arise from the requirement of strong typing an algorithm
> in the first place, so need to be considered as errors whose existence
> are largely a by-product of the development environment in use.
My (admittedly very limited) experience with Python bears this
out. Many of my compile time errors caught by C++ are errors that
would not have been present in a language with cleaner syntax.
I know this is the exceptional case, but sometimes Python even has the
advantage here. Every C++ programmer has done this at some point:
for (int i = 0; i < 10; ++i);
cout << "Hello" << endl;
This, of course, prints "Hello" only once, not 10 times as we
intended. In a toy example it's easy to spot the offending ; at the
end of the loop construct, but is there a C or C++ programmer alive
who hasn't spent hours trying to track down insidious problems caused
by that single legal semicolon? I know I have.
If I made the corresponding mistake in Python:
for x in range(10) # forgot the :
print "hello"
I'd know it straight away.
> But true, there's the area of name errors during runtime, which my
> first inclination was to consider a real problem with Python. Even
> with some of the 'lint'-like tools around, it didn't seem to be
> considered a major problem by the community. But the more code I
> write the less concerned I become as I find that surprisingly it just
> isn't showing up as a major problem,
I too find it surprising, but my experience is the same.
> ... and it's easy enough to program
> defensively against anyway.
I think the use of assertions to define the intended behaviour of a
routine is a better way of both preventing and catching bugs than any
compile time mechanisms. That's just my personal opinion. (Of course,
that much is possible with C++ too).
More information about the Python-list
mailing list