473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reduce need of backslash

Hi,

I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?

Regards,

Nicolas

Jul 18 '05 #1
16 1795
Nicolas Fleury wrote:

I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?


What should Python do in the following case?

a = 5 +
someFunc(a)

Okay, you want it to quietly add 5 and the result of someFunc() together and
assign to "a". What if I told you that I actually had intended to add 5
plus "b" and assign to a, then call someFunc() and discard the return value.

You've just turned a nice clean error message from the compiler into a
silent and possibly deadly bug.

"Explicit is better than implicit, and errors should never pass silently"
as has been noted again recently in another thread.

-Peter
Jul 18 '05 #2
Nicolas Fleury <ni******@yahoo.com_remove_the_> wrote in
news:h4*********************@nnrp1.uunet.ca:
I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?


You very rarely need \ as it is. Any parenthesised expression may be split
across lines without problems.

--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #3
Nicolas Fleury wrote:
I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?


Did you know about (...)?
("alpha" .... + "beta"
.... + "gamma"
....
.... )
'alphabetagamma'

Peter
Jul 18 '05 #4

"Duncan Booth" <du****@NOSPAMrcp.co.uk> wrote in message
news:Xn***************************@127.0.0.1...
Nicolas Fleury <ni******@yahoo.com_remove_the_> wrote in
news:h4*********************@nnrp1.uunet.ca:
I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?
You very rarely need \ as it is. Any parenthesised expression may be split
across lines without problems.


And you can parenthesize a surprisingly large number of places. One
that I learned just recently was that the entire operand string of the
print statement can be put into parenthesis.

John Roth
--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

Jul 18 '05 #5
John Roth wrote:
"Duncan Booth" <du****@NOSPAMrcp.co.uk> wrote in message
And you can parenthesize a surprisingly large number of places. One
that I learned just recently was that the entire operand string of the
print statement can be put into parenthesis.


I'm not sure what you mean exactly.
print (1,2) prints a tuple while print 1,2 prints a different thing.

Regards,

Nicolas

Jul 18 '05 #6
Nicolas Fleury wrote:
John Roth wrote:
"Duncan Booth" <du****@NOSPAMrcp.co.uk> wrote in message
And you can parenthesize a surprisingly large number of places. One
that I learned just recently was that the entire operand string of the
print statement can be put into parenthesis.

I'm not sure what you mean exactly.
print (1,2) prints a tuple while print 1,2 prints a different thing.


Ok, print (1) doesn't print a tuple... forget my question...

Nicolas

Jul 18 '05 #7
Peter Otten wrote:
Nicolas Fleury wrote:

I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?

Did you know about (...)?


Actually, no. But it's still not what I'm looking for. It's just that
I'm used to languages where I can put my code on multiple easily to make
lines shorter. As John pointed, it's possible to add () to print. I
just discovered that it can be done with return also. I wonder how to
remove the need for \ in that example:

parser.StartElementHandler = \
lambda name, attrs: \
GenericParser.handleElementStart(self, name, attrs)

Regards,

Nicolas

Jul 18 '05 #8
Peter Hansen wrote:
What should Python do in the following case?

a = 5 +
someFunc(a)

Okay, you want it to quietly add 5 and the result of someFunc() together and
assign to "a". What if I told you that I actually had intended to add 5
plus "b" and assign to a, then call someFunc() and discard the return value.

You've just turned a nice clean error message from the compiler into a
silent and possibly deadly bug.


What if the second line would be indented? Indentation is already used
to determine blocks, why not instructions? For example, the following
is not error-prone at all:

a = 5 +
someFunc()

Doesn't it stay with python minimalistic philosophy?

Regards,

Nicolas

Jul 18 '05 #9

"Nicolas Fleury" <ni******@yahoo.com_remove_the_> wrote in message
news:MI*********************@nnrp1.uunet.ca...
Peter Otten wrote:
Nicolas Fleury wrote:

I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?

Did you know about (...)?


Actually, no. But it's still not what I'm looking for. It's just that
I'm used to languages where I can put my code on multiple easily to make
lines shorter. As John pointed, it's possible to add () to print. I
just discovered that it can be done with return also. I wonder how to
remove the need for \ in that example:

parser.StartElementHandler = \
lambda name, attrs: \
GenericParser.handleElementStart(self, name, attrs)


How about:

parser.StartElementHandler = (lambda name, attrs:
GenericParser.handleElementStart(self, name, attrs))

John Roth
Regards,

Nicolas

Jul 18 '05 #10
On Fri, 26 Sep 2003 13:34:22 -0400, Nicolas Fleury
<ni******@yahoo.com_remove_the_> wrote:
What if the second line would be indented? Indentation is already used
to determine blocks, why not instructions? For example, the following
is not error-prone at all:

a = 5 +
someFunc()

Doesn't it stay with python minimalistic philosophy?


I don't know the original rationale, but to me this mostly looks ugly.
Maybe I'd get used to it if it happened a lot, but this is rarely an
issue in practice.

Basically, when I need to break an expression over multiple lines, the
odds are that it already has parentheses anyway. And I wouldn't indent
that way anyway, I'd do it as...

a = ( firstitem
+ seconditem
+ ( thirditem
* fourthitem
)
)

.... ie using indentation to clarify the structure of the expression
much as I would with block structuring - whether I was using Python or
some other language.

In a way I can imagine some value to putting a statement in
parentheses. It would look very Lispy, but then some would say that's
a good thing.

Occasionally, I go through a phase of thinking semicolons should be
used as compulsory statement terminators rather than as the rarely
used separators they are now - in which case '\' would be completely
redundant - but it really is a trivial issue, whereas the idea of
changing such a fundamental piece of syntax - well, don't go there.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #11
Stephen Horne wrote:
Basically, when I need to break an expression over multiple lines, the
odds are that it already has parentheses anyway. And I wouldn't indent
that way anyway, I'd do it as...

a = ( firstitem
+ seconditem
+ ( thirditem
* fourthitem
)
)


Didn't know about that possibility; I though it would assign a one
element tuple. I just read that a one-element tuple is written (x,).
Everything's fine now, thx ;)

Nicolas

Jul 18 '05 #12
John Roth wrote:
How about:

parser.StartElementHandler = (lambda name, attrs:
GenericParser.handleElementStart(self, name, attrs))


That's perfect. All my incomprehension was because I didn't know a
one-element tuple is written (x,) and not (x). Thx

Nicolas

Jul 18 '05 #13
On Fri, 26 Sep 2003 16:33:25 +0200, Peter Otten <__*******@web.de> wrote:
Nicolas Fleury wrote:
I was wondering if the need for \ could be reduce in the language. For
example, could a line ending with = or + could be automaticly considered
incomplete?


Did you know about (...)?
("alpha"... + "beta"
... + "gamma"
...
... )
'alphabetagamma'

Did you know the tokenizer concatenates white-space-separated string literals into
a single literal? ;-)
("alpha" .... "beta"
.... "gamma"
.... )
'alphabetagamma'

Note the effect in code:
import dis
f1 = lambda: ("alpha" ... + "beta"
... + "gamma"
... ) f2 = lambda: ("alpha" ... "beta"
... "gamma"
... ) dis.dis(f1) 1 0 LOAD_CONST 1 ('alpha')
3 LOAD_CONST 2 ('beta')
6 BINARY_ADD
7 LOAD_CONST 3 ('gamma')
10 BINARY_ADD
11 RETURN_VALUE dis.dis(f2)

1 0 LOAD_CONST 1 ('alphabetagamma')
3 RETURN_VALUE

Regards,
Bengt Richter
Jul 18 '05 #14
Stephen Horne wrote:
Basically, when I need to break an expression over multiple lines, the
odds are that it already has parentheses anyway. And I wouldn't indent
that way anyway, I'd do it as...

a = ( firstitem
+ seconditem
+ ( thirditem
* fourthitem
)
)


But that's indentation anyway. If the rule would be "all lines with a
superior indentation are part of the previous line", would that work?
This way it would not be necessary to add the parenthesis. I wonder if
I'm missing something...

Regards,

Nicolas

Jul 18 '05 #15
On Sat, 27 Sep 2003 15:49:59 -0400, Nicolas Fleury
<ni******@yahoo.com_removethe_> wrote:
Stephen Horne wrote:
Basically, when I need to break an expression over multiple lines, the
odds are that it already has parentheses anyway. And I wouldn't indent
that way anyway, I'd do it as...

a = ( firstitem
+ seconditem
+ ( thirditem
* fourthitem
)
)


But that's indentation anyway. If the rule would be "all lines with a
superior indentation are part of the previous line", would that work?


Probably yes, but it has been discussed before and never generated a
clear enough choice or sufficient will to make the change.

My personal preference would be closer to Haskells offside rule,
allowing me to write something similar to my example above but with
indentation reducing the need for parentheses. But it really isn't an
important issue IMO.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #16
Bengt Richter wrote:
Did you know the tokenizer concatenates white-space-separated string
literals into a single literal? ;-)
("alpha" ... "beta"
... "gamma"
... )
'alphabetagamma'

Note the effect in code:
>>> import dis
>>> f1 = lambda: ("alpha" ... + "beta"
... + "gamma"
... ) >>> f2 = lambda: ("alpha" ... "beta"
... "gamma"
... ) >>> dis.dis(f1) 1 0 LOAD_CONST 1 ('alpha')
3 LOAD_CONST 2 ('beta')
6 BINARY_ADD
7 LOAD_CONST 3 ('gamma')
10 BINARY_ADD
11 RETURN_VALUE >>> dis.dis(f2)

1 0 LOAD_CONST 1 ('alphabetagamma')
3 RETURN_VALUE


No. Or I would have chosen another example :-)

But now you point it out I see it's used quite frequently in the library.

Peter


Jul 18 '05 #17

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

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
181
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
5
by: Arjen | last post by:
Hi All, What I want to is using a string as PATTERN in a split function. This makes it possible for me to change the PATTERN on one place in my script... For example: $separator = ";"; $line...
2
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
2
by: Tobiah | last post by:
>>"'" "'" "'" "\\'" "\\'" This is quite different than any other language that I am used to. Normally, a double backslash takes away the special meaning of the last backslash, and so you...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
4
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an...
4
nithinpes
by: nithinpes | last post by:
I will boil down my exact requirement to this: I should print out lines that do not contain semi-colon, backslash and closing parentheses. The following one -liner works fine. perl -ne "unless(//)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.