473,651 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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?
--
Petr Prikryl (prikrylp at skil dot cz)
Jul 18 '05 #1
7 4374
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?

Jul 18 '05 #2
Petr Prikryl wrote:
Summary: In my opinion, the C-like prefix
increment and decrement operators (++i and --i)
should be marked as "syntax error".


This would give some weird assymetry:
i = 1
++i Traceback ( File "<interacti ve input>", line 1
++i
^
SyntaxError: invalid syntax --i Traceback ( File "<interacti ve input>", line 1
--i
^
SyntaxError: invalid syntax +-i -1 -+i -1


Of course, anyone who writes +-i or -+i should probably be shot anyway.
;) I'm -0 on this.

Steve
Jul 18 '05 #3
Petr Prikryl wrote:
Summary: In my opinion, the C-like prefix
increment and decrement operators (++i and --i)
should be marked as "syntax error".


My guess is that the impact of it would be nil.

This is python, there are no prefix or postfix
operators. That is very easy to remember. Just because
one might get burned by it when learning python
it cannot become a recurring problem that needs fixing.

Istvan.
Jul 18 '05 #4
On Mon, 13 Dec 2004 16:42:28 +0100, rumours say that "Petr Prikryl"
<Pr*****@skil.c z> might have written:
Summary: In my opinion, the C-like prefix
increment and decrement operators (++i and --i)
should be marked as "syntax error".


[snip of lots of explanations]

I am +0 on this.

However, I can imagine no *non-obscure* reasons[1] for someone to use ++
and -- as prefixes or postfixes[2], so I think that it's possible to
modify the lexer or grammar (ain't sure) to make ++ and -- without any
spaces in-between be a valid operator somehow throwing a SyntaxError.

I have been bitten by this in the beginning[3], but OTOH it didn't last
long. I am on the plus side of 0 just because of a couple of lines of
the python Zen:

Errors should never pass silently. (although it's only a logical error)
In the face of ambiguity, refuse the temptation to guess.

my 2e-2 euros

[1] including overloaded operators and side-effects
[2] "p++ - x" is valid python even if "p++" is not
[3] at least Javascript and [ng]awk accept these operators
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #5
Christian Ergh a écrit :
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


IMO, there is an assignement only for languages like python ! (ie.
reference languages)

In languages like C or C++ (in which variables correspond to values) it
makes perfect sens to modify the current value by an operator.

Nevertheless, I agree with you concerning Python ! But not for C++ :)

Pierre
Jul 18 '05 #6
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".


We have a patch for increment and decrement operators in boo (
http://boo.codehaus.org/ ), along with an operator overloading syntax
like below. See http://jira.codehaus.org/browse/BOO-223

def +:
pass
Jul 18 '05 #7
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".

Let me rephrase my answer.
This is a good sugestion for Python 3.0, a.k.a. Python 3000:
http://www.python.org/cgi-bin/moinmoin/Python3.0

In the future you may be able to to this:

variable++

However, Python 3.0 is likely years away. If you want to know how to
run this code today, ask Fredrik Lundh.
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5154
by: James | last post by:
Please help me with this sql: SELECT z005aNORTHEAST_3days_Formula.Region, z005aNORTHEAST_3days_Formula.DiffofClaimsAssignment FROM (SELECT .Region, (.)-( .) AS DiffofClaimsAssignment FROM (SELECT .Region, ., ., .
3
1924
by: shifty shaker | last post by:
I've modified sql text and now i'm getting a syntax error that I cannot figure out....anyone? error occurs at the Insert Into line but the entire function is given in case you need it. --- Function ThisIs() Dim TDate As Date, C1 As Integer, StrSQL As String, TypeAttend, RecDetect If Not IsNull(Me.scrStudent) Then C1 = 1: TDate = Me!
3
2605
by: ChildProgrammer | last post by:
I am trying to upload data into an Access db from vb.net. The data was parsed out from text files. Everything seems to be working fine up till the .execute point. The debugger insists there is a syntax error in my statement, but when I check my insert into statement, I get what I expect. What am I doing wrong? Here is my code.: Dim str As String Dim s As ADODB.Connection = New ADODB.Connection Dim cmd As OleDbCommand s.ConnectionString =...
7
4619
by: luttkens | last post by:
I used to have no problems using IF-statement in SQL-queries. Now nothing works, it always returns "Syntax error". This query also returns an error. IF (1=1) THEN SELECT 'True' ELSE SELECT 'False' END IF What is wrong? I know it doesn't do anything, but why do I get syntax error?
2
2352
by: RAG2007 | last post by:
Hi, I'm running an ADP with SQL Server as back end. On a main form, my subform is coming up blank. When I was running as an mdb with no back end I didn't have this problem. I get an error "Syntax error access violation", and the subform is all white, not even any empty fields. I'm not even sure where to begin to look for the issue. Thanks, any help is appreciated.
2
5169
by: tvnaidu | last post by:
I am getting this error for line 108, I kept C code also below, any idea?. main.c:108: underscore in number main.c:108: syntax error before numeric constant 104: #define EXPAND_CONCAT(name1,name2) name1 ## name2 105: #define CONCAT(name1,name2) EXPAND_CONCAT(name1,name2) 106: #define RT_MODEL CONCAT(MODEL,_rtModel)
0
1623
by: Daniel Halvorse | last post by:
hi I am working on an application that manages the data in a access database. but i cant seem to get past this error. When i try to run it it says: "Syntax error in INSERT INTO statement" syntax error, I have made all the fields in database TEXT(255) so it cant be that. any help regarding this will be much appreciated, i am new to datasets and would love any help or guides i can get on the matter. ...
5
11095
by: nilupat | last post by:
Parse error: syntax error, unexpected T_VARIABLE in C:\Inetpub\vhosts\dspseed.in\httpdocs\dspseed\odernow_mail.php on line 13 my code is as folow : <?php extract($_POST); echo $_POST."<br>".$_POST."<br>".$_POST."<br>".$_POST."<br>".$_POST."<br>".$_POST."<br>".$_POST."<br>".$_POST."<br>"; $recipient=$_POST;
3
13094
by: lingjun | last post by:
Hi, I am taking my first programing course in college... and I am completely lost on this assignment. I am not sure what is wrong with my current code. Any help will be appreciate it... thanks! I keep on getting the follow error messages when I try to compile it. test.c:3: error: syntax error before numeric constant test.c: In function `main': test.c:18: error: `next_day' undeclared (first use in this function) test.c:18: error:...
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8803
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.