A Suggestion for Python Colon Syntax

D-Man dsh8290 at rit.edu
Fri Dec 22 14:19:55 EST 2000


On Fri, Dec 22, 2000 at 06:42:11PM +0000, William Djaja Tjokroaminata wrote:

<snip>

> Exactly.  I just regretted the initial study that used newbies and they
> preferred colons.  At the present time, correct me if I am wrong, I think
> it is still rare that Python is one's first programming language.  

I think you are right,  most people have never heard of Python.  It's
really too bad because python is such a nice language and much easier
to learn as a first language than many others.


> I am not too familiar with the parsing stuff.  However, in my simplistic
> opinion, Python is not a free-form language like C or Perl.  Therefore,
> probably it is reasonable for any parser to breaks a Python code first
> into lines, even in backward parsing, instead of parsing it token by
> token first.  In parsing backwards, can then it just detect first that the
> line is at different indentation level rather than try to detect the
> colon?

If the parser (I believe you are referring to someone's emacs mode
thing) used the indentation level to infer the structure, it would
totally defeat the purpose.  The purpose of that parser is with the
following input:

if 1 :<enter>print "hello"

To give the following result in the editor:

if 1:
	print "hello"


I use vim myself and rather like this feature in C/C++/Java modes.  It
also handles the unindent when a } is typed.


I for one rather like having the colon and I have more experience
using C++, C, and Java than Python.

-D

BTW, A python mode for vim would be a very cool thing.  I also have a
habit of using a comment to identify the end of blocks (so it is
obvious what the brace is for). 

Ex in C I would write :

	if ( cond )
	{
	} /* if */

In C++/Java I use:
	if ( cond )
	{
	} // if

In Python I write:
	if ( cond) :
		pass
	# end if


It would be cool if the editor would recognize the "# end" like it
currently does for "}"




More information about the Python-list mailing list