POV-Ray : Newsgroups : povray.off-topic : All bow to the mighty Python : Re: All bow to the mighty Python Server Time
4 Sep 2024 19:19:52 EDT (-0400)
  Re: All bow to the mighty Python  
From: Darren New
Date: 21 Apr 2010 13:25:00
Message: <4bcf34ec$1@news.povray.org>
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> If existing lines are indented incorrectly, then your code is broken. The 
>> reason that "auto indenting" is not possible in Python is the same reason 
>> that "auto bracing" isn't possible in C.
> 
>   Actually, I can't think why "auto-bracing" wouldn't be possible in C,
> at least if you don't mind having braces even around single-statement blocks
> (something which many programming guides actually recommend).

This is why:  Take all the braces out of a C program. Now put them back in 
the right place.  That's what you're asking.

Distinguish between "indent Python not knowing how much it should be 
indented" and "indent changing python when the program is already correctly 
indented so far."

Your editor can indent when necessary, and unindent with a keystroke, as you 
type. This is the equivalent of your "you write a statement which is 
followed by a code block" statement. Cut and paste can automatically put 
things as the right indent level (with a python-aware editor, of course). Etc.

Statements that should be aligned that aren't can be fixed. If you have four 
lines under your "if" with slightly varying indents but all indented 
relative to the "if", then this is trivial to fix. (Python might already be 
happy with that one, actually.)

The only failure is when you have something that should be indented relative 
to a line above it somewhere but it isn't. This is precisely analogous to 
having the wrong number of closing braces. Asking for this to be fixed 
automatically is identical to asking for C code with too many closing braces 
to get fixed automatically. You can't do it, because you don't know how 
indented it is *supposed* to be, just like you don't know which closing 
brace is the one that ought be removed.  (I'm sure you've encountered this 
at least once. :-)

Indeed, I wouldn't be surprised if it was trivial to program a python editor 
that } at the start of a line translates to a dedent. :-)

>   Every time you write a statement which is followed by a code block (even
> if it's an empty one in rare cases), such as a for-loop, the editor could
> automatically add the '{' and '}' characters and indent the code such that
> you can just keep typing the contents of the loop.

Lots of HTML editors do this too.

>   A lesser variation of that would be that every time you write a '{' the
> editor automatically adds (and indents) a '}'. The editor could actually
> constantly keep matching braces auto-indented, even if one of the pair is
> changed somehow (most editors, including emacs, can highlight matching
> braces, so it shouldn't be a problem to auto-indent them as well).

Yep. Visual Studio does this.

Python doesn't need to. ;-)

-- 
Darren New, San Diego CA, USA (PST)
   Linux: Now bringing the quality and usability of
   open source desktop apps to your personal electronics.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.