Python Quiz

Discussion in 'Python' started by Michael Chermside, Jul 16, 2003.

  1. richardc writes:
    > Im no expert but wouldnt you accept that Python has 'borrowed' FORTRAN's
    > fixed format syntax. I can only think of Python and FORTRAN off the top of
    > my head which use whitespace as part of the syntax.


    Definitely NOT. Without addressing the question of HOW Python came by the
    idea of using indentation to indicate block structure, it clearly couldn't
    have been from Fortran, because what Python does and what Fortran does
    are COMPLETELY different.

    In Fortran, starting lines in particular columns is meaningful (as are other
    particular characters in particular leading columns). In Python, particular
    columns have NO meaning. In fact, I would venture to say that it is
    NOT whitespace that is "significant" in Python... it's INDENTATION. The
    distinction is significant, because humans are very poor at reading
    whitespace (the presense or absence of it yes, but the amount is something
    we're not good at reading), but we find indentation to be a *very* readable
    way to mark block structure (in practically every language which doesn't
    (like Fortran) prohibit indentation, it is a convention adhered to
    universally ).

    There's also the fact that "lines" (statements) are defined by line breaks
    in Python -- but I rarely hear complaints about this, since most programmers
    mentally chunk up code into "lines" anyway.

    Of course, I'm not suggesting that whitespace is *meaningless* in Python
    outside of indentation... Python is much like C (and many, many others) in
    that regard. After all, in C "y=x+ ++z" and "y=x++ +z" are quite
    different things. And in both Python and C "x=abc" is legal, but "x=a bc"
    is not.

    So I would say MOST languages make the presence or absence of whitespace
    significant... and that's a good idea, since it helps humans "tokenize"
    the code they read. Python uses newlines to indicate where new "lines"
    (statements) begin... not usually a controversial convention. Finally,
    most PROGRAMMERS use indentation to indicate block structure, but Python
    differs from most languages in that the Python parser uses the indentation
    level as syntax for blocks, while most languages don't. And Python
    doesn't[1] care about the AMOUNT of white space (independent of indentation
    level) which is a good thing, because humans find that difficult to
    read.

    -- Michael Chermside

    [1] Unless you mix tabs and spaces. Don't do that. Use tabnanny if you
    need to.
     
    Michael Chermside, Jul 16, 2003
    #1
    1. Advertising

  2. Michael Chermside

    Mark Jackson Guest

    Michael Chermside <> writes:
    > richardc writes:
    > > Im no expert but wouldnt you accept that Python has 'borrowed' FORTRAN's
    > > fixed format syntax. I can only think of Python and FORTRAN off the top of
    > > my head which use whitespace as part of the syntax.

    >
    > Definitely NOT. Without addressing the question of HOW Python came by the
    > idea of using indentation to indicate block structure, it clearly couldn't
    > have been from Fortran, because what Python does and what Fortran does
    > are COMPLETELY different.
    >
    > In Fortran, starting lines in particular columns is meaningful (as are other
    > particular characters in particular leading columns). In Python, particular
    > columns have NO meaning.


    > Of course, I'm not suggesting that whitespace is *meaningless* in Python
    > outside of indentation... Python is much like C (and many, many others) in
    > that regard. After all, in C "y=x+ ++z" and "y=x++ +z" are quite
    > different things. And in both Python and C "x=abc" is legal, but "x=a bc"
    > is not.


    Note that Fortran (at least historic Fortran - not sure about those
    upstart 9x variants) is *not* among the "many, many others." One can
    write any of

    DO 10 I = something
    DO10I = something
    D O 1 0 I = something

    and leave it to the compiler to figure out whether you're starting a
    DO-loop or assigning a value to the variable DO10I.

    [Signature from February 1993.]

    --
    Mark Jackson - http://www.alumni.caltech.edu/~mjackson
    Consistently separating words by spaces became a general custom
    about the tenth century A.D., and lasted until about 1957, when
    FORTRAN abandoned the practice.
    - Sun FORTRAN Reference Manual
     
    Mark Jackson, Jul 16, 2003
    #2
    1. Advertising

  3. Michael Chermside

    richardc Guest

    Sorry, I didnt mean to suggest for a second that Python's use of indentation
    (ws), is a problem or in any way a labour of love like FORTRAN's.



    "Michael Chermside" <> wrote in message
    news:...
    SNIP
    > Definitely NOT. Without addressing the question of HOW Python came by the
    > idea of using indentation to indicate block structure, it clearly couldn't
    > have been from Fortran, because what Python does and what Fortran does
    > are COMPLETELY different.


    Very true, but to say that FORTRAN and Python have nothing in common would
    also be untrue. They both use ws to delimit syntatic elements, not the same
    elements but use it in a very different way to most other languages.

    I admit that Python probley gained no insiration from FORTRAN and any
    'similarities' are coincidental.

    > There's also the fact that "lines" (statements) are defined by line breaks
    > in Python -- but I rarely hear complaints about this, since most

    programmers
    > mentally chunk up code into "lines" anyway.


    No complaints there

    > Of course, I'm not suggesting that whitespace is *meaningless* in Python
    > outside of indentation...


    should hope not

    Please dont misinterprit my post as an attack on Python, whilst Im a old-hat
    C++ programmer and first time I looked at Pythno I thought... urggh, no
    brackets thats horrid. After a bit better look, I love it. Like everything
    it has its place.

    Sorry if I upset anyone... I know FORTRAN's bad, but its not that bad...
    erm, actually mabe it is ?

    As for OCCAM, I havent programmed in that for years, that was fun *lost in
    fond memories*

    Rich
     
    richardc, Jul 16, 2003
    #3
  4. Michael Chermside

    Peter Hansen Guest

    Mark Jackson wrote:
    >
    > Michael Chermside <> writes:
    > > Of course, I'm not suggesting that whitespace is *meaningless* in Python
    > > outside of indentation... Python is much like C (and many, many others) in
    > > that regard.

    >
    > Note that Fortran (at least historic Fortran - not sure about those
    > upstart 9x variants) is *not* among the "many, many others." One can
    > write any of
    >
    > DO 10 I = something
    > DO10I = something
    > D O 1 0 I = something
    >
    > and leave it to the compiler to figure out whether you're starting a
    > DO-loop or assigning a value to the variable DO10I.


    If you are saying that you leave it up to the compiler to decide how
    to interpret any of the three above statements, then clearly whitespace
    is *not* meaningless. It might be compiler-dependent or something,
    but no meaningless. Unless you are saying that on a given FORTRAN
    compiler, only one possible interpretation of all three statements
    above is possible. That would be surprising.

    -Peter
     
    Peter Hansen, Jul 16, 2003
    #4
  5. In article <>, Peter Hansen wrote:

    >>> Of course, I'm not suggesting that whitespace is *meaningless*
    >>> in Python outside of indentation... Python is much like C (and
    >>> many, many others) in that regard.

    >>
    >> Note that Fortran (at least historic Fortran - not sure about
    >> those upstart 9x variants) is *not* among the "many, many
    >> others." One can write any of
    >>
    >> DO 10 I = something
    >> DO10I = something
    >> D O 1 0 I = something
    >>
    >> and leave it to the compiler to figure out whether you're
    >> starting a DO-loop or assigning a value to the variable DO10I.

    >
    > If you are saying that you leave it up to the compiler to
    > decide how to interpret any of the three above statements, then
    > clearly whitespace is *not* meaningless.


    IIRC (it's been a _long_ time) it's not up to the compiler. All
    three of the above are required to be treated the same by the
    compiler (a DO loop).

    > It might be compiler-dependent or something, but no
    > meaningless. Unless you are saying that on a given FORTRAN
    > compiler, only one possible interpretation of all three
    > statements above is possible.


    I don't think it's "on a given FORTRAN compiler", I think it's
    more like "according to the language definition for FORTRAN IV".

    > That would be surprising.


    Yup. I found a lot of things in FORTRAN surprising. Python is
    so much nicer in that respect. Though I was recently surprised
    that the remove() method for lists uses "==" and not "is" to
    determine what to remove. It's documented that it works that
    way. But, it wasn't what I excpected, and it took me a while to
    figure out that it was using my class's __cmp__ method rather
    than the object ID.

    --
    Grant Edwards grante Yow! Go on, EMOTE! I
    at was RAISED on thought
    visi.com balloons!!
     
    Grant Edwards, Jul 16, 2003
    #5
  6. Michael Chermside

    Mark Jackson Guest

    Peter Hansen <> writes:
    > Mark Jackson wrote:
    > >
    > > Michael Chermside <> writes:
    > > > Of course, I'm not suggesting that whitespace is *meaningless* in Python
    > > > outside of indentation... Python is much like C (and many, many others) in
    > > > that regard.

    > >
    > > Note that Fortran (at least historic Fortran - not sure about those
    > > upstart 9x variants) is *not* among the "many, many others." One can
    > > write any of
    > >
    > > DO 10 I = something
    > > DO10I = something
    > > D O 1 0 I = something
    > >
    > > and leave it to the compiler to figure out whether you're starting a
    > > DO-loop or assigning a value to the variable DO10I.

    >
    > If you are saying that you leave it up to the compiler to decide how
    > to interpret any of the three above statements, then clearly whitespace
    > is *not* meaningless. It might be compiler-dependent or something,
    > but no meaningless. Unless you are saying that on a given FORTRAN
    > compiler, only one possible interpretation of all three statements
    > above is possible. That would be surprising.


    You misunderstand, probably because I didn't express myself clearly.
    Again from the Sun Fortran Reference Manual, "Special characters used
    for punctuation," after the graphic used in the manual for the space
    character: "Ignored in statements, except as part of a character
    constant."

    Ignored means *ignored*, the three examples given will be parsed
    identically and the meaning will be determined using other
    information. I think in this case the nature of "something" should be
    determinative, as the syntax for the range and stride of a DO-loop

    start, stop [,stride]

    doesn't match any legal expression (which is what would be required if
    this were assignment to the variable DO10I.

    But it's perfectly legal, if insane, to declare (or, with implicit
    typing undefeated, just go ahead and use) a variable named DO10I and
    write, say

    DO 10 I = 1.10

    because in Fortran whitespace is *not* considered to delimit tokens.

    --
    Mark Jackson - http://www.alumni.caltech.edu/~mjackson
    It is necessary to be slightly underemployed if you want to
    do something significant. - James D. Watson
     
    Mark Jackson, Jul 16, 2003
    #6
  7. Michael Chermside

    Peter Hansen Guest

    Grant Edwards wrote:
    >
    > Though I was recently surprised
    > that the remove() method for lists uses "==" and not "is" to
    > determine what to remove. It's documented that it works that
    > way. But, it wasn't what I excpected, and it took me a while to
    > figure out that it was using my class's __cmp__ method rather
    > than the object ID.


    Probably a very good thing, considering what would happen if
    you were trying to remove strings from the list, rather than
    simple things like integers...

    -Peter
     
    Peter Hansen, Jul 16, 2003
    #7
  8. In article <>, Peter Hansen wrote:

    >> Though I was recently surprised that the remove() method for
    >> lists uses "==" and not "is" to determine what to remove. It's
    >> documented that it works that way. But, it wasn't what I
    >> excpected, and it took me a while to figure out that it was
    >> using my class's __cmp__ method rather than the object ID.

    >
    > Probably a very good thing, considering what would happen if
    > you were trying to remove strings from the list, rather than
    > simple things like integers...


    I didn't mean to imply that the way it's done isn't a good
    idea, or that what I expected wasn't a bad idea. It's just
    novel to be surprised by Python -- which wasn't the case with
    FORTRAN.

    --
    Grant Edwards grante Yow! My nose feels like a
    at bad Ronald Reagan movie...
    visi.com
     
    Grant Edwards, Jul 16, 2003
    #8
  9. > I admit that Python probley gained no insiration from FORTRAN and any
    > 'similarities' are coincidental.


    Didn't FORTRAN popularise the idea of having
    the language separate from tons of special purpose
    libraries?


    Raymond Hettinger
     
    Raymond Hettinger, Jul 17, 2003
    #9
  10. Michael Chermside

    Terry Reedy Guest

    "Grant Edwards" <> wrote in message
    news:3f156c23$0$166$...
    > Yup. I found a lot of things in FORTRAN surprising. Python is
    > so much nicer in that respect. Though I was recently surprised
    > that the remove() method for lists uses "==" and not "is" to
    > determine what to remove. It's documented that it works that
    > way. But, it wasn't what I excpected, and it took me a while to
    > figure out that it was using my class's __cmp__ method rather
    > than the object ID.


    Given ints = [9, 99, 999, 9999] would it not surprise you even more if
    ints.remove(99) worked and ints.remove(999) did not, or even worse, if
    the behavior of ints.remove(99) depended on the implementation?
    (Similar examples apply to strings, where the implementation of
    interning and hence behavior based on identity *has* changed!)

    Terry
     
    Terry Reedy, Jul 17, 2003
    #10
  11. Michael Chermside fed this fish to the penguins on Wednesday 16 July
    2003 05:47 am:

    > richardc writes:
    >> Im no expert but wouldnt you accept that Python has 'borrowed'
    >> FORTRAN's
    >> fixed format syntax. I can only think of Python and FORTRAN off the
    >> top of my head which use whitespace as part of the syntax.

    >
    > Definitely NOT. Without addressing the question of HOW Python came by
    > the idea of using indentation to indicate block structure, it clearly
    > couldn't have been from Fortran, because what Python does and what
    > Fortran does are COMPLETELY different.
    >

    When it comes to FORTRAN, other than the reserved columns for branch
    label, continuation, and "sequence number", FORTRAN totally IGNORES
    white-space...

    D O 1 0I=1, 3 0, 2
    and
    DO 10 I = 1, 30, 2

    are IDENTICAL to a FORTRAN compiler.

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Bestiaria Home Page: http://www.beastie.dm.net/ <
    > Home Page: http://www.dm.net/~wulfraed/ <
     
    Dennis Lee Bieber, Jul 18, 2003
    #11
  12. Grant Edwards fed this fish to the penguins on Wednesday 16 July 2003
    08:15 am:


    >
    > IIRC (it's been a _long_ time) it's not up to the compiler. All
    > three of the above are required to be treated the same by the
    > compiler (a DO loop).
    >

    It depends on the "something"

    DO10I=1.3 is an assignment
    DO10I=1,3 is a DO loop. And the compiler can't tell
    the difference until it reaches the . or , (and if it guessed wrong, it
    has to backtrack to the beginning of the statement and reparse).

    Spacing, however, is not signicant.

    D O10 I = 1 . 3 is valid for the first one.
    D O10 I = 1 , 3 is identical to the second above.

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Bestiaria Home Page: http://www.beastie.dm.net/ <
    > Home Page: http://www.dm.net/~wulfraed/ <
     
    Dennis Lee Bieber, Jul 18, 2003
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruby Quiz

    [QUIZ] Animal Quiz (#15)

    Ruby Quiz, Jan 14, 2005, in forum: Ruby
    Replies:
    11
    Views:
    427
    James Edward Gray II
    Jan 18, 2005
  2. David Tran
    Replies:
    9
    Views:
    247
    David Tran
    Jan 21, 2005
  3. Ruby Quiz

    [QUIZ] 1-800-THE-QUIZ (#20)

    Ruby Quiz, Feb 18, 2005, in forum: Ruby
    Replies:
    15
    Views:
    353
    gabriele renzi
    Feb 24, 2005
  4. Marcelo Alvim

    [QUIZ] Newbie doubts about the quiz

    Marcelo Alvim, Aug 15, 2006, in forum: Ruby
    Replies:
    15
    Views:
    279
    Marcelo Alvim
    Aug 16, 2006
  5. Daniel Moore
    Replies:
    10
    Views:
    335
    James Gray
    Jan 31, 2009
Loading...

Share This Page