Forget To Answer The Result

My single most common error in Smalltalk is to forget to answer the result of a method. This was a very common error I used to make in C/C++ as well. In those languages I solved it by never using them again.

In Smalltalk, I changed the method template to include ^result at the end. Then I disciplined myself always to edit the template, not just replace the whole thing. --RonJeffries


I'm surprised you had that problem in C/C++. Modern compilers will warn you if you don't return the value that was declared, or if you try to use a result that wasn't declared. -- DaveHarris

This was long ago, before I gave up C/C++. They put in that feature for me. --RonJeffries


Perl uses the results of the last expression evaluated as the return value of a subroutine/method. But often the return value returns on the context (scalar or list) in which the subroutine/method is invoked. Every so often... Oops. --DaveSmith


FunctionalProgrammingLanguages tend to have well-defined return statements and in good style, they are quite vital and thus hardly missable. The common thing to return in a block is the last statement's return code. This was probably where it was copied to Perl from.


EditText of this page (last edited October 20, 2007) or FindPage with title or text search