-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: Implicit Return
Whenever a CoffeeScript function is invoked, if no explicit return statement is executed, the function will implicitly return the value of the last expression to be evaluated in the function body. This is known as an implicit return.
In CoffeeScript, (almost) everything is an expression. Blocks evaluate to the value of the last expression to be evaluated during the execution of the block. Implicit returns are consistent with this, however, the feature has always been controversial.
There is a (disputed) performance cost associated with generating and returning values that are immediately garbage collected where a function is invoked for its side effects, and the return value is not used.
Within this project, no consensus has been established yet. The options are:
- Keep the current behaviour.
- Introduce syntax (for example, new function operators) that disable the feature on specific functions.
- Introduce compiler options, so the feature can be disabled on specific files (possibly for a whole project).
- Remove the feature entirely.
Option 4 is unlikely, as it is at odds with the design of CoffeeScript. Ashkenas has always favoured Option 1.
This has been discussed many times. This is an incomplete list: