Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Suggestion for "syntax error": ++i, --i

Reply
Thread Tools

Re: Suggestion for "syntax error": ++i, --i

 
 
Petr Prikryl
Guest
Posts: n/a
 
      12-13-2004
Hi Christian,

The suggestion is to mark PREFIX version ++i as
syntax error. It is not related to the postfix
version of the ++ operator. For prefix in/decrement,
there is no extra variable behind. But again,
it is not related to the suggestion. The postfix
version is already marked as "syntax error".
The suggestion is to do the same with the prefix
version of the operators that are not used in Python.

Petr

"Christian Ergh" wrote...
> Hmm, i never liked the i++ syntax, because there is a value asignment
> behind it and it does not show - except the case you are already used

to it.
>
> >>> i = 1
> >>> i +=1
> >>> i

> 2
>
> I like this one better, because you see the assignment at once, it is
> easy to read and inuitive usability is given - in my opinion.
> Chris
>
>
>
>
> Petr Prikryl wrote:
> > Hi,
> >
> > Summary: In my opinion, the C-like prefix
> > increment and decrement operators (++i and --i)
> > should be marked as "syntax error".
> >
> >
> > Current situation: try... (Python 2.4 (#60, ...))
> >
> >>>>i = 1
> >>>>i

> >
> > 1
> >
> >>>>i++

> >
> > File "<stdin>", line 1
> > i++
> > ^
> > SyntaxError: invalid syntax
> >
> >>>>++i

> >
> > 1
> >
> >>>>--i

> >
> > 1
> >
> >
> > Reason for how ++i and --i behaves in Python is
> > that it is probably treated as (-(-i)) and (+(+i))
> > respectively.
> >
> > Rationale: My guess is that many Python users
> > do use other languages at the same time.
> > The C-family languages do use the prefix increment
> > and decrement operators. When used in Python
> > no warning appears -- the code simply does not work
> > as expected. In the same time, there is probably no
> > reason to use the increment and decrement
> > prefix operators. On the other hand, the newcommer
> > or the programmer that "types ++i automatically
> > because of brain synapses say he/she should..."
> > is not warned until something does not work.
> >
> > Con: The situation must be recognized by the parser
> > (i.e. someone have to implement it).
> >
> > Pro: No runtime overhead except of the detection
> > of the situation. As Python is a good candidate
> > to be used as the language for teaching, the "syntax
> > error" would be the pedagogical plus.
> >
> > Personal experience: Many things in Python work
> > intuitively. My C++ experience "forced me" to use
> > ++i as described above. I use iteration more these
> > days and I know about the ++i problem invisibility
> > in Python. But I had to learn by mistake. The ++i
> > behaviour is not intuitive for me.
> >
> > Your opinion?
> >
> >

 
Reply With Quote
 
 
 
 
Christian Ergh
Guest
Posts: n/a
 
      12-13-2004
Ah, ok, i misunderstood you. Well, to mark it as a syntax error sounds
good, and at the Moment I would not know a case where this conflicts
with a implementation.
Chris
Petr Prikryl wrote:
> Hi Christian,
>
> The suggestion is to mark PREFIX version ++i as
> syntax error. It is not related to the postfix
> version of the ++ operator. For prefix in/decrement,
> there is no extra variable behind. But again,
> it is not related to the suggestion. The postfix
> version is already marked as "syntax error".
> The suggestion is to do the same with the prefix
> version of the operators that are not used in Python.
>
> Petr
>
> "Christian Ergh" wrote...
>
>>Hmm, i never liked the i++ syntax, because there is a value asignment
>>behind it and it does not show - except the case you are already used

>
> to it.
>
>> >>> i = 1
>> >>> i +=1
>> >>> i

>>2
>>
>>I like this one better, because you see the assignment at once, it is
>>easy to read and inuitive usability is given - in my opinion.
>>Chris
>>
>>
>>
>>
>>Petr Prikryl wrote:
>>
>>>Hi,
>>>
>>>Summary: In my opinion, the C-like prefix
>>>increment and decrement operators (++i and --i)
>>>should be marked as "syntax error".
>>>
>>>
>>>Current situation: try... (Python 2.4 (#60, ...))
>>>
>>>
>>>>>>i = 1
>>>>>>i
>>>
>>>1
>>>
>>>
>>>>>>i++
>>>
>>> File "<stdin>", line 1
>>> i++
>>> ^
>>>SyntaxError: invalid syntax
>>>
>>>
>>>>>>++i
>>>
>>>1
>>>
>>>
>>>>>>--i
>>>
>>>1
>>>
>>>
>>>Reason for how ++i and --i behaves in Python is
>>>that it is probably treated as (-(-i)) and (+(+i))
>>>respectively.
>>>
>>>Rationale: My guess is that many Python users
>>>do use other languages at the same time.
>>>The C-family languages do use the prefix increment
>>>and decrement operators. When used in Python
>>>no warning appears -- the code simply does not work
>>>as expected. In the same time, there is probably no
>>>reason to use the increment and decrement
>>>prefix operators. On the other hand, the newcommer
>>>or the programmer that "types ++i automatically
>>>because of brain synapses say he/she should..."
>>>is not warned until something does not work.
>>>
>>>Con: The situation must be recognized by the parser
>>>(i.e. someone have to implement it).
>>>
>>>Pro: No runtime overhead except of the detection
>>>of the situation. As Python is a good candidate
>>>to be used as the language for teaching, the "syntax
>>>error" would be the pedagogical plus.
>>>
>>>Personal experience: Many things in Python work
>>>intuitively. My C++ experience "forced me" to use
>>>++i as described above. I use iteration more these
>>>days and I know about the ++i problem invisibility
>>>in Python. But I had to learn by mistake. The ++i
>>>behaviour is not intuitive for me.
>>>
>>>Your opinion?
>>>
>>>

 
Reply With Quote
 
 
 
 
Peter Maas
Guest
Posts: n/a
 
      12-13-2004
Christian Ergh schrieb:
> Ah, ok, i misunderstood you. Well, to mark it as a syntax error sounds
> good, and at the Moment I would not know a case where this conflicts
> with a implementation.


target = 'a='
sign = '-'
operand = '-2'

exec(target+sign+operand)

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
-------------------------------------------------------------------

 
Reply With Quote
 
Steven Bethard
Guest
Posts: n/a
 
      12-13-2004
Peter Maas wrote:
>
> target = 'a='
> sign = '-'
> operand = '-2'
>
> exec(target+sign+operand)


Hopefully not too many people write code like above when it isn't much
harder to write this without exec:

>>> target = 'a'
>>> sign = '-'
>>> operand = '-2'
>>> sign_functions = {'+'perator.pos, '-'perator.neg}
>>> globals()[target] = sign_functions[sign](int(operand))
>>> a

2

This avoids fun with exec like:

target = 'a='
sign = '-'
operand = '-2; import os; os.removedirs("/")'

=)

Steve
 
Reply With Quote
 
Mel Wilson
Guest
Posts: n/a
 
      12-14-2004
In article <cpkgda$pt3$04$(E-Mail Removed)-online.com>,
Christian Ergh <(E-Mail Removed)> wrote:
>Ah, ok, i misunderstood you. Well, to mark it as a syntax error sounds
>good, and at the Moment I would not know a case where this conflicts
>with a implementation.


Well, you can overload prefix `+` and `-` operators on an
object by defining __pos__ and __neg__ methods, so --a, ++a,
+-a, -+a, +-+a and other similar combinations are actually
good syntax, and as useful as you want them to be.

Regards. Mel.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless Access Point Suggestion =?Utf-8?B?UyBMYW5l?= Wireless Networking 2 06-24-2005 10:39 PM
Suggestion for a new name, logo and slogan for the Mozilla Suite... Charles Firefox 2 03-12-2005 04:31 AM
"Read-only" version of Mozilla? (suggestion for a new software idea) Hallvard Tangeraas Firefox 4 01-12-2005 07:24 PM
FireFox-opening new tabs, a suggestion me Firefox 3 09-21-2004 04:19 PM
Re: Suggestion for Cache flush in Moz Caffeine Junkie Firefox 1 01-20-2004 06:06 AM



Advertisments