Two sorts of languages
Here is a thesis:
There are two sorts of languages: languages where writing your own code is (usually) almost as fast as using the builtin features, and languages where the builtins are an order of magnitude faster than doing the same work in your own code.
C is an example of the first sort of language; it is merely silly, not
laughably absurd, to reimplement your own version of
is an example of the second sort of language; it's utterly stupid to
write your own version of the builtin string
(There are degrees of this, depending on how much slower attempts to reimplement the builtins wind up.)
This difference matters a lot for how you write programs. In the second sort of language, the way to make things fast is to use the builtins as much as possible by finding some way to express your problem in their terms; programs often spend a lot of time and effort connecting builtins together and mapping back and forth between them. Programs in the first sort of language are usually written in a much more direct way; people use the builtins, but mostly when they're convenient.
(For example, if you want to find the first occurrence in a memory block
of a byte with values between (varying) A and B, a C programmer will
probably write a
memchr-alike but a Python programmer will probably
build and match a regular expression on the fly.)
The difference also places the implementors and the users of the first sort of languages on a much more level playing field. In the second sort of language, there are strong limits on what you can do as a mere user; you can never create your own extension that runs as fast as the builtins, which means that user-level extensions are always to some degree second class citizens.
Comments on this page:Written on 27 February 2008.