[swift-evolution] Returning nothing
Daniel Steinberg
daniel at dimsumthinking.com
Thu Jul 21 17:02:49 CDT 2016
Thanks all,
I did note that Nothing had been considered for another purpose and rejected so I didn’t think it would cause confusion.
I understand folks who advocate another name such as Unit but don’t feel that would help newcomers. Unit doesn’t seem to be more intuitive for them than Void.
Chris’ note addressed my misconception that a goal of Swift was that it could be a good first or learning language. I apologize for drawing that conclusion from (perhaps misreading) articles about Playgrounds that mentioned Swift as being designed so that it was a ideal for children and new programmers. The articles may have meant that the environment was designed for that purpose not the language.
Although my examples were in stand-alone functions, I was really thinking about functions that are passed as argument to other functions.
Given the response, there doesn’t seem to be a reason for me to draw up a proposal.
Thank you for the quick feedback,
Best,
Daniel
> On Jul 21, 2016, at 1:19 PM, Matthew Johnson <matthew at anandabits.com> wrote:
>
>>
>> On Jul 21, 2016, at 11:59 AM, Xiaodi Wu <xiaodi.wu at gmail.com <mailto:xiaodi.wu at gmail.com>> wrote:
>>
>> Quite frankly, I think the ship has long sailed for renaming Void.
>
> Agree. I’m not advocating change, just stating things that should be considered if anyone wants to propose it.
>
>>
>>
>> On Thu, Jul 21, 2016 at 11:52 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>>
>> Sent from my iPad
>>
>> > On Jul 21, 2016, at 11:42 AM, Daniel Steinberg via swift-evolution <swift-evolution at swift.org <mailto: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 <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.
>>
>> If we consider renaming it Unit is the obvious way to go (https://en.m.wikipedia.org/wiki/Unit_type <https://en.m.wikipedia.org/wiki/Unit_type>)
>>
>> >
>> > So
>> >
>> > f: ( input: Int) -> Void
>> >
>> > becomes
>> >
>> > f: ( input: Int) -> Nothing
>> >
>> > Instead of saying “f takes an Int and returns a Void” I read this as “f takes an Int and returns nothing”.
>> >
>> > I’ve been using f:(input: Int) -> () because it’s easier to explain than Void to non-experienced programmers. Experienced programmers have no problem with Void. But Void seems to be something we’re using just because we have for a while - like x++ and C-style for loops.
>> >
>> > Best,
>> >
>> > Daniel
>> > _______________________________________________
>> > swift-evolution mailing list
>> > swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> > https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160721/5b5799a7/attachment.html>
More information about the swift-evolution
mailing list