<Can you offer real code examples of your two scenarios?
In my experience, if one wanted to append to a file one would open the file for append and the OS would normally create the file, if it was not there, automatically.
Well, that's true in my experience, too, so maybe it's not the best example. We'll take your pseudocode and alter it a bit, to provide a better example. As for real code examples, my main expertise is in VB6, and attempting to demonstrate these techniques in VB6 wouldn't serve to clarify them. As Appleman says, VB6 error handling sucks.
<Following your argument we would have to add a test for zero rows, throw an exception on that zero and write some code to handle the exception.
Actually, I would have a data reading object whose job it was to throw exceptions typical in its use do that testing and throwing. Of course, it wouldn't write any code to handle the exception. Whether the user of the object handles it would depend on whether the user's assumptions have been violated by its occurrence or not.
<Why do I need to throw an exception here?
You don't! However, that fact doesn't support your argument! All you're really saying in that it doesn't need to handle a zero row response differently from a nonzero one. As such, it isn't an example of what we're debating about. I'm not suggesting that you have to throw an exception when the interface's implicit assumptions are NOT violated, and as far as I can see, that's not what you're trying to refute.
<Oh, and on the subject of efficiency, which version is more efficient?
Why yours is, most certainly. Of course, it doesn't represent your side of the argument, QED.
I'm going to use your pseudocode to provide a better example than my own, as I promised:
Code:
//Your argument:
row = sql("select * from invoices where date >= start and date <= end_date");
/*
if there are no rows then
{
tell user, invite to change dates
}
*/
display_page_header();
foreach row in rows {
display_row(row);
}
display_footer();
Code:
//my argument:
try
row = sql("select * from invoices where date >= start and date <= end_date");
catch NoRowReturnedException
tell user, invite to change dates
end try
display_page_header();
foreach row in rows {
display_row(row);
}
display_footer();
This also supports my last. I'll repeat it again: exceptions handle behavior that violates the assumptions of their associated interface. Exceptions are not to be thrown when they do NOT do so. Your example does NOT do so; one of the assumptions of the interface is that it is not required that rows be displayed.
As for your last post, it appears to be based entirely on the perception that strongm and BobRodes are the same person, and so I will refrain from further comment, assuming it was posted in error. Except for making the observation that I'm unaware of anywhere in my posts that I've made an ad hominem argument, so I invite you to show me. Further, I'm unaware of anywhere in my posts where I mentioned that I was a lawyer. (Actually, I'm a musician, and since I'm so fond of analogies, the fact that I study scales and arpeggios and music theory doesn't suggest that I can't play Chopin and Beethoven and the blues. Rather the opposite, I would think.)
Since it's not clear from your use of the term that you and I have the same understanding of the term ad hominem, I'll state mine here. An ad hominem argument is one that attempts to lend weight to a position by establishing the value of the holder of the position rather than the position itself, or conversely, to trivialize the position by reducing the value of its holder. Of course, such arguments are spurious; their value lies in using emotion to distract focus from the issue at hand.
Examples from your posts include:
<I do know how kernels work, I've written kernel device drivers, languages, databases, firmware, comms systems and all manner of things in my time.
<you have no interest in seeing both sides of an argument.
<I wonder, just out of interest, how much actual real world development have you done?
<You are classed as an Instructor, does that mean that you read books and echo them or that you acutally use the info in the real world?
<Are you sure you're a lawyer and not a politician? (Maybe both?)
I'm not able to find examples in my posts. Perhaps you can. In any case, perhaps you will refrain from making them in future, as they do not add to the quality of the thread. Furthermore, if you find examples in my posts, please point them out, so that I can also refrain.
Now, I believe I've pretty well stated my case at this point. I find that I have supported my point of view quite well, I don't find that you've supported yours well enough to change mine and adopt it. Your showing that my example was not the best does not suggest to me that you have refuted its underlying assertion. The example certainly doesn't do so. If you, or anyone else, can provide fresh fuel for the debate, please do so.
As for begging to differ with strongm, that should be interesting. I shall stay tuned.
Bob