Re:I don't like Python. Does that make me a bad person?
by Goladus on Saturday June 26, 2010 @09:17PM
(#1464651)
While it's true that "last expression in a function" is not technically ambiguous, because of python's statement/expression distinction leaving off the return can lead to unclear code.
For example, if there's a function composed entirely of print statements, the last expression evaluated will be the expression in the last print statement executed. But, that means you have to know that 'print' is a statement and not an expression, and that the right-hand side of the print statement is in fact an expression.
In ruby, actions like prints and assignments are side-effects and always evaluated as expressions. So if puts is the last expression in a function you'll get the return value of puts (which is usually nil I believe). That's pretty simple.
In Ruby, the last expression in a function is the return value; in Python you must use the return keyword, even though there's no ambiguity.