Experiences/guidance on teaching Python as a first programming language
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Dec 19 12:12:24 EST 2013
On Wed, 18 Dec 2013 17:15:30 +0000, Mark Lawrence wrote:
> On 18/12/2013 08:18, Steven D'Aprano wrote:
>>
>> The C99 standard lists 191 different kinds of undefined behavior,
>> including what happens when there is an unmatched ' or " on a line of
>> source code.
>>
>> No compile-time error, no run-time error, just blindingly fast and
>> correct (according to the standard) code that does the wrong thing.
>>
>>
> Plenty of compile-time warnings depending on the compiler, which the
> CPython core devs take a great deal of trouble to eliminate on every
> buildbot.
Correct. The *great deal of trouble* part is important. Things which are
the responsibility of the language and compiler in (say) Java, D, Rust,
Go, etc. are the responsibility of the programmer with C.
I mention these languages as they are all intended to be safer languages
than C while still being efficient. Whether they succeed or not is
another question.
Now, I wish to be absolutely clear. There are certain programming areas
where squeezing out every last iota of performance is important, and to
do so may require making some compromises on correctness or safety. I
find the C standard's position on undefined behaviour to be
irresponsible, but, hey, maybe it is justified on the basis that C is a
systems language intended for use in writing performance-critical
operating system kernels, device drivers and similar. It's fine for
Python to promise that nothing you do will ever cause a segfault, but for
a language used to write kernels and device drivers, you probably want
something more powerful and less constrained.
But why is so much non-performance critical code written in C? Why so
many user-space applications? History has shown us that the decision to
prefer efficiency-by-default rather than correctness-by-default has been
a disaster for software safety and security. C language practically is
the embodiment of premature optimization: the language allows compilers
to silently throw your code away in order to generate efficient code by
default, whether you need it or not.
--
Steven
More information about the Python-list
mailing list