This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Webmaster forum > July 2006 > OT: Computer programming generation gap





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author OT: Computer programming generation gap
MGW

2006-07-10, 7:20 pm

OK. I know I'm an old fogey. I know that teens are supposed to fight
with their parents. But I just wasn't prepared to be having fights
with my son over computer programming!

He's currently mad at me because I told him it was not a good idea to
have an empty "while" statement in his PERL program!

Try arguing proper programming practice when you speak different
languages (I don't know Perl, he doesn't know Fortran or Pascal)

Kids!

--
MGW (Note: my Hotmail address is seldom checked)
Hofstadter's Law: It always takes longer than you expect, even
when you take into account Hofstadter's Law. - Douglas Hofstadter
Toby Inkster

2006-07-10, 7:20 pm

MGW wrote:

> He's currently mad at me because I told him it was not a good idea to
> have an empty "while" statement in his PERL program!


Normally, in

while (TEST)
{
ACTION
}

ACTION will be some activity that will eventually negate TEST; but
occasionally TEST will be such that it doesn't depend on ACTION, so the
following do make sense:

while ($stdin = <> )
{
# discard input
}

and:

# $var will be slowly decremented by another thread
# wait for it to hit 0.
while ($var > 0)
{
# do nothing
}
# now do something

And empty while loop is a little inelegant though; there is usually a
nicer way to achieve what you wanted.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

mbstevens

2006-07-10, 7:20 pm

On Sat, 08 Jul 2006 12:12:11 +0100, Toby Inkster wrote:

> And empty while loop is a little inelegant though; there is usually a
> nicer way to achieve what you wanted.


Python provides a
pass
statement that allows you to create a null statement.

In C and PERL you can use empty braces or a lone
semicolon for the same result.


MGW

2006-07-10, 7:20 pm

On Sat, 08 Jul 2006 12:12:11 +0100, Toby Inkster
<usenet200606@tobyinkster.co.uk> scrawled:

> MGW wrote:
>
>
> Normally, in
>
> while (TEST)
> {
> ACTION
> }
>
> ACTION will be some activity that will eventually negate TEST; but
> occasionally TEST will be such that it doesn't depend on ACTION, so the
> following do make sense:
>
> while ($stdin = <> )
> {
> # discard input
> }
>
> and:
>
> # $var will be slowly decremented by another thread
> # wait for it to hit 0.
> while ($var > 0)
> {
> # do nothing
> }
> # now do something
>
> And empty while loop is a little inelegant though; there is usually a
> nicer way to achieve what you wanted.


Oops - I wasn't clear. His statement is

while ( )
{ do stuff}.....


It's the ( ) that I objected to.


--
MGW (Note: my Hotmail address is seldom checked)
Hofstadter's Law: It always takes longer than you expect, even
when you take into account Hofstadter's Law. - Douglas Hofstadter
Jerry Stuckle

2006-07-10, 7:20 pm

MGW wrote:
> On Sat, 08 Jul 2006 12:12:11 +0100, Toby Inkster
> <usenet200606@tobyinkster.co.uk> scrawled:
>
>
>
>
> Oops - I wasn't clear. His statement is
>
> while ( )
> { do stuff}.....
>
>
> It's the ( ) that I objected to.
>
>


Nothing wrong with that - although maybe while(true) might be better.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
MGW

2006-07-10, 7:20 pm

On Sat, 08 Jul 2006 11:52:21 -0400, Jerry Stuckle
<jstucklex@attglobal.net> scrawled:

>
> Nothing wrong with that - although maybe while(true) might be better.


OK - please explain to me why that's ok. I was taught (back in the
dark ages) that something like that was just asking to end up in an
infinite loop.

--
MGW (Note: my Hotmail address is seldom checked)
Hofstadter's Law: It always takes longer than you expect, even
when you take into account Hofstadter's Law. - Douglas Hofstadter
MGW

2006-07-10, 7:20 pm

I should add that I'm open to being educated about this - the problem
is that my son, in typical adolescent fashion, turned this into a
fight rather than a discussion. It's amazing how quickly things can
escalate on *any* topic when dealing with a 15 y.o. in the midst of
hormonal changes ;-P

--
MGW (Note: my Hotmail address is seldom checked)
Hofstadter's Law: It always takes longer than you expect, even
when you take into account Hofstadter's Law. - Douglas Hofstadter
Jerry Stuckle

2006-07-10, 7:20 pm

MGW wrote:
> On Sat, 08 Jul 2006 11:52:21 -0400, Jerry Stuckle
> <jstucklex@attglobal.net> scrawled:
>
>
>
>
> OK - please explain to me why that's ok. I was taught (back in the
> dark ages) that something like that was just asking to end up in an
> infinite loop.
>


Either way it's an infinite loop. But there is the "break" statement
you can use to exit the loop.

Its quite useful when you need to make some tests in a loop to determine
whether to exit or not.

For instance, you could use:

$done = false;
while (!$done) {
Do some work
Test results
if test succeeded
$done = true;
else
do more work
}

Or
while () {
Do some work
Test results
if test succeeded
break;
do more work
}


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jerry Stuckle

2006-07-10, 7:20 pm

MGW wrote:
> I should add that I'm open to being educated about this - the problem
> is that my son, in typical adolescent fashion, turned this into a
> fight rather than a discussion. It's amazing how quickly things can
> escalate on *any* topic when dealing with a 15 y.o. in the midst of
> hormonal changes ;-P
>


It also depends on if you're a parent or not :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews