3 ms·
It can cause surprises. One of the biggest ones is turning a loop into an expression if it’s the last thing a function does. Edit: here is an example https://
by city41 6y ago
It can cause surprises. One of the biggest ones is turning a loop into an expression if it’s the last thing a function does.
Edit: here is an example
https://coffeescript.org/#try:-%3E%20%0A%20%20for%20i%20in%20%5B1...3%5D%0A%20%20%20%20console.log%20i https://coffeescript.org/#try:-%3E%20%0A%20%20for%20i%20in%2...
- rraval 6y agoAccumulating loop results in an array is bad for perf, but won't necessarily cause logic bugs. My favourite implicit return gotcha comes from the intersection of CoffeeScript and jQuery, where implicitly returning `false` from an event handler implies `preventDefault()` and `stopPropagation()`. This can even cause heisenbugs if your logging throws booleans around.
- dgoldstein0 6y agoAnother bad one: returning a jQuery.ajax object, and then consumers of your api may start using it directly. We have that in our codebase still. Not sure if it was intentional or not but it's going to be hard to undo.
- brlewis 6y agoThat's specific to Coffeescript. Implicit returns in Scheme don't do that.