Search |
||||||||||
Much A-do About NothingPosted by cayhorstmann on April 6, 2009 at 6:04 PM PDT
Why am I not keen on bigger coverage of the
Here are the grep statements in case someone wants to improve on this: grep -r -h "[^A-Za-z0-9]for (" . | grep -v "^[ ]*[*]" | wc
grep -r -h "[^A-Za-z0-9]while (" . | grep -v "^[ ]*[*]" | wc
grep -r -h "[^A-Za-z0-9]do {" . | grep -v "^[ ]*[*]" | wc
As you can see, 98% of the loops are not Moreover, a boolean positive = false;
while (!positive)
{
System.out.print("Please enter a positive number: ");
value = in.nextDouble();
if (value > 0) positive = true;
}
instead of do
{
System.out.print("Please enter a positive number: ");
value = in.nextDouble();
}
while (value <= 0);
Is the first alternative that much worse?
That's indeed what other textbooks do. They give equal billing to each Java loop type. Here is a quote from one briskly selling text:
To paraphrase Truman Capote, that's not computer science—it's taxonomy. (And it's bad taxonomy. Wouldn't “the case of reading the numbers
until the input is 0” be one of the few cases where a
But, you may say, an employer wants to make sure that any student whom they
hire can read a I guess this gets to the heart of the difference between certification and education. In my loop chapter, I want to educate students to
Am I getting all worked up over nothing? I could just give in and turn the “advanced topic” into a regular section. Or should I stick to my guns? Please help me make up my mind by posting your thoughts! »
Comments
Comments are listed in date ascending order (oldest first)
Submitted by varan on Mon, 2009-04-06 23:14.
Now if the students can understand and explain the grep statements at the top that will be real education.
All joking aside, it may not be that bad for students if you ask them to do the same problem with and without the do-while loops in terms of exercising their brains.
You contradict yourself somewhat, because your statistics are clearly significant from a utilitarian (read vocational) perspective but you want to make a decision on the basis of what is more educational.
Submitted by fabriziogiudici on Tue, 2009-04-07 00:34.
I cannot comment much about pedagogy - my classes are only towards older people and if I want to make some "brainful" divagation it's more about design. But I agree with you on the scarce relevance of do-while. I also believe that if I go and look at my own code, I seldom use the while itself.
For instance the above example could be rewritten as (of course, now the code formatting will be ruined):
for (boolean positive = false; !positive; )
{
System.out.print("Please enter a positive number: ");
value = in.nextDouble();
if (value > 0) positive = true;
}
What I appreciate about the for is the capability of using a local scope for the needed variable (which is what you need 95% of times - i.e., you don't need to read the iteration variable outside of the loop). Of course, this point about the local scope has very limited consequences of the code - it's not even taxonomy, rather aesthetics.
Submitted by felipegaucho on Tue, 2009-04-07 00:38.
Certification do not endorse education, that's obvious.. and it never will.. it is just a memory test, like sudoku and others :)
But certification proves discipline and resilience .. ability to memorize and to keep focus under pressure.. it is like an amateur athlete finishing a marathon.. he is not the best, eventually he is not even born to do that.. but he proved he has strengths and determination to reach his goals.. and this is also important :)
* in Brazil (and I suppose in several other countries) it is very common to find young students collecting SUN certifications, some of them with more than 5 and just twenty fews year old.. :)
* In Switzerland, people barely remember such certifications exist.. and they only apply for such tests due to the obviousness of the market..
rule of thumb: more educated the people, less interested they are in memory tests..
Submitted by billdavidson on Tue, 2009-04-07 02:50.
>Am I getting all worked up over nothing?
I think you kind of are. I agree that in practice, do-while is used a lot less. It seems weird to call it an "advanced topic" though since I don't consider it any more advanced than the other loops. It's just another detail of the exact same topic.
I like the idea of having the students solve the same looping problem with each of the different loop types. I think it helps them understand the differences between the loop types. I realize it may seem like minutiae, but I think that understanding the differences between the different loop types helps give beginners a better sense of what loops are really doing for them.
I have to ask, does the do-while really slow down the curriculum that much?
Submitted by johnreynolds on Tue, 2009-04-07 04:58.
Cay,
I think it's worth pointing out the different philosophy between "while" and "do-while" as an example of why folks need to think before they code.
The former makes no assumption that the body of the loop will ever be executed, the latter asserts that the body of the loop will be performed at least once.
I agree with you that the language would have been just fine leaving out "do-while"... but since it is there you might as well use it as an entry into programming style and philosophy.
-JohnR
Submitted by cajo on Tue, 2009-04-07 13:21.
Hi Cay,
I lump do-while in the same category as finally; you can of course get by without them -- but, there are times when they can so eloquently express an idea... it exists simply to add expressive richness to the language.
Perhaps consider providing some examples, where using the other types of loops would look clumsy.
I feel it is not an "advanced topic" at all, but rather an exploration into alternate constructs, and different ways of thinking.
John
Submitted by dwalend on Wed, 2009-04-08 06:01.
Cay,
The most important bit of trivia that's important about do-while is to contrast it with repeat-until. Pointing out the difference would save useless aggravation for the student.
What's your opinion of the ? operator? It seems like the same sort of choice.
Dave
Submitted by avrecko on Wed, 2009-04-08 06:26.
Cay, keep it up! You're one of a few who are not afraid to remove the unpopular and rarely used stuff and replace it with something more interesting. I think that do-while does deserve a quick mentioning and that is about it.
Big Java is an excellent book. I had the pleasure of reading the 2nd edition. It is about learning to program i.e. solving problems with code and not about learning constructs and doing construct related workouts - that is a side effect of solving a problem not the main objective. You're book and writing style gets it right!
I am not against learning "constructs" it is just that usually one learns more about constructs and how they are implemented from a course in "Programming Languages" and not from Introduction to Programming.
Submitted by cayhorstmann on Wed, 2009-04-08 09:23.
cajo: do-while is NOT in the same category as finally. Students absolutely need to know how to use finally for resource cleanup. (Oddly enough, some of those briskly selling textbooks treat finally as an exotic topic--go figure...)
dwalend: Indeed I take the same approach with the ? : operator. It's nice to know but not considered very important. (In my experience. students tend to pick it up on their own anyway because they enjoy the saved keystrokes :-))
Submitted by brucechapman on Thu, 2009-04-09 03:05.
Cay,
leaving it out somewhat seems like a good idea, but calling it "advanced" is maybe where the problem lies. Maybe a section title that emphasises the low usage in practice rather than hinting at complexity (which doesn't really exist relative to "while" ) might keep the reviewers happy, and allow you to keep to your ideals.
Bruce
|
||||||||||
|
|