Python indentation
Dan Bishop
danb_83 at yahoo.com
Wed Jul 7 17:03:49 EDT 2004
Grant Edwards <grante at visi.com> wrote in message news:<slrncentbi.ak.grante at grante.rivatek.com>...
> On 2004-07-07, Reinhold Birkenfeld <reinhold-birkenfeld-nospam at wolke7.net> wrote:
>
> >> I am a beginner in Python, and am wondering what is it about
> >> the indentation in Python, without which python scripts do not
> >> work properly. Why can't the indentation not so strict so as
> >> to give better freedom to the user? Is there any plausible
> >> reason behind this?
> >
> > Yes. It's about readability.
> >
> > In many languages, such as C or Perl, you can write readable code, but
> > you can also squeeze your code in as few lines as possible, resulting in
> > hard to read, hard to maintain, hard to debug code[1]. Whenever I
> > translate a Perl script into Python, I end up with about 25-40% more
> > lines, but the script is much more readable than the Perl counterpart
> > (mostly, of course, because of the lacking $'s ;).
>
> Compare C and Python:
>
> In C, we have 10 lines [compared to 6 in Python]
>
> if (condition)
> {
> doThis();
> doThat();
> }
> else
> {
> doWhatever();
> andSoOn();
> }
Only because you're using an inefficient brace style.
The style I use writes it as:
if (condition) {
doThis();
doThat();
} else {
doWhatever();
andSoOn();
}
which is 7 lines, only 1 more than the Python version.
But this does demonstrate an advantage of Python: No arguments over
where to put braces :-)
More information about the Python-list
mailing list