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


Groups > comp.lang.python > #9384

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

From Thorsten Kampe <thorsten@thorstenkampe.de>
Newsgroups comp.lang.python
Subject Re: An interesting beginner question: why we need colon at all in the python language?
Date 2011-07-13 13:26 +0200
Message-ID <MPG.28879f471300a74a989833@news.individual.de> (permalink)
References <CAAyd8ckM7WqzTpXzVFFocEFQcm8oeHPQGAv1KH6BcBj6kqA2WA@mail.gmail.com> <mailman.889.1310393783.1164.python-list@python.org> <MPG.288770fad6930dba989832@news.individual.de> <4e1d7c66$0$30000$c3e8da3$5496439d@news.astraweb.com>

Show all headers | View raw


* 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web