2 ms·
"Return" is much more reliable to spot (moreso with syntax highlighting) than having to identify the last expression, in particular in functional-style programm
by layer8 6y ago
"Return" is much more reliable to spot (moreso with syntax highlighting) than having to identify the last expression, in particular in functional-style programming where expressions can take up many lines.
One way to think about it is how assigning subexpressions to a descriptively named variable helps reader comprehension, instead of nesting everything into one big expression. "Return" fulfills a similar role.
(In some imperative languages, the return value is defined by assigning it to the name of the function — or rather, to an implicitly declared variable having the same name as the function. While that design has some problems of its own (mutability, default values, naming), it exemplifies the analogy with descriptive variables noted above.)