Slices time complexity
Rustom Mody
rustompmody at gmail.com
Tue May 19 07:41:19 EDT 2015
On Tuesday, May 19, 2015 at 1:49:31 PM UTC+5:30, Steven D'Aprano wrote:
> On Tuesday 19 May 2015 15:33, Rustom Mody wrote:
>
> > However conceptually/pedagogically making a fundamenal distinction of
> > timeless | time
> > value | object
> > immutable | mutable
> > expression | statement
> > function | procedure
> >
> > is key to getting programming [and is something that Pascal got better
> > than most of its successors].
>
> Hmmm. Well, I don't quite know what distinction you are making between
> timeless and time, that's ambiguous, and I strongly disagree with the
> value/object distinction, but the rest seems reasonable.
Take Pascal and the statement:
y := x+1
A Pascal programmer (and more generally any imperative language programmer)
understands this in two frames:
The 'x+1' is understood mathematically; ie we dont need or wish or encourage
to think of it in terms of machine instructions.
OTOH the 'y := <rhs>' is to be understood procedurally or algorithmically or
in terms of some (maybe half-assed) machine abstraction.
It is only after learning to juggle these two framings that we can deal with
things like
x := x+1
C messes all this badly
1. Illegitimately coopting the '=' symbol for the assignment
2. By making expressions like ++ which are enough to confuse everyone
[ including the compiler eg i = i++ --- does that increment or is it a no-op?]
3. Expressions are statement-ified by a ';' which discards the top-level value
Python is in some respects better than C -- at least assignment is a statement
In some its worse. Think how frequent are questions out here on/around
- mixing up list.extend with +; sorted with sort
- comprehensions with side-effecting expressions etc
Think of the straigtforwardness of this error
>>> x = while
File "<stdin>", line 1
x = while
^
SyntaxError: invalid syntax
with clueless silence of this one:
>>> l = [1,2,3]
>>> l = l.append(4)
>>> l
>>>
Most answers to issues like the second focus on the fact that None at
top-level vanishes. A minor nuisance compared the to the real culprit, viz
the append allowable as an rhs.
More information about the Python-list
mailing list