Python and the need for speed
rantingrickjohnson at gmail.com
Fri Apr 14 22:35:30 EDT 2017
On Wednesday, April 12, 2017 at 8:44:30 AM UTC-5, bart... at gmail.com wrote:
> On Wednesday, 12 April 2017 12:56:32 UTC+1, Jussi Piitulainen wrote:
> > bartc writes:
> > >
> > > These are straightforward language enhancements.
> > FYI, the question is not how to optimize the code but how
> > to prevent the programmer from writing stupid code in the
> > first place. Someone suggested that a language should do
> > that.
> The 'stupid code' thing is a red herring. I assume the
> code people write is there for a reason.
Yeah, but you have to admit, sometimes there is no obvious
good reason -- as Steven's example code has proven. ;-)
Although, i'm convinved that any one of us could find
examples like that in our own repos. And if you cannot find
code that makes you feel embarassed, then you're not
> But the language can also play a part in not allowing
> certain things to be expressed naturally.
> So the for-loop in the example has to have a control-
> variable even if it's not referenced.
Yes, one of the design flaws of Python's "for loop" is that
the control variable is injected whether you need it or not
(Nightmarish images of petulant children being force-fed
castor oil comes to mind...). In fact, in Python, there are
only two loop forms avialable -- the "for" and the "while".
-- however, many other languages have relized that these two
forms are insufficent to cover the various types of loops
that are needed. At a minimum, every language should offer
the following four loop-forms (using Python semantics):
for VALUE in COLLECTION:
loop(N) as i:
More information about the Python-list