Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: An interesting beginner question: why we need colon at all inthe python language?

Reply
Thread Tools

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

 
 
Grant Edwards
Guest
Posts: n/a
 
      07-13-2011
On 2011-07-13, Steven D'Aprano <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      07-13-2011
On 7/13/2011 2:26 AM, alex23 wrote:
> Thomas Jollans<(E-Mail Removed)> 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/2...indentation-an...

>
> It's also part of the Python FAQ:
>
> http://docs.python.org/faq/design.ht...ass-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

 
Reply With Quote
 
 
 
 
Thorsten Kampe
Guest
Posts: n/a
 
      07-13-2011
* Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
> On 2011-07-13, Thorsten Kampe <(E-Mail Removed)> 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
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      07-14-2011
On 2011-07-13, Thorsten Kampe <(E-Mail Removed)> wrote:
> * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
>> On 2011-07-13, Thorsten Kampe <(E-Mail Removed)> 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!!
 
Reply With Quote
 
Wanderer
Guest
Posts: n/a
 
      07-14-2011
On Jul 14, 10:34*am, Grant Edwards <(E-Mail Removed)> wrote:
> On 2011-07-13, Thorsten Kampe <(E-Mail Removed)> wrote:
>
> > * Grant Edwards (Wed, 13 Jul 2011 13:03:22 +0000 (UTC))
> >> On 2011-07-13, Thorsten Kampe <(E-Mail Removed)> 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.


 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      07-16-2011
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= ASP .Net 7 02-03-2005 02:47 PM
Unable to open web project. A rogue colon ':' is appearing in the =?Utf-8?B?Z3JlZyBz?= ASP .Net 1 01-18-2005 07:58 PM
regex: colon screwing up my pattern? Darrel ASP .Net 0 12-28-2004 12:56 PM



Advertisments