2 ms·
Yeah, that's one of the good reasons for having a return statement. I don't know if it outweighs the reasons not to have a return statement (yet). Another iss
by mpweiher 5y ago
Yeah, that's one of the good reasons for having a return statement. I don't know if it outweighs the reasons not to have a return statement (yet).
Another issue is that there are actually 2 functions of the return statement: (1) it sends a result and (2) it terminates the method/function/whatever. In call/return, those are the same, but more generally they are not, and Objective-S wants to make it easy to not default to call/return semantics.
And that's difficult, because we are so incredibly used to call/return semantics that it's often hard to see that another way is even possible, let alone practical. So in the design, I need to very deliberately push against what seems comfortable and familiar.
Which can lead to insights or nonsense.
We'll see how it turns out.
- ghusbands 5y agoHaving implicit returns has been a source of bugs and vulnerabilities in code [1][2][3]. Essentially, it results in accidental return of temporary values, especially in cases in which people don't want to return anything. [1] https://github.com/CodeNarc/CodeNarc/issues/450 https://github.com/CodeNarc/CodeNarc/issues/450 [2] https://stackoverflow.com/questions/24070544/suppressing-implicit-returns-in-swift https://stackoverflow.com/questions/24070544/suppressing-imp... [3] https://nug.xojo.narkive.com/GvvcWglM/bug-command-keys-are-absorbed-by-menu-handlers-on-mac-but-not-on-windows https://nug.xojo.narkive.com/GvvcWglM/bug-command-keys-are-a...
- slver 5y agoIf you don't want to return anything you'd declare your function return type as void, so that's probably more in dynamically typed systems.
- magicalhippo 5y agoWe've had cases at work where the issue is that a void function (procedure) is converted to a "proper" function, and some return paths are missed. For our compiler, for certain types it fails to warn that the return variable is unassigned, hence bugs occur. This is a statically typed language, it's just an unfortunate interaction between compiler magic and the code that checks for unassigned return variables.