Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python Quiz

Reply
Thread Tools

Python Quiz

 
 
Michael Chermside
Guest
Posts: n/a
 
      07-16-2003
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.


 
Reply With Quote
 
 
 
 
Mark Jackson
Guest
Posts: n/a
 
      07-16-2003
Michael Chermside <(E-Mail Removed)> 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



 
Reply With Quote
 
 
 
 
richardc
Guest
Posts: n/a
 
      07-16-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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



 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      07-16-2003
Mark Jackson wrote:
>
> Michael Chermside <(E-Mail Removed)> 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
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      07-16-2003
In article <(E-Mail Removed)>, 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!!
 
Reply With Quote
 
Mark Jackson
Guest
Posts: n/a
 
      07-16-2003
Peter Hansen <(E-Mail Removed)> writes:
> Mark Jackson wrote:
> >
> > Michael Chermside <(E-Mail Removed)> 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


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      07-16-2003
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
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      07-16-2003
In article <(E-Mail Removed)>, 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
 
Reply With Quote
 
Raymond Hettinger
Guest
Posts: n/a
 
      07-17-2003
> 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


 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      07-17-2003

"Grant Edwards" <(E-Mail Removed)> wrote in message
news:3f156c23$0$166$(E-Mail Removed).. .
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[QUIZ] Gathering Ruby Quiz 2 Data (#189) Daniel Moore Ruby 10 01-31-2009 08:36 PM
[QUIZ] Newbie doubts about the quiz Marcelo Alvim Ruby 15 08-16-2006 02:08 PM
[QUIZ] 1-800-THE-QUIZ (#20) Ruby Quiz Ruby 15 02-24-2005 06:05 AM
[SOLUTION] Ruby Quiz #15 Animal Quiz David Tran Ruby 9 01-21-2005 02:11 AM
[QUIZ] Animal Quiz (#15) Ruby Quiz Ruby 11 01-18-2005 02:42 PM



Advertisments