[Python-ideas] Operator for inserting an element into a list
mikhailwas at gmail.com
Sat Jun 16 13:21:42 EDT 2018
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 = item
> Silent breakage, requiring runtime debugging.
Not sure that it's different from any other situation:
e.g. if by mistake I will write:
L[i+1] instead of
Visual difference between
is big enough to reduce the typing error. But maybe I did not
understand your example case.
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?
>> 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
imo has more chance to be understood correctly than e.g.:
L = 
L ^= x
L ^= y
By L there is some mnemonical hint because  is used to create
new empty list. Plus it does not introduce overloading of the operator.
And overloading has weakness in this - e.g. " var1 += var2 " does not
have mnemonics, other than + character (it could be two integers as well).
So if L is found somwhere far from initialisation - it may be a good aid.
It makes it more clear what is happening, compared to augmented operator.
More information about the Python-ideas