Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9242 > unrolled thread

Re: An interesting beginner question: why we need colon at all in the python language?

Started byThomas Jollans <t@jollybox.de>
First post2011-07-11 16:16 +0200
Last post2011-07-16 14:07 +1000
Articles 16 — 9 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.


Contents

  Re: An interesting beginner question: why we need colon at all in the python language? Thomas Jollans <t@jollybox.de> - 2011-07-11 16:16 +0200
    Re: An interesting beginner question: why we need colon at all in the python language? Grant Edwards <invalid@invalid.invalid> - 2011-07-11 14:43 +0000
    Re: An interesting beginner question: why we need colon at all in the python language? alex23 <wuwei23@gmail.com> - 2011-07-12 23:26 -0700
      Re: An interesting beginner question: why we need colon at all in the python language? Terry Reedy <tjreedy@udel.edu> - 2011-07-13 12:18 -0400
    Re: An interesting beginner question: why we need colon at all in   the python language? Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-07-13 10:08 +0200
      Re: An interesting beginner question: why we need colon at all in   the python language? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-13 21:07 +1000
        Re: An interesting beginner question: why we need colon at all in   the python language? Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-07-13 13:26 +0200
          Re: An interesting beginner question: why we need colon at all in the python language? Tim Chase <python.list@tim.thechases.com> - 2011-07-13 07:16 -0500
        Re: An interesting beginner question: why we need colon at all in the python language? Chris Angelico <rosuav@gmail.com> - 2011-07-13 21:58 +1000
        Re: An interesting beginner question: why we need colon at all in   the python language? Grant Edwards <invalid@invalid.invalid> - 2011-07-13 13:18 +0000
      Re: An interesting beginner question: why we need colon at all in   the python language? Grant Edwards <invalid@invalid.invalid> - 2011-07-13 13:03 +0000
        Re: An interesting beginner question: why we need colon at all in the python language? Chris Angelico <rosuav@gmail.com> - 2011-07-13 23:11 +1000
        Re: An interesting beginner question: why we need colon at all in     the python language? Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-07-13 19:27 +0200
        Re: An interesting beginner question: why we need colon at all in the python language? Grant Edwards <invalid@invalid.invalid> - 2011-07-14 14:34 +0000
          Re: An interesting beginner question: why we need colon at all in the python language? Wanderer <wanderer@dialup4less.com> - 2011-07-14 08:14 -0700
            Re: An interesting beginner question: why we need colon at all in the python language? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-16 14:07 +1000

#9242 — Re: An interesting beginner question: why we need colon at all in the python language?

FromThomas Jollans <t@jollybox.de>
Date2011-07-11 16:16 +0200
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<mailman.889.1310393783.1164.python-list@python.org>
On 07/11/2011 03:51 PM, Anthony Kong wrote:
> Hi, all,
> 
> Lately I am giving some presentations to my colleagues about the python
> language. A new internal project is coming up which will require the use
> of python.
> 
> One of my colleague asked an interesting:
> 
> /If Python use indentation to denote scope, why it still needs
> semi-colon at the end of function declaration and for/while/if loop?/
> 
> My immediate response is: it allows us to fit statements into one line.
> e.g. if a == 1: print a
> 
> However I do not find it to be a particularly strong argument. I think
> PEP8 does not recommend this kind of coding style anyway, so one-liner
> should not be used in the first place!

Basically, it looks better, and is more readable. A colon, in English
like in Python, means that something follows that is related to what was
before the colon. So the colon makes it abundantly clear to the human
reader that a block follows, and that that block is to be considered in
relation to what was just said, before the colon.

Coincidentally, Guido wrote this blog post just last week, without which
I'd be just as much at a loss as you:

http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html

[toc] | [next] | [standalone]


#9251

FromGrant Edwards <invalid@invalid.invalid>
Date2011-07-11 14:43 +0000
Message-ID<ivf279$jl9$1@reader1.panix.com>
In reply to#9242
On 2011-07-11, Thomas Jollans <t@jollybox.de> wrote:
> On 07/11/2011 03:51 PM, Anthony Kong wrote:
>> Hi, all,
>> 
>> Lately I am giving some presentations to my colleagues about the python
>> language. A new internal project is coming up which will require the use
>> of python.
>> 
>> One of my colleague asked an interesting:
>> 
>> /If Python use indentation to denote scope, why it still needs
>> semi-colon at the end of function declaration and for/while/if loop?/
>> 
>> My immediate response is: it allows us to fit statements into one line.
>> e.g. if a == 1: print a
>> 
>> However I do not find it to be a particularly strong argument. I think
>> PEP8 does not recommend this kind of coding style anyway, so one-liner
>> should not be used in the first place!
>
> Basically, it looks better, and is more readable.

And it makes adding a "python mode" to a programming editor almost
trivial.

-- 
Grant Edwards               grant.b.edwards        Yow! I am a jelly donut.
                                  at               I am a jelly donut.
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#9367

Fromalex23 <wuwei23@gmail.com>
Date2011-07-12 23:26 -0700
Message-ID<641c72bd-9321-4f34-b11c-2146a90fea22@28g2000pry.googlegroups.com>
In reply to#9242
Thomas Jollans <t...@jollybox.de> wrote:
> Coincidentally, Guido wrote this blog post just last week, without which
> I'd be just as much at a loss as you:
>
> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-an...

It's also part of the Python FAQ:

http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements

[toc] | [prev] | [next] | [standalone]


#9410

FromTerry Reedy <tjreedy@udel.edu>
Date2011-07-13 12:18 -0400
Message-ID<mailman.994.1310573910.1164.python-list@python.org>
In reply to#9367
On 7/13/2011 2:26 AM, alex23 wrote:
> Thomas Jollans<t...@jollybox.de>  wrote:
>> Coincidentally, Guido wrote this blog post just last week, without which
>> I'd be just as much at a loss as you:
>>
>> http://python-history.blogspot.com/2011/07/karin-dewar-indentation-an...
>
> It's also part of the Python FAQ:
>
> http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements

An added note: the header lines of compound statements do not 
necessarily occupy just one physical line. The : signals the end of the 
logical line. Editors can use to to indent intelligently. Consider

def myfunc(a,
            b,
            c):
     return a+b+c

All indentation was done automatically by IDLE's editor.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#9373 — Re: An interesting beginner question: why we need colon at all in the python language?

FromThorsten Kampe <thorsten@thorstenkampe.de>
Date2011-07-13 10:08 +0200
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<MPG.288770fad6930dba989832@news.individual.de>
In reply to#9242
* Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200)
> Basically, it looks better, and is more readable. 

People tend to overlook the colon for the same reason they tend to 
forget to set the colon in the first place:
a) it's a very weak marker in comparison to indentation and
b) it looks like doubling the markup to them (colon plus indentation)

What makes the if syntax for me even more weird, is the fact that you 
can have an else clause with an else without a then clause with a then.

if x > 5:
    print whatever 
else:
    print whatever  

in comparison to:

if x > 5
then
    print whatever 
else
    print whatever 

> A colon, in English like in Python, means that something follows that
> is related to what was before the colon. So the colon makes it
> abundantly clear to the human reader that a block follows,

The block that follows makes it abundantly clear to the human reader 
that a block follows.

> and that that block is to be considered in relation to what was just
> said, before the colon.

The indentation makes it abundantly clear to the human reader that that 
indented block is to be considered in relation to what was just said, 
before the indentation.

Thorsten

[toc] | [prev] | [next] | [standalone]


#9383 — Re: An interesting beginner question: why we need colon at all in the python language?

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-07-13 21:07 +1000
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com>
In reply to#9373
Thorsten Kampe wrote:

> * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200)
>> Basically, it looks better, and is more readable.
> 
> People tend to overlook the colon for the same reason they tend to
> forget to set the colon in the first place:
> a) it's a very weak marker in comparison to indentation and
> b) it looks like doubling the markup to them (colon plus indentation)

I can't speak for others, but speaking for myself, I wonder whether this is
a difference between English speakers and non-English speakers? To me, as a
native English speaker, leaving the colon out of a header line, as follows
below, just looks wrong.

    Nobody expects the Spanish Inquisition! <OMINOUS MUSIC>
    Our three weapons are
        * fear
        * surprise
        * and ruthless efficiency
        * and an almost fanatical devotion to the Pope!


Although the bullet list is indented, the header line "Our three weapons
are" looks like something is missing, as if I had started to write
something and forgotten to finish. It needs a colon to be complete:

    Nobody expects the Spanish Inquisition! <JARRING CHORDS>
    Amongst our weapons are:
        * fear
        * surprise
        * ruthless efficiency
        * an almost fanatical devotion to the Pope
        * and nice red uniforms


The colon indicates that the sentence has more to follow: I think of it as a
pointer. It doesn't finish the thought, like a full stop, nor is it a mere
pause, like a comma or semi-colon.

    An indented block on its own is surprising. It just hangs there, 
    with no connection to what was going on before. Why is it indented?
    Is it connected to the previous sentence?

On the other hand, a colon gives the reader that connection:

    It gives the reader a clue to expect additional information, 
    that the indented block that follows is not an independent 
    block, floating in space for its own reasons, but is intimately 
    linked to the previous line.

I know that Python is not English, and not all English conventions apply.
For example, Python uses newlines to end "sentences" (lines of code)
instead of a full stop. Nevertheless, as an English reader, it would look
wrong and awkward to drop the colon.


>> A colon, in English like in Python, means that something follows that
>> is related to what was before the colon. So the colon makes it
>> abundantly clear to the human reader that a block follows,
> 
> The block that follows makes it abundantly clear to the human reader
> that a block follows.

But it's too late by then. You have to mentally backtrack.

blah blah blah blah <statement is complete>
    indented block <surprise the previous line wasn't complete>


blah blah blah blah colon <statement is not complete>
    indented block


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#9384 — Re: An interesting beginner question: why we need colon at all in the python language?

FromThorsten Kampe <thorsten@thorstenkampe.de>
Date2011-07-13 13:26 +0200
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<MPG.28879f471300a74a989833@news.individual.de>
In reply to#9383
* Steven D'Aprano (Wed, 13 Jul 2011 21:07:17 +1000)
> Thorsten Kampe wrote:
> > * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200)
> >> Basically, it looks better, and is more readable.
> > 
> > People tend to overlook the colon for the same reason they tend to
> > forget to set the colon in the first place:
> > a) it's a very weak marker in comparison to indentation and
> > b) it looks like doubling the markup to them (colon plus indentation)
> 
> I can't speak for others, but speaking for myself, I wonder whether this is
> a difference between English speakers and non-English speakers?

It's not a difference between English and non-English speakers but the 
difference between a branch (if-then-else) and an enumeration (your 
example).

> To me, as a native English speaker, leaving the colon out of a header
> line, as follows below, just looks wrong.
> [enumeration] 
> 
> Although the bullet list is indented, the header line "Our three weapons
> are" looks like something is missing, as if I had started to write
> something and forgotten to finish. It needs a colon to be complete:

Sure, because it's an enumeration - and not a branch or loop.
 
>     An indented block on its own is surprising. It just hangs there, 
>     with no connection to what was going on before. Why is it indented?
>     Is it connected to the previous sentence?

In normal text: sure. You cannot "just indent" in Python as you like. 
Indentation always shows the connection.
 
> >> A colon, in English like in Python, means that something follows
> >> that is related to what was before the colon. So the colon makes it
> >> abundantly clear to the human reader that a block follows,
> > 
> > The block that follows makes it abundantly clear to the human reader
> > that a block follows.
> 
> But it's too late by then. You have to mentally backtrack.
> 
> blah blah blah blah <statement is complete>
>     indented block <surprise the previous line wasn't complete>
> 
> blah blah blah blah colon <statement is not complete>
>     indented block

Source code is (unlike normal text) not read line by line. So you (at 
least I) don't have to backtrack from line 2 to line 1 because you see 
them both at the same time.

Thorsten

[toc] | [prev] | [next] | [standalone]


#9386

FromTim Chase <python.list@tim.thechases.com>
Date2011-07-13 07:16 -0500
Message-ID<mailman.974.1310559392.1164.python-list@python.org>
In reply to#9384
On 07/13/2011 06:26 AM, Thorsten Kampe wrote:
> Source code is (unlike normal text) not read line by line. So
> you (at least I) don't have to backtrack from line 2 to line 1
> because you see them both at the same time.

$a
You mean there are people who don't use "ed" to write their code? ;-)

-tkc
.
w
q





[toc] | [prev] | [next] | [standalone]


#9385

FromChris Angelico <rosuav@gmail.com>
Date2011-07-13 21:58 +1000
Message-ID<mailman.973.1310558302.1164.python-list@python.org>
In reply to#9383
On Wed, Jul 13, 2011 at 9:07 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> The colon indicates that the sentence has more to follow: I think of it as a
> pointer. It doesn't finish the thought, like a full stop, nor is it a mere
> pause, like a comma or semi-colon.
>
>    An indented block on its own is surprising. It just hangs there,
>    with no connection to what was going on before. Why is it indented?
>    Is it connected to the previous sentence?

It's not necessarily surprising, depending on context; the brain
automatically assumes that the indented block was originally said by
someone else.

    The <blockquote> tag defines a long quotation.

    A browser inserts white space before and after a blockquote
    element. It also insert margins for the blockquote element.

http://www.w3schools.com/tags/tag_blockquote.asp

(I didn't need to quote that, I just wanted to go meta and block quote
something about blockquote.)

Having the colon makes it clear that the content is part of the same
general thought (paragraph or sentence).

Chris Angelico

[toc] | [prev] | [next] | [standalone]


#9392 — Re: An interesting beginner question: why we need colon at all in the python language?

FromGrant Edwards <invalid@invalid.invalid>
Date2011-07-13 13:18 +0000
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<ivk5v6$72f$1@reader1.panix.com>
In reply to#9383
On 2011-07-13, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> Thorsten Kampe wrote:
>
>> * Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200)
>>> Basically, it looks better, and is more readable.
>> 
>> People tend to overlook the colon for the same reason they tend to
>> forget to set the colon in the first place:
>> a) it's a very weak marker in comparison to indentation and
>> b) it looks like doubling the markup to them (colon plus indentation)
>
> I can't speak for others, but speaking for myself, I wonder whether this is
> a difference between English speakers and non-English speakers? To me, as a
> native English speaker, leaving the colon out of a header line, as follows
> below, just looks wrong.
>
>     Nobody expects the Spanish Inquisition! <OMINOUS MUSIC>
>     Our three weapons are
>         * fear
>         * surprise
>         * and ruthless efficiency
>         * and an almost fanatical devotion to the Pope!

Except that's wrong English[1]. At least that's not correct usage
according to what I learned in school.  A colon follows an independent
clause: something that could in essence be a complete sentence and
expresses a complete thought.  The colon separates that independent
clause from examples or an explanation or clarification of that
independent clause.  The phrase "Our three weapons are" isn't an
independent clause. It has the transitive verb "are" but no predicate
nominative.  You've placed the colon in the middle of an independent
clause between the verb "are" and the predicate nominative phrase
"fear, surprise, and ruthless efficiency, and an almost fanatical
devotion to the Pope".

Your example should be something like this [accurace of the quotation
aside]:

     The Spanish Inquisition has three main weapons: fear, surprise,
     ruthless efficiency, and an almost fanatical devotion to the
     Pope!
     
> Although the bullet list is indented, the header line "Our three weapons
> are" looks like something is missing,

Something is missing.  It's not a complete independent clause.

> as if I had started to write something and forgotten to finish.

Except a colon doesn't "complete" an independent clause that's
otherwise incomplete.

> It needs a colon to be complete:
>
>     Nobody expects the Spanish Inquisition! <JARRING CHORDS>

Now, that usage is correct.

> The colon indicates that the sentence has more to follow: I think of
> it as a pointer.

That is correct also.

> On the other hand, a colon gives the reader that connection:
>
>     It gives the reader a clue to expect additional information, 
>     that the indented block that follows is not an independent 
>     block, floating in space for its own reasons, but is intimately 
>     linked to the previous line.

Yup.

[1] Since all posts criticising grammar or spelling will have an above
    average number of grammar and spelling errors, I thought I'd get
    a head start on it.

-- 
Grant Edwards               grant.b.edwards        Yow! I'm ZIPPY the PINHEAD
                                  at               and I'm totally committed
                              gmail.com            to the festive mode.

[toc] | [prev] | [next] | [standalone]


#9390 — Re: An interesting beginner question: why we need colon at all in the python language?

FromGrant Edwards <invalid@invalid.invalid>
Date2011-07-13 13:03 +0000
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<ivk52q$78p$1@reader1.panix.com>
In reply to#9373
On 2011-07-13, Thorsten Kampe <thorsten@thorstenkampe.de> wrote:

>> and that that block is to be considered in relation to what was just
>> said, before the colon.
>
> The indentation makes it abundantly clear to the human reader that
> that indented block is to be considered in relation to what was just
> said, before the indentation.

You would think so, but human readers like redundancy.

Most natural human languages have plenty of redundancy.  For example
in English when speaking of multiple subjects one not only uses a
plural noun or pronoun (e.g. "they" rather than "him"), but one also
uses a plural verb ("run" rather than "runs") even though the plural
noun alone should make it abundantly clear to the human reader than
we're talking about more than one person.  The same holds true for
objective and subjective case: the position of the noun in the
sentence makes it abundantly clear whether the noun is an object or a
subject, yet we still often have two cases (it's "I run" rather than
"Me run").

-- 
Grant Edwards               grant.b.edwards        Yow! I'm having an
                                  at               EMOTIONAL OUTBURST!!  But,
                              gmail.com            uh, WHY is there a WAFFLE
                                                   in my PAJAMA POCKET??

[toc] | [prev] | [next] | [standalone]


#9391

FromChris Angelico <rosuav@gmail.com>
Date2011-07-13 23:11 +1000
Message-ID<mailman.976.1310562704.1164.python-list@python.org>
In reply to#9390
On Wed, Jul 13, 2011 at 11:03 PM, Grant Edwards <invalid@invalid.invalid> wrote:
> You would think so, but human readers like redundancy.
>

One of the benefits of redundancy is error-trapping. If you see a list
of numbers like this:

   40
   14
   24
   56
   48
   12
   60
   16
=====
  269

then you know the result can't be right, because they're all even
numbers and the total isn't. The redundancy of having both the string
of numbers and the total adds only a small amount to the transmission
requirement, but it adds a lot to the reliability of transfer.

ChrisA

[toc] | [prev] | [next] | [standalone]


#9416 — Re: An interesting beginner question: why we need colon at all in the python language?

FromThorsten Kampe <thorsten@thorstenkampe.de>
Date2011-07-13 19:27 +0200
SubjectRe: An interesting beginner question: why we need colon at all in the python language?
Message-ID<MPG.2887f3d2a785d056989834@news.individual.de>
In reply to#9390
* Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
> On 2011-07-13, Thorsten Kampe <thorsten@thorstenkampe.de> wrote:
> 
> >> and that that block is to be considered in relation to what was just
> >> said, before the colon.
> >
> > The indentation makes it abundantly clear to the human reader that
> > that indented block is to be considered in relation to what was just
> > said, before the indentation.

> You would think so, but human readers like redundancy.

I also like redundancy (and consistency). That's why I'd much more 
prefer a "then" than a colon which is easily overlooked while reading 
/and/ while writing.

Thorsten

[toc] | [prev] | [next] | [standalone]


#9469

FromGrant Edwards <invalid@invalid.invalid>
Date2011-07-14 14:34 +0000
Message-ID<ivmupv$8t6$2@reader1.panix.com>
In reply to#9390
On 2011-07-13, Thorsten Kampe <thorsten@thorstenkampe.de> wrote:
> * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
>> On 2011-07-13, Thorsten Kampe <thorsten@thorstenkampe.de> wrote:
>> 
>> >> and that that block is to be considered in relation to what was just
>> >> said, before the colon.
>> >
>> > The indentation makes it abundantly clear to the human reader that
>> > that indented block is to be considered in relation to what was just
>> > said, before the indentation.
>
>> You would think so, but human readers like redundancy.
>
> I also like redundancy (and consistency). That's why I'd much more 
> prefer a "then" than a colon which is easily overlooked while reading 
> /and/ while writing.

How is the "then" going to be consistent with other things that also
introduce blocks (def, try, with, etc.).

-- 
Grant Edwards               grant.b.edwards        Yow! !  I'm in a very
                                  at               clever and adorable INSANE
                              gmail.com            ASYLUM!!

[toc] | [prev] | [next] | [standalone]


#9474

FromWanderer <wanderer@dialup4less.com>
Date2011-07-14 08:14 -0700
Message-ID<147a626f-21e0-42f6-a939-50d0ee1e0303@g16g2000yqg.googlegroups.com>
In reply to#9469
On Jul 14, 10:34 am, Grant Edwards <inva...@invalid.invalid> wrote:
> On 2011-07-13, Thorsten Kampe <thors...@thorstenkampe.de> wrote:
>
> > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
> >> On 2011-07-13, Thorsten Kampe <thors...@thorstenkampe.de> wrote:
>
> >> >> and that that block is to be considered in relation to what was just
> >> >> said, before the colon.
>
> >> > The indentation makes it abundantly clear to the human reader that
> >> > that indented block is to be considered in relation to what was just
> >> > said, before the indentation.
>
> >> You would think so, but human readers like redundancy.
>
> > I also like redundancy (and consistency). That's why I'd much more
> > prefer a "then" than a colon which is easily overlooked while reading
> > /and/ while writing.
>
> How is the "then" going to be consistent with other things that also
> introduce blocks (def, try, with, etc.).
>
> --
> Grant Edwards               grant.b.edwards        Yow! !  I'm in a very
>                                   at               clever and adorable INSANE
>                               gmail.com            ASYLUM!!

But if you have the colon, why do you need the brackets or backslashes
in an if statement.

Why not

if condition1 or
   condition2 or
   condition3:
    do_something()

The statement ain't over til there's a colon.

[toc] | [prev] | [next] | [standalone]


#9595

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-07-16 14:07 +1000
Message-ID<4e210e9b$0$29995$c3e8da3$5496439d@news.astraweb.com>
In reply to#9474
Wanderer wrote:

> But if you have the colon, why do you need the brackets or backslashes
> in an if statement.
> 
> Why not
> 
> if condition1 or
>    condition2 or
>    condition3:
>     do_something()
> 
> The statement ain't over til there's a colon.


Because there are virtues in having the parser be nice and simple. Syntax
constraints help identify errors:

mystr = "this is a string

Should we say that no closing quote is needed, because the newline
unambiguously ends the string? Well, perhaps... but allowing such a rule
would mask errors:

mystr = "this is a %s % type(something)

Good language design requires constraints on what is allowed as well as
freedom from unnecessary syntax. 

The appropriate lines from the Zen are

Errors should never pass silently.
Unless explicitly silenced.

Newlines end parsing of the current token or expression. Including a newline
inside an expression is an error, unless you explicitly silence it by using
a backslash or using brackets. It's a bit too far to say that "any if
statement is an explicit way to silent newline errors".



-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web