--- Begin Message ---
Hi,

Brian Blais wrote:

I find that when teaching beginning programmers, they usually think in "until" terms, and not "while" terms.

do:
    Forward()
until Touched()

and I have to explain to them that Python doesn't have "until", and that the logic for while is exactly the opposite:

while not Touched():
    Forward()

I must admit, this is one of those cases, where the PASCAL way is indeed just how beginners tend to think. I guess many of our students would say the same. On the other hand, the bigger problem is understanding condition controlled loops at all, so it is only a minor thing which you have to get over with when using Python.

If Python's main goal was to be "the most beginner friendly programming language for the first x hours", then it should probably provide many more such constructs; PASCAL FOR-loop is also easier to teach to novices than Pythons list iteration on a range()-result.

Havin said that: more experienced programmers appreciate Python, because these possibilities don't exist. In the long run, it is easier for me to read code when there is principally "just one way to do it". Perhaps it was a tiny bit harder to program the loop by using an entry condition. But as a reader, I only have to scan from top down, always only entry conditions, never exit conditions (except with a break, but then the exit condition is directly next to the break and I seldom use break.)

they find the "while" logic to be unintuitive, and I often find myself feeling the same way: crafting it with the until logic, and then reversing it. Perhaps I should do as above, and do:

while True:
    Forward()
    if Touched(): break

but somehow that feels wrong to me, like bypassing the point of the while: all that power to check for conditions, and you just use it to check True, and then use a break inside. It's readable, I guess, but not a programming construct I am immediately drawn to.

I liked your first way much better. Reversing the condition is very readable:

while not touched():
   forward()
# must have touched something to come here
doSomethingAtTheEnd()

Cheers,

Christian


--- End Message ---
_______________________________________________
Edu-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to