Wandering Thoughts archives


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 strchr(). Python is an example of the second sort of language; it's utterly stupid to write your own version of the builtin string .find() method.

(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.

programming/TwoSortsOfLanguages written at 23:54:55; Add Comment

Page tools: See As Normal.
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.