Differences between revisions 1 and 8 (spanning 7 versions)
Revision 1 as of 2008-08-12 05:18:59
Size: 389
Editor: 219
Comment:
Revision 8 as of 2009-04-05 23:45:26
Size: 2344
Editor: 99-51-74-201
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
SEE:'''[wiki:Ten_things_people_want_to_know_about_Python Ten things people want to know about Python]''' SEE:'''[[Ten things people want to know about Python|Ten things people want to know about Python]]'''
Line 4: Line 4:
  * You're going to indent your code even if your language uses brackets or other start/end separators, if you want it to be readable and understandable. Extra notation beyond what we should be doing regardless of the language doesn't add anything, except for clutter.   * In order to separate blocks of code (like for loops, if blocks and function definitions) the compiler / interpreter needs something to tell it when a block ends. Curly braces and end statements are perfectly valid ways of providing this information for the compiler. For a human to be able to read the code indentation is a much better way of providing the visual cues about block structure. As indentation also contains all the information for the compiler, to use both would be redundant. As indentation is better for humans, it makes sense to use that for the compiler too. It has the advantage that Python programs tend to be uniformly and consistently indented, removing one hurdle to understanding other people's code. Python does not mandate how you indent (two spaces or four, tabs or spaces - but not both), just that you do it consistently. Those that get used to the Python way of doing things tend to start seeing curly braces as unnecessary line noise that clutters code. On the other hand, [['the whitespace thing']] is possibly the single biggest reason why some developers refuse to even try Python.

[Folklore says that the [[ABC]]ers in the '80s experimentally determined that significant
whitespace has measurable advantages. 'Anyone have documentation for this?]

Additional observation::
  * Among programmers using languages which ignore white space the prevailing conventions are to indent blocks of code to facilitate readability by humans. The exact details of such conventions vary (and are subject to considerable stylistic debate among some programmers). But the general features are ubiquitous, nearly universal: code is rendered mostly in an "outline" format ... with levels of lexical nesting denoted by increasing degrees of indentation. Python merely uses this (nearly universal) convention as part of its syntax which allows it to dispense with other block ending tokens. Some argue that this syntax helps avoid situations where the code doesn't match the apparent intent (when the indentation is subtly inconsistent with the lexical structure). As with the finer points of how code should be indented in white space agnostica languages, that is a point of endless discussion.

SEE:Ten things people want to know about Python

Answer
  • In order to separate blocks of code (like for loops, if blocks and function definitions) the compiler / interpreter needs something to tell it when a block ends. Curly braces and end statements are perfectly valid ways of providing this information for the compiler. For a human to be able to read the code indentation is a much better way of providing the visual cues about block structure. As indentation also contains all the information for the compiler, to use both would be redundant. As indentation is better for humans, it makes sense to use that for the compiler too. It has the advantage that Python programs tend to be uniformly and consistently indented, removing one hurdle to understanding other people's code. Python does not mandate how you indent (two spaces or four, tabs or spaces - but not both), just that you do it consistently. Those that get used to the Python way of doing things tend to start seeing curly braces as unnecessary line noise that clutters code. On the other hand, 'the whitespace thing' is possibly the single biggest reason why some developers refuse to even try Python.

[Folklore says that the ABCers in the '80s experimentally determined that significant whitespace has measurable advantages. 'Anyone have documentation for this?]

Additional observation::

  • Among programmers using languages which ignore white space the prevailing conventions are to indent blocks of code to facilitate readability by humans. The exact details of such conventions vary (and are subject to considerable stylistic debate among some programmers). But the general features are ubiquitous, nearly universal: code is rendered mostly in an "outline" format ... with levels of lexical nesting denoted by increasing degrees of indentation. Python merely uses this (nearly universal) convention as part of its syntax which allows it to dispense with other block ending tokens. Some argue that this syntax helps avoid situations where the code doesn't match the apparent intent (when the indentation is subtly inconsistent with the lexical structure). As with the finer points of how code should be indented in white space agnostica languages, that is a point of endless discussion.

Why separate sections by indentation instead of by brackets or 'end' (last edited 2009-04-05 23:45:26 by 99-51-74-201)

Unable to edit the page? See the FrontPage for instructions.