[Tutor] repeat

Scott Sandeman-Allen scott at rscorp.ab.ca
Sat Nov 17 18:51:02 CET 2007


On 11/17/07, bob gailer (bgailer at alum.rpi.edu) wrote:

>Michael wrote:
>> Hi All
>>
>> This has probably been asked before but can I get some clarification on 
>> why Python does not have a repeat...until statement, and does that mean 
>> repeat...until is bad practice? I was trying to get Python on the 
>> standard langauge list for my state secondary school system but they say 
>> a langauge must have a test last structure in it to be considered.
>>   
>That rules out FORTRAN!
>
>And I would point out (as one of us already did):
>
>while True:
>  blahblah
>  if condition: break
>
>Is a test-last structure.

If one considers the "repeat" statement to have an _implied_ truthfulness there is even less difference _except_ for the nesting syntax which IMO is arbitrary and therefore moot.

    repeat [while true]
        perform task
    until [proven false by] condition

or  
    do [while true]
        blah blah blah
        
VS the explicitly stated

    >while True:
    >  blahblah
    >  if condition: break
    
Python is a very rich language and provides a great deal of flexibility, even with this single flow-control statement i.e.
    
    while [state | condition] maintains truthfulness:
        perform task [intrinsically modify state | argument(s)]
        [test argument(s) & exit | modify state]

Python is a modern and full-featured language. The test of its sutability should be based upon its clarity and capability rather than an arbitrary syntactical (sp?) construct.

Can the language clearly perform looping constructs: yes, in many ways.
Does the language have a reasonable level of flow-control: yes.
...

I could see a language like PHP being excluded because of its dependence upon environment. But if I were to teach a language to a student, Python would probably be one of my first choices as opposed to C/Java/Perl/VB/AppleScript and such.

Ultimately, what is the objective of the programming programme? Is it to teach students to consider application development at a high-level or incumber them with unnecessary syntax at a low level i.e. 
    
    def some_variable as some_type
    
    test some_variable then
        ...
    end test

IMO, the def, then and end are unnecessary cluter; totally superfluious!

Personally, I would rather my students (if I had any) be less incumbered with "verbosity" and more focussed on planning and understanding. Letting the language work for them rather than enslaving them.

"When the only tool you have is a hammer, all of your problems start looking like nails" is a favorite quote of mine (unknown origin). Python is one heck of a hammer to have in the bag.

Scott

PS. Interesting thing about Python: in minutes a student could be working with the language i.e. 'Hello world', and understand it. Within days they can be writing functional code with reasonable complexity. The kicker is, the language is deep enough that new approaches can still appear many months and even years of regular use. Not only is it tasty, it's nutritious too ;^)


More information about the Tutor mailing list