Allowing Arbitrary Indentation in Python

Sam L33tminion at gmail.com
Tue Dec 18 19:11:46 EST 2007


On Dec 18, 5:28 pm, Grant Edwards <gra... at visi.com> wrote:
> On 2007-12-18, Sam <L33tmin... at gmail.com> wrote:
>
>
>
> > A friend of mine is picking up some Python and is frustrated by
> > Python's indentation rules (http://greatbiggary.livejournal.com/
> > 260460.html?thread=1835884#t1835884).  Personally, I've never had any
> > issues with Python's ways of indentation, but that conversation got me
> > thinking about the issue.
>
> > Consider the following indentation rules:
> > 1. Blocks begin with a line ending in ":"
> > 2. A line on the same indentation level or lower ends a block.
>
> > Under those rules, this would work:
> > layouts = ['column', 'form', 'frame']
> > cmds.window(t='gwfUI Builder')
> > cmds.paneLayout(configuration='vertical3', ps=((1, 25, 100), (3, 20,
> > 100)))
> >     cmds.paneLayout(configuration='horizontal2')
> >         cmds.frameLayout(l='Layouts')
> >             cmds.scrollLayout(cr=True)
> >                 cmds.columnLayout(adj=True, cat=('both', 2))
> >                     for i in layouts:
> >                    cmds.button(l=i)
> >                 cmds.setParent('..')
> >             cmds.setParent('..')
> >         cmds.setParent('..')
> >     cmds.setParent('..')
> > cmds.setParent('..')
> > cmds.showWindow()
>
> And you think that example is an argument in _favor_ of what
> you propose?
>
> > Do such rules make sense?
>
> IMO, no.
>
> > Is there any way to make code work that way in Python?
>
> no.
>
> > Should there be?
>
> God no.
>
> Code should work the way it looks and look the way it works.
> Changing the language in order to allow authors to mislead
> readers is a bad thing.
>
> > Does that make this sort of code more or less readable?
>
> You must be joking.
>
> --
> Grant Edwards                   grante             Yow! I joined scientology
>                                   at               at a garage sale!!
>                                visi.com

Well, using tabs to lay out GUI elements in a hierarchy is something
I've seen before in other programming languages, so it seems that
_some_ people would find that more readable.  Admittedly, I don't find
the oddly tabbed code easier to read (it strikes me as about the same
level of readability).  The code provided as an example of some non-
Python language being "more readable" (also in the post I linked to)
struck me as far less readable, but I assumed that was only because I
didn't know the language in question.

The question that interests me more is how much power Python
programmers have to alter how the compiler deals with indentation and
so on (within Python, without altering the source code of the compiler
itself or something like that).  I couldn't find anything that
indicated that such power exists, but I'm still relatively new to
Python, so I thought that someone on CLP might have a more decisive
answer.

Anyways, thanks for your reply.



More information about the Python-list mailing list