[Python-ideas] Operator for inserting an element into a list

Cameron Simpson cs at cskk.id.au
Sat Jun 16 18:25:20 EDT 2018

On 16Jun2018 20:21, Mikhail V <mikhailwas at gmail.com> wrote:
>On Sat, Jun 16, 2018 at 4:44 AM, Cameron Simpson <cs at cskk.id.au> wrote:
>> On 16Jun2018 02:42, Mikhail V <mikhailwas at gmail.com> wrote:
>> Some things _should_ be syntax errors. Particularly things which may be
>> typing errors. Suppose I'd meant to type:
>>  L[0] = item
>> Silent breakage, requiring runtime debugging.
>Not sure that it's different from any other situation:

Well, many typing errors are invalid syntax. When that happens you find out 

>e.g. if by mistake I will write:
>    L[i+1]   instead of
>    L[i+2]

This is true: many other typing errors are not syntax errors.

>Visual difference between
>    L[] =
>    L[1] =
>is big enough to reduce the typing error. But maybe I did not
>understand your example case.

No, you understand the example; we differ in our estimation of likelihoods and 
costs to mistakes.

Particularly, I dislike "silent breakage", which aan be much harder to fix 
because it shows as incorrect behaviour far from the error (eg counters being 
slightly wrong leading to misbehaviour in things depending on the counter).  
Assuming we are lucky enough for the misbehaviour to be obvious.

But there is also the point that _every_ new piece of syntax reduces the 
surface of "invalid syntax that can catch simple mistakes". So new syntax tends 
to requires a higher perceived benefit than, say, a new feature on a 
class/type. Such as your suggestions about having lists support more operators 
i.e. "^" to mediate list insertion.

>FWIW in general, claims about possible typing errors by
>introducing this or that syntax are speculative.


>Main source of typos usually is high similarity of spellings and
>characters, or initial obscurity of spelling - e.g. excessive
>punctuation. Does it apply here?

Unsure, depends on the programer.

>>> I understand this is totally different approach than operator
>>> overloading and maybe
>>> hard to implement, but I feel like it looks really appealing.
>>> And it is quite intuitive imo. For me the syntax reads like:
>>> "add new empty element and this element will be "item".
>> The term "new empty element" is a nonsense term to me.
>> If you mean "replace an empty slice at the end of the list with a new
>> element", that can already be written:
>I just say that I find this syntax is more intuitive than the idea
>with operator. Not sure that we need to start semantics nitpicking.
>For example, such code:
>    L = []
>    L[] = x
>    L[] = y

Well, as someone else pointed out, PHP has this notation for append. It is 
quite convenient. (In fact, it is one of the very few convenient things in 

However, PHP is generally not a winning source of ideas in the Python world.  
Certainly I was _very_ glad to not be suffering with PHP once I left my 
previous job. There were many many things to like about my previous job, but 
PHP was not one of them.

Cameron Simpson <cs at cskk.id.au>

More information about the Python-ideas mailing list