> > Hello, > I'm a student in MATAM. > In your lecture yesterday (monday) you said that a function shouldn't return > "result" each and every time and it depends on the function, because then we > would have to do a lot of checks each time a function is called. > In the homework exercise about ADT we were provided with a LIST ADT in which > ALL the functions return "result" except, of course, the "create" function > and told to use only this ADT when impementing a list. > After writing some of the code we were required to write I found myself > doing check after check after check every time I used a function from the > provided ADT. It's very tedious and creates a very long code. > I'm not asking for you to change the provided ADT, I just wanted to point > this out. > Gal. > Shalom, I am afraid you, somehow, missed my point. 1. As you mentioned, I've already said that, so you basically give an evidence that supports my claim. OTOH, smart coding style may eliminate much of the tediousness, e.g, Result do_some_work(some_type data) { other_type local; Result r = may_fail(data, &local); if (r == FAILURE) { clean_up(local); return FAILURE; } return may_fail_that_cleans_itself(local, data); } 2. I did *not* say that you do not have to check successful completion of functions. Ignoring a possible failure is in most of the cases wrong. I *just* said that in many cases you do not have to build your functions in a way that every one of them is *explicit* about it. 3. I already said in class that, to my view, the returned type Result is overemphasized in recitations (but I did *not* say it was wrong). 4. I said in class that in C++ there is a system that separates error-detection from error-handling, and it is done in a way that does not require the functions that are between them to participate in the process. This system is called "exception" and you better look at your (good) book index. We may or may not touch this subject in our MaTaM lectures. Enjoy Yechiel -------------------------------------------------------------------------------- Have you looked at recent updates to "Bad Books Amusement Park" ? Try http://www.cs.technion.ac.il/users/yechiel/CS/BadBooksC+C++.html TIME cannot be saved !!! You can either borrow it - and PAY high interest in return, or invest it - and GET high interest in return. Yechiel M. Kimchi yechiel Faculty Comp. Sc. The Technion, Haifa, 32000 IL Homepage: http://www.cs.technion.ac.il/users/yechiel/