Thoughts on making NSOperatingSystemVersion Comparable?


(Robert S Mozayeni) #1

Hello.

I’ve recently forked swift-corelibs-foundation and implemented Comparable for NSOperatingSystemVersion.

What’s the point of this? Well, in the words of a friend, "It’s a value type with a clear ordering, why not?”.

I have also added a new initializer that allows something like

NSOperatingSystemVersion(10,11,4)

instead of requiring

NSOperatingSystemVersion(majorVersion: 10, minorVersion: 11, patchVersion: 4)

Not only is this new initializer easier to type, but it also much clearer, especially when one is quickly scanning through code.

My changes: https://github.com/rsmoz/swift-corelibs-foundation/commit/e3db7ae2d7f4ba27ae5597e157b41a4b34def468

Also, the Version struct in swift-package-manager has an extension for Comparable, as well as concise initializer:
https://github.com/apple/swift-package-manager/blob/39fdccc74fcb11bc0a352b73fb7e656ba6843ff4/Sources/PackageDescription/Version.swift#L23

Tests: https://github.com/rsmoz/swift-corelibs-foundation/commit/db44f29e42f29ad0fe35f69ac83d853453c77bc6

I’d like to hear your opinions on my changes. For instance, do you think implementing Comparable for NSOperatingSystemVersion would best be done in an extension? That’s how SwiftPM does it.

Best,
Robert Mozayeni


(Jordan Rose) #2

Since the corelibs version of Foundation is meant to match the Darwin version (for the most part), this is more a question for the owners of the Darwin Foundation framework (and overlay). Fortunately, they're the same people maintaining the corelibs port (Tony Parker, Philippe Hausler, and others), and they have the freedom to make such decisions without going through the full Swift evolution process.

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

Jordan

···

On Jan 26, 2016, at 3:32, Robert S Mozayeni via swift-evolution <swift-evolution@swift.org> wrote:

Hello.

I’ve recently forked swift-corelibs-foundation and implemented Comparable for NSOperatingSystemVersion.

What’s the point of this? Well, in the words of a friend, "It’s a value type with a clear ordering, why not?”.

I have also added a new initializer that allows something like

NSOperatingSystemVersion(10,11,4)

instead of requiring

NSOperatingSystemVersion(majorVersion: 10, minorVersion: 11, patchVersion: 4)

Not only is this new initializer easier to type, but it also much clearer, especially when one is quickly scanning through code.

My changes: https://github.com/rsmoz/swift-corelibs-foundation/commit/e3db7ae2d7f4ba27ae5597e157b41a4b34def468

Also, the Version struct in swift-package-manager has an extension for Comparable, as well as concise initializer:
https://github.com/apple/swift-package-manager/blob/39fdccc74fcb11bc0a352b73fb7e656ba6843ff4/Sources/PackageDescription/Version.swift#L23

Tests: https://github.com/rsmoz/swift-corelibs-foundation/commit/db44f29e42f29ad0fe35f69ac83d853453c77bc6

I’d like to hear your opinions on my changes. For instance, do you think implementing Comparable for NSOperatingSystemVersion would best be done in an extension? That’s how SwiftPM does it.

Best,
Robert Mozayeni
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Robert S Mozayeni) #3

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I file a proposal: https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I actually draft a formal proposal.

-Robert

···

On Jan 26, 2016, at 5:59 PM, Jordan Rose <jordan_rose@apple.com> wrote:

Since the corelibs version of Foundation is meant to match the Darwin version (for the most part), this is more a question for the owners of the Darwin Foundation framework (and overlay). Fortunately, they're the same people maintaining the corelibs port (Tony Parker, Philippe Hausler, and others), and they have the freedom to make such decisions without going through the full Swift evolution process.

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

Jordan

On Jan 26, 2016, at 3:32, Robert S Mozayeni via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hello.

I’ve recently forked swift-corelibs-foundation and implemented Comparable for NSOperatingSystemVersion.

What’s the point of this? Well, in the words of a friend, "It’s a value type with a clear ordering, why not?”.

I have also added a new initializer that allows something like

NSOperatingSystemVersion(10,11,4)

instead of requiring

NSOperatingSystemVersion(majorVersion: 10, minorVersion: 11, patchVersion: 4)

Not only is this new initializer easier to type, but it also much clearer, especially when one is quickly scanning through code.

My changes: https://github.com/rsmoz/swift-corelibs-foundation/commit/e3db7ae2d7f4ba27ae5597e157b41a4b34def468

Also, the Version struct in swift-package-manager has an extension for Comparable, as well as concise initializer:
https://github.com/apple/swift-package-manager/blob/39fdccc74fcb11bc0a352b73fb7e656ba6843ff4/Sources/PackageDescription/Version.swift#L23

Tests: https://github.com/rsmoz/swift-corelibs-foundation/commit/db44f29e42f29ad0fe35f69ac83d853453c77bc6

I’d like to hear your opinions on my changes. For instance, do you think implementing Comparable for NSOperatingSystemVersion would best be done in an extension? That’s how SwiftPM does it.

Best,
Robert Mozayeni
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jordan Rose) #4

Ha! Okay, my bad. I think I mixed up "implementing something already present in C" (like SR-576 <https://bugs.swift.org/browse/SR-576>) with "extending C API in a Swifty way", which certainly needs some kind of review. Sorry about that.

Jordan

···

On Jan 26, 2016, at 15:04, Robert S Mozayeni <dev@mzy.me> wrote:

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I file a proposal: https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I actually draft a formal proposal.


(Jordan Rose) #5

For the record, this seems like a totally reasonable addition to me.

Jordan

···

On Jan 26, 2016, at 15:07, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 26, 2016, at 15:04, Robert S Mozayeni <dev@mzy.me <mailto:dev@mzy.me>> wrote:

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I file a proposal: https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I actually draft a formal proposal.

Ha! Okay, my bad. I think I mixed up "implementing something already present in C" (like SR-576 <https://bugs.swift.org/browse/SR-576>) with "extending C API in a Swifty way", which certainly needs some kind of review. Sorry about that.


(Jacob Bandes-Storch) #6

This feature makes logical sense, and I'm for it, as long as documentation
is clear that it's a lexicographical comparison. I like the simpler
initializer too.

···

On Tue, Jan 26, 2016 at 3:04 PM, Robert S Mozayeni via swift-evolution < swift-evolution@swift.org> wrote:

Discussion is fine, of course, but you should bring this up with Tony or
Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I
file a proposal:
https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I
actually draft a formal proposal.

-Robert

On Jan 26, 2016, at 5:59 PM, Jordan Rose <jordan_rose@apple.com> wrote:

Since the corelibs version of Foundation is meant to match the Darwin
version (for the most part), this is more a question for the owners of the
Darwin Foundation framework (and overlay). Fortunately, they're the same
people maintaining the corelibs port (Tony Parker, Philippe Hausler, and
others), and they have the freedom to make such decisions without going
through the full Swift evolution process.

Discussion is fine, of course, but you should bring this up with Tony or
Philippe on the swift-corelibs-dev list.

Jordan

On Jan 26, 2016, at 3:32, Robert S Mozayeni via swift-evolution < > swift-evolution@swift.org> wrote:

Hello.

I’ve recently forked swift-corelibs-foundation and implemented Comparable
for NSOperatingSystemVersion.

What’s the point of this? Well, in the words of a friend, "It’s a value
type with a clear ordering, why not?”.

I have also added a new initializer that allows something like

NSOperatingSystemVersion(10,11,4)

instead of requiring

NSOperatingSystemVersion(majorVersion: 10, minorVersion: 11,
patchVersion: 4)

Not only is this new initializer *easier* *to type*, but it also much
clearer, especially when one is quickly scanning through code.

My changes:
https://github.com/rsmoz/swift-corelibs-foundation/commit/e3db7ae2d7f4ba27ae5597e157b41a4b34def468

Also, the Version struct in swift-package-manager has an extension for
Comparable, as well as concise initializer:

https://github.com/apple/swift-package-manager/blob/39fdccc74fcb11bc0a352b73fb7e656ba6843ff4/Sources/PackageDescription/Version.swift#L23

Tests:
https://github.com/rsmoz/swift-corelibs-foundation/commit/db44f29e42f29ad0fe35f69ac83d853453c77bc6

I’d like to hear your opinions on my changes. For instance, do you think
implementing Comparable for NSOperatingSystemVersion would best be done in
an extension? That’s how SwiftPM does it.

Best,
Robert Mozayeni
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Robert S Mozayeni) #7

I have drafted a proposal. Feedback is welcome.

https://github.com/rsmoz/swift-evolution/blob/master/proposals/implementing-comparable-on-NSOperatingSystemVersion.md

-Robert

···

On Jan 26, 2016, at 6:07 PM, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 26, 2016, at 15:07, Jordan Rose <jordan_rose@apple.com <mailto:jordan_rose@apple.com>> wrote:

On Jan 26, 2016, at 15:04, Robert S Mozayeni <dev@mzy.me <mailto:dev@mzy.me>> wrote:

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I file a proposal: https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I actually draft a formal proposal.

Ha! Okay, my bad. I think I mixed up "implementing something already present in C" (like SR-576 <https://bugs.swift.org/browse/SR-576>) with "extending C API in a Swifty way", which certainly needs some kind of review. Sorry about that.

For the record, this seems like a totally reasonable addition to me.

Jordan


(Jordan Rose) #8

NSOperatingSystemVersion is a struct imported from C, so you can't add anything to the original declaration. The only thing Swift can do is add extensions. But that doesn't significantly impact the proposal.

I'm not sure it makes sense to cram the initializer in the same proposal but I'll let Philippe comment on that. I don't have any objections to it.

Jordan

···

On Jan 31, 2016, at 19:13 , Robert S Mozayeni <dev@mzy.me> wrote:

I have drafted a proposal. Feedback is welcome.

https://github.com/rsmoz/swift-evolution/blob/master/proposals/implementing-comparable-on-NSOperatingSystemVersion.md

-Robert

On Jan 26, 2016, at 6:07 PM, Jordan Rose <jordan_rose@apple.com <mailto:jordan_rose@apple.com>> wrote:

On Jan 26, 2016, at 15:07, Jordan Rose <jordan_rose@apple.com <mailto:jordan_rose@apple.com>> wrote:

On Jan 26, 2016, at 15:04, Robert S Mozayeni <dev@mzy.me <mailto:dev@mzy.me>> wrote:

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I file a proposal: https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I actually draft a formal proposal.

Ha! Okay, my bad. I think I mixed up "implementing something already present in C" (like SR-576 <https://bugs.swift.org/browse/SR-576>) with "extending C API in a Swifty way", which certainly needs some kind of review. Sorry about that.

For the record, this seems like a totally reasonable addition to me.

Jordan


(Robert S Mozayeni) #9

I've updated the proposal to use extensions.

···

Sent from my tablet

On Feb 1, 2016, at 12:51 PM, Jordan Rose <jordan_rose@apple.com> wrote:

NSOperatingSystemVersion is a struct imported from C, so you can't add anything to the original declaration. The only thing Swift can do is add extensions. But that doesn't significantly impact the proposal.

I'm not sure it makes sense to cram the initializer in the same proposal but I'll let Philippe comment on that. I don't have any objections to it.

Jordan

On Jan 31, 2016, at 19:13 , Robert S Mozayeni <dev@mzy.me> wrote:

I have drafted a proposal. Feedback is welcome.

https://github.com/rsmoz/swift-evolution/blob/master/proposals/implementing-comparable-on-NSOperatingSystemVersion.md

-Robert

On Jan 26, 2016, at 6:07 PM, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 26, 2016, at 15:07, Jordan Rose <jordan_rose@apple.com> wrote:

On Jan 26, 2016, at 15:04, Robert S Mozayeni <dev@mzy.me> wrote:

Discussion is fine, of course, but you should bring this up with Tony or Philippe on the swift-corelibs-dev list.

I discussed this briefly with Philippe through GitHub, and he suggested I file a proposal: https://github.com/apple/swift-corelibs-foundation/pull/240

I’m still interested in getting feedback from the community before I actually draft a formal proposal.

Ha! Okay, my bad. I think I mixed up "implementing something already present in C" (like SR-576) with "extending C API in a Swifty way", which certainly needs some kind of review. Sorry about that.

For the record, this seems like a totally reasonable addition to me.

Jordan