Indentation problem

Gilles Diribarne gdiribarne at udcast.com
Mon Mar 25 08:16:49 EST 2002


Hi,

I like Python language and use it every day. But...
I read some articles from October, 1998 where there was a fight with 
space and tabs and indent problems.
Today, we can found code with spaces and tabs in the code.

I've some problem with identing code. I'm allright with the example.
But, I think it's important to have an "end" building block like "!:"

What do you think about that?

Why I would like to put this in the code?
1/ Because it's almost impossible to paste python code with ident = n 
spaces to another code with indent = m spaces
This kind of examples occurs more and more and you can indent the code 
by hand when it's 10 lines of codes, but not 1000 code lines.
It prevents the re-use of code pieces.

2/ Programmers wants independence: some wants to manage building blocks 
with spaces, other with tabs, some wants length = 4 with tabs.
I would like to use my own programming style! But, my code risks to be 
not supported by others.

2/ Emacs and a great number of editors cannot indent region, since the 
building blocks are only in programmer's mind.

3/ A large number of programming language use this. C, PERL, Ruby, ...
Why not Python?

4/ Solve the problem of space and tabs length. But, we should keep the 
indenting mode which produces beautifull syntax.
pythona.py:
  def func():
    a = 1
    if a == 1:
      a ==2
      print "beatifull! Isn't it?"

5/ This kind of separator should be optional ???
So, don't change the current library. It will be very easy to adapt old 
code with this kind of separator.
A parser could be provided to re-adapt the old code !!!

EXAMPLE:

pythona.py:
  def func():
    a = 1
    if a == 1:
      a ==2



pythonb.py
    def func2():
        a = 2
        if a == 2:
             print "Yeah!"


You cannot merge correctly or tell me how to do this ?
This is simply because the language doesn't have a "end" instruction 
block. It has ":" as beginning instruation block.
I would like to propose an end instruction block like "!:" or "end"

pythona.py:
  def func():
    a = 1
    if a == 1:
      a ==2
    !:
  !:

pythonb.py
    def func2():
        a = 2
        if a == 2:
             print "Yeah!"
        !:
     !:


Now, with your favorite emacs, you can indent two portions of code very 
easily.

  def func():
    a = 1
    if a == 1:
      a ==2
    !:
  !:

  def func2():
    a = 2
    if a == 2:
      print "Yeah!"
    !:
  !:


Gilles,
Python programmer





More information about the Python-list mailing list