New to programming

Alex Martelli aleaxit at yahoo.com
Mon May 21 17:35:25 EDT 2001


"Patrick Kirk" <pknews at kirks.net> wrote in message
news:9ebdp8$jr0$1 at newsg3.svr.pol.co.uk...
> Hi all,
>
> I'm learning to program and in my enthusiasm rushed out and bought Visual
> C++ and a beginners guide.  Its OK but I've read several articles warning
> that C and C++ are poor first languages.  Python is widely commented on as
> an ideal first language.
    ...
> Without starting an advocacy thread, why is Python so well spoken of as a
> first language?  Obviously knowing what makes it good makes learning it
even
> more useful...

C++ is very complex and carries a lot of historical baggage.  Its design
objectives were VERY ambitious: allow high-level, high-abstraction
programming, at the same time allow access to 100% of a machine's
power (thus, allow very low-level programming too), keep portable on
top of even very poor and widely divergent operating systems, AND, to
top it off, keep substantially all of C as its subset.  Oh, and, also keep
compatibility with C++ itself as it evolved over the years... no breaking
working code, as large investments were made in it already.  Not to
mention extra, nice, principles, such as not requiring "too much"
compilation effort (no feature requiring the compiler to 'see' all of
the code at once), having each feature such that programmers not
using it paid NO price (in terms of runtime performance), etc, which
were substantially adhered to, though not as strict as the constraints.

It made it.  It's impressive that it did manage to cover all of these
bases.  But note that "easy to learn", "easy to use", "of complexity
within the compass of the human brains", were not among the
design constraints... had they been, it would likely be an over-
constrained system, unfeasible:-).

C++ is unsuited to beginners as it's (by far) too complicated.

C is simpler, but it achieves simplicity by cutting off the crucial
"high-level" building blocks -- classes, inheritance, polymorphism,
templates.  No high-abstraction support.  And some of the 'legacy'
aka 'baggage' issues are there -- certain design decisions, that
the language designers don't care much about after all these
years, are carved in stone.

C is unsuited to beginners (not a unanimous opinion, but a widely
shared one) because it's too low-level.  "Premature optimization
is the root of all evil", quoth Knuth: starting a beginner off in a
very low-level language, such as C or assembly, can be seen as
just such a "premature optimization".  Get the high-abstraction,
high-level parts right first... optimize, if at all, later!-)


Python's design objectives, wrt C++'s, omitted high-performance
and compatibility with any specific existing language, and added
care for syntactic sparseness and elegance.  Design guidelines
differed too, both in kind (Python has no big worry about 'not
paying a price for a feature you don't use' -- it's never keen about
performance like C++) and application.

For example, Python and C++ both worry about ambiguity, and
as a principle won't "guess" at what is meant by an ambiguous
construction.  But the actual application of the principle is so
different!  C++ won't let your class A inherit from two classes B
and C which both have a method named d() unless A hides or
overrides d() -- so there will be no ambiguity about what d() is
meant if one is ever called on A.  Python decided that the order
in which the base classes are listed as A's bases is an acceptable
disambiguation: if A inherits from B first, and C second, then a
method d() not found in A will be then lookep up in B, and the
search will go on to C only if d() wasn't found in B.

In Python "explicit is better than implicit" is raised to the dignity
of a design guideline.  C++ does a lot "implicitly for you", for
your convenience... this results in an explosion of complexity.
In Python, you often spell things out, so everything remains
simple and, in the end, MORE convenient and regular for you.


Alex






More information about the Python-list mailing list