Indentation problem

brueckd at tbye.com brueckd at tbye.com
Mon Mar 25 11:11:21 EST 2002


On Mon, 25 Mar 2002, Gilles Diribarne wrote:

> 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?

Rather than changing the language, get a smarter code editor. The current
way works very well for lots of people.

> 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

How much code pasting do you do? It's common to do some, but 99% of it
will probably be your own code, in which case you'll have the same number
of spaces. Pasting in large blocks of other peoples' code is kinda scary
anyway.

> 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.

This is sounding more and more like a hypothetical corner case and not a
real problem you're encountering every day. I'd stick the 1000 lines in
its own module anyway.

> It prevents the re-use of code pieces.

Copy/paste is one of the lowest and worst forms of code reuse - try
reusing modules instead if you can.

> 2/ Programmers wants independence: some wants to manage building blocks
> with spaces, other with tabs, some wants length = 4 with tabs.

Um, isn't this the problem you're complaining about? ;-) Seriously though,
I'd always be willing to give up an insignificant amount of independence
if it bought me fewer code headaches and more consistency. Just set a
coding standard for your organization and the "problem" evaporates.

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

??? Are there any Python editors that do _not_ have this? I don't know of
any...

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

Because Python isn't broken? Herd mentality and peer pressure are always
poor reasons for doing anything.

> 4/ Solve the problem of space and tabs length. But, we should keep the
> indenting mode which produces beautifull syntax.

Going back to the start of this post, I think the source of your pain has
less to do with block delimiters and more to do with choice of editor
and/or your approach to code reuse. Please don't think I'm trying to be
rude, but if you're encountering this problem a lot then you're doing
something wrong.

-Dave





More information about the Python-list mailing list