Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31665 > unrolled thread
| Started by | Dave Angel <d@davea.name> |
|---|---|
| First post | 2012-10-18 12:47 -0400 |
| Last post | 2012-10-18 22:00 -0400 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: A desperate lunge for on-topic-ness Dave Angel <d@davea.name> - 2012-10-18 12:47 -0400
Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-19 01:20 +0000
Re: A desperate lunge for on-topic-ness Dave Angel <d@davea.name> - 2012-10-18 22:00 -0400
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-10-18 12:47 -0400 |
| Subject | Re: A desperate lunge for on-topic-ness |
| Message-ID | <mailman.2454.1350578890.27098.python-list@python.org> |
On 10/18/2012 12:26 PM, Chris Angelico wrote: > On Fri, Oct 19, 2012 at 3:16 AM, Evan Driscoll <driscoll@cs.wisc.edu> wrote: >> Python isn't as bad as C++ though (my main other language), where >> 80 characters can go by *very* quickly. >> >> 2. Backslash continuations are *terrible*. I hate them with a firery >> passion. :-) A line could be 1000 characters long and it would be >> better than a 120-character line backslash-continued. > I have one mid-sized C++ project at work that's pretty much > exclusively under my control. There is precisely ONE place where > backslash continuations crop up, and that's long strings that want to > be formatted on multiple lines (eg huge SQL statements) - in Python, > they'd be trip-quoted. We don't have *any* backslash continuations in > Python code. > > But both C++ and Python have automatic concatenation of adjacent strings. So you can just start and end each line with a quote, and leave off the backslash. Similarly, if you need a newline at the end of each line, you can use the \n just before the trailing quote. Naturally I agree with you that this case is better handled in Python with triple-quote. I never use the backslash at end-of-line to continue a statement to the next. Not only is it a readability problem, but if your editor doesn't have visible spaces, you can accidentally have whitespace after the backslash, and wonder what went wrong. -- DaveA
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-10-19 01:20 +0000 |
| Message-ID | <5080aadf$0$29971$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #31665 |
On Thu, 18 Oct 2012 12:47:48 -0400, Dave Angel wrote:
> I never use the backslash at end-of-line to continue a statement to the
> next. Not only is it a readability problem, but if your editor doesn't
> have visible spaces, you can accidentally have whitespace after the
> backslash, and wonder what went wrong.
What, you don't read the SyntaxError that you will invariably get?
# Python 2.7 and 3.3:
py> x = 42 + \
File "<stdin>", line 1
x = 42 + \
^
SyntaxError: unexpected character after line continuation character
Even if you go back to truly ancient Python 1.5:
[steve@ando ~]$ python1.5
Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat
4.1.2-52)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> x = 42 + \
File "<stdin>", line 1
x = 42 + \
^
SyntaxError: invalid token
Honestly, it's not that hard to diagnose line continuation errors. It's
probably easier to diagnose them than to diagnose missing parentheses.
The more I hear people dissing line continuation backslashes, the more I
want to use them everywhere.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-10-18 22:00 -0400 |
| Message-ID | <mailman.2490.1350612076.27098.python-list@python.org> |
| In reply to | #31699 |
On 10/18/2012 09:20 PM, Steven D'Aprano wrote: > On Thu, 18 Oct 2012 12:47:48 -0400, Dave Angel wrote: > >> I never use the backslash at end-of-line to continue a statement to the >> next. Not only is it a readability problem, but if your editor doesn't >> have visible spaces, you can accidentally have whitespace after the >> backslash, and wonder what went wrong. > What, you don't read the SyntaxError that you will invariably get? > > > # Python 2.7 and 3.3: > > py> x = 42 + \ > File "<stdin>", line 1 > x = 42 + \ > ^ > SyntaxError: unexpected character after line continuation character > > > > Even if you go back to truly ancient Python 1.5: > > [steve@ando ~]$ python1.5 > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>> x = 42 + \ > File "<stdin>", line 1 > x = 42 + \ > ^ > SyntaxError: invalid token > > > Honestly, it's not that hard to diagnose line continuation errors. It's > probably easier to diagnose them than to diagnose missing parentheses. > > The more I hear people dissing line continuation backslashes, the more I > want to use them everywhere. The context was both C++ and python, and I got into the habit of avoiding the continuation characters in C++, where the compiler usually has a totally stupid error, if any. it's been so long since I've used them, it's quite possible I never tried it in python. -- DaveA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web