[swift-evolution] Returning nothing
matthew at anandabits.com
Thu Jul 21 12:57:25 CDT 2016
> On Jul 21, 2016, at 12:51 PM, Haravikk <swift-evolution at haravikk.me> wrote:
>> On 21 Jul 2016, at 17:52, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
>>> On Jul 21, 2016, at 11:42 AM, Daniel Steinberg via swift-evolution <swift-evolution at swift.org> wrote:
>>> This may be a silly question - given that one of Swift’s design principles is to be a language for new programmers and for APIs to read like English phrases, should we replace the typealias of Void for the return type () with Nothing.
>> Nothing was one of the names considered for the bottom type that replaces @noreturn (https://github.com/apple/swift-evolution/blob/master/proposals/0102-noreturn-bottom-type.md). I think it would be confusing to rename Void to Nothing.
> I think on that issue the favourite for replacing @noreturn is Never or NoReturn, rather than Nothing (since @noreturn doesn't return nothing, it doesn't return in the first place), so Nothing is actually okay in that regard.
Yes, Never won that debate. But Nothing was considered and does imply “bottom type” to many people. That is why I don’t think it is a good choice here.
> I wouldn't mind the change of name, as void to me suggests something like a yawning abyss, which implies a substantive gap, rather than an actual absence of something, whereas Nothing is a bit clearer. That said I've never had any real trouble with Void, but can see Nothing being a tad easier to teach.
> It's also not necessarily a very disruptive change, as many people don't write -> Void and just omit it, though personally I prefer to always write it out explicitly.
Agree. I’m neutral on changing it. I just think Nothing is the wrong name. I would advocate Unit if we’re going to change it. Both Unit and Void have precedence in other languages. The precedence for Nothing in other languages is “bottom type” which means it is going to be a confusing choice.
More information about the swift-evolution