The periodic strangeness of idiomatic PythonJuly 29, 2012
Suppose that you want to do something N times, for whatever reason. In
C, the straightforward and idiomatic way to do this is a for _ in range(0, times): .... (Some people will use This is certainly what instantly popped into my head when I ran into this situation recently and at first I didn't think any more of it. But once I began actually looking at this it started getting stranger and stranger, less like a clear language idiom and much more like a convention. Let me run down a number of the ways that this is strange:
The overall summary of this is that the Python idiom really is close to being an idiom, in the literal definition of the word: it is an expression whose meaning is not clearly and immediately understandable from a quick read of its component parts. By contrast the C idiom is much clearer (at least for me). (I don't think that all of this makes the Python idiom bad; it remains the most compact and probably the most efficient way of expressing this. And even without knowing this idiom off the top of your head I think it's reasonably clear roughly what it does (and it's reasonably easy to work out all of the details).) Comments on this page:
From 87.194.56.231 at 2012-07-29 03:35:06:
By nothings at 2012-07-29 04:38:22:
From 173.72.85.26 at 2012-07-30 01:53:41:
From 87.79.236.202 at 2012-07-30 08:54:49:
From 72.207.242.240 at 2012-08-07 23:32:25:
By cks at 2012-08-22 13:00:49:
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |