FAQ
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!

Is there any other reasons for use of semi-colon in python?


Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110711/ff993d5d/attachment.html>

Search Discussions

  • Thomas Jollans at Jul 11, 2011 at 2:16 pm

    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
  • Anthony Kong at Jul 11, 2011 at 2:23 pm
    Awesome! Thanks for blog post link

    Cheers
    On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans 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. 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

    --
    http://mail.python.org/mailman/listinfo/python-list


    --
    /*--*/
    Don?t EVER make the mistake that you can design something better than what
    you get from ruthless massively parallel trial-and-error with a feedback
    cycle. That?s giving your intelligence _much_ too much credit.

    - Linus Torvalds
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110712/34ddd68c/attachment.html>
  • Sébastien Volle at Jul 11, 2011 at 2:50 pm
    Could it have been made optional, like the trailing comma in list
    declaration?

    --
    Seb

    2011/7/11 Anthony Kong <anthony.hw.kong at gmail.com>
    Awesome! Thanks for blog post link

    Cheers

    On Tue, Jul 12, 2011 at 12:16 AM, Thomas Jollans 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. 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

    --
    http://mail.python.org/mailman/listinfo/python-list


    --
    /*--*/
    Don?t EVER make the mistake that you can design something better than what
    you get from ruthless massively parallel trial-and-error with a feedback
    cycle. That?s giving your intelligence _much_ too much credit.

    - Linus Torvalds



    --
    http://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110711/1a714640/attachment.html>
  • Ian Kelly at Jul 11, 2011 at 3:28 pm

    On Mon, Jul 11, 2011 at 8:50 AM, S?bastien Volle wrote:
    Could it have been made optional, like the trailing comma in list
    declaration?
    Cobra makes the colons optional, so probably yes.
  • Dan Stromberg at Jul 11, 2011 at 11:35 pm

    On Mon, Jul 11, 2011 at 8:28 AM, Ian Kelly wrote:

    On Mon, Jul 11, 2011 at 8:50 AM, S?bastien Volle
    wrote:
    Could it have been made optional, like the trailing comma in list
    declaration?
    Cobra makes the colons optional, so probably yes.
    --
    http://mail.python.org/mailman/listinfo/python-list
    A little redundancy in a computer language facilitates error checking - much
    like the bits of redundancy in one's English make written and voice
    communication less error prone.

    But strictly speaking, the colon could've been left out.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110711/166d991d/attachment-0001.html>
  • Dave Angel at Jul 11, 2011 at 2:36 pm

    On 01/-10/-28163 02:59 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!

    Is there any other reasons for use of semi-colon in python?


    Cheers
    You're confusing the colon with the semi-colon. If you want two
    statements on the same line, you use a semi-colon.

    The character you're asking about is the colon. It goes at the end of
    an if, else, for, with, while statement. I doubt it's absolutely
    essential, but it helps readability, since a conditional expression
    might span multiple lines.
    if someexpression ==
    someotherexpression:
    body_of_the_conditional

    DaveA
  • Thomas Jollans at Jul 11, 2011 at 3:01 pm

    On 07/11/2011 04:36 PM, Dave Angel wrote:
    The character you're asking about is the colon. It goes at the end of
    an if, else, for, with, while statement. I doubt it's absolutely
    essential, but it helps readability, since a conditional expression
    might span multiple lines.
    if someexpression ==
    someotherexpression:
    body_of_the_conditional
    That, of course, is not legal Python. Your point stands when you add
    brackets or a backslash to hold the condition together.
  • Anthony Kong at Jul 11, 2011 at 3:10 pm
    Sorry, typo in my original question. I do mean 'colon'. It should have read

    *If Python use indentation to denote scope, why it still needs colon at the
    end of function declaration and for/while/if loop?*

    Thanks

    On Tue, Jul 12, 2011 at 12:36 AM, Dave Angel wrote:
    On 01/-10/-28163 02:59 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!

    Is there any other reasons for use of semi-colon in python?


    Cheers

    You're confusing the colon with the semi-colon. If you want two
    statements on the same line, you use a semi-colon.

    The character you're asking about is the colon. It goes at the end of an
    if, else, for, with, while statement. I doubt it's absolutely essential,
    but it helps readability, since a conditional expression might span multiple
    lines.
    if someexpression ==
    someotherexpression:
    body_of_the_conditional

    DaveA

    --
    /*--*/
    Don?t EVER make the mistake that you can design something better than what
    you get from ruthless massively parallel trial-and-error with a feedback
    cycle. That?s giving your intelligence _much_ too much credit.

    - Linus Torvalds
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110712/204cfcd7/attachment-0001.html>
  • Grant Edwards at Jul 11, 2011 at 2:43 pm

    On 2011-07-11, Thomas Jollans 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
  • Alex23 at Jul 13, 2011 at 6:26 am

    Thomas Jollans 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
  • Terry Reedy at Jul 13, 2011 at 4:18 pm

    On 7/13/2011 2:26 AM, alex23 wrote:
    Thomas Jollanswrote:
    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
  • Thorsten Kampe at Jul 13, 2011 at 7:36 am
    * Dave Angel (Mon, 11 Jul 2011 10:36:48 -0400)
    On 01/-10/-28163 02:59 PM, Anthony Kong wrote:
    My immediate response is: it allows us to fit statements into one
    line. e.g.
    if a == 1: print a
    You're confusing the colon with the semi-colon. If you want two
    statements on the same line, you use a semi-colon.
    He's not confusing anything at all. His example made it pretty clear
    that he didn't mean "two statements" but "multiline statemements".

    Thorsten
  • Anthony Kong at Jul 13, 2011 at 10:40 am
    Thanks, mate! I was writing that up really late at night. Somehow I changed
    term to semi-colon half way through,

    Cheers

    On Wed, Jul 13, 2011 at 5:36 PM, Thorsten Kampe
    wrote:
    * Dave Angel (Mon, 11 Jul 2011 10:36:48 -0400)
    On 01/-10/-28163 02:59 PM, Anthony Kong wrote:
    My immediate response is: it allows us to fit statements into one
    line. e.g.
    if a == 1: print a
    You're confusing the colon with the semi-colon. If you want two
    statements on the same line, you use a semi-colon.
    He's not confusing anything at all. His example made it pretty clear
    that he didn't mean "two statements" but "multiline statemements".

    Thorsten
    --
    http://mail.python.org/mailman/listinfo/python-list


    --

    Tony Kong
    *blog:* www.ahwkong.com

    Don?t EVER make the mistake that you can design something better than what
    you get from ruthless massively parallel trial-and-error with a feedback
    cycle. That?s giving your intelligence *much* too much credit.


    - Linus Torvalds
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110713/e520efbe/attachment.html>
  • Thorsten Kampe at Jul 13, 2011 at 8:08 am
    * 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
  • Steven D'Aprano at Jul 13, 2011 at 11:07 am

    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
  • Thorsten Kampe at Jul 13, 2011 at 11:26 am
    * 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
  • Tim Chase at Jul 13, 2011 at 12:16 pm

    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
  • Chris Angelico at Jul 13, 2011 at 11:58 am

    On Wed, Jul 13, 2011 at 9:07 PM, Steven D'Aprano 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
  • Grant Edwards at Jul 13, 2011 at 1:18 pm

    On 2011-07-13, Steven D'Aprano 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.
  • Grant Edwards at Jul 13, 2011 at 1:03 pm

    On 2011-07-13, Thorsten Kampe 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??
  • Chris Angelico at Jul 13, 2011 at 1:11 pm

    On Wed, Jul 13, 2011 at 11:03 PM, Grant Edwards 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
  • Thorsten Kampe at Jul 13, 2011 at 5:27 pm
    * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
    On 2011-07-13, Thorsten Kampe 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
  • Grant Edwards at Jul 14, 2011 at 2:34 pm

    On 2011-07-13, Thorsten Kampe wrote:
    * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
    On 2011-07-13, Thorsten Kampe 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!!
  • Wanderer at Jul 14, 2011 at 3:14 pm

    On Jul 14, 10:34?am, Grant Edwards wrote:
    On 2011-07-13, Thorsten Kampe wrote:

    * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
    On 2011-07-13, Thorsten Kampe 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.
  • Steven D'Aprano at Jul 16, 2011 at 4:07 am

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 11, '11 at 1:51p
activeJul 16, '11 at 4:07a
posts26
users14
websitepython.org

People

Translate

site design / logo © 2022 Grokbase