[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: expressions vs. statements

kragen@pobox.com (Kragen Sitaker) writes:


> The consequence is that your function returns some value, even if you
> didn't really intend for it to do so.  This means that whenever you
> change the function, you need to either maintain the same return value
> (possibly leading to wordier code, inefficiency, or in the worst case,
> the inability to make code correct) or verify that nobody is using the
> return value.

I confirm this is a problem in Perl. I have some functions that ends with:
   if () {
   } else {
where the if_then_else returns an error/warning value.

When you want to add some code after it, you must check wether the return
value was wanted and used by some caller. Adding debugging statement after the
if_then_else may cause havoc!


> I don't think this issue is terribly important in language design, but
> it's obvious to me that the right answer is that most blocks of
> sequential statements shouldn't return a meaningful value.

agreed for while/for. My only problem is with if_then_else which return value
is useful. Alas in perl you can't write "return if () ..." to disambiguate.