Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing explicitly named operator equivalents #107

Merged
merged 1 commit into from
Aug 29, 2019
Merged

Added missing explicitly named operator equivalents #107

merged 1 commit into from
Aug 29, 2019

Conversation

regexident
Copy link
Collaborator

@regexident regexident commented Aug 6, 2019

With this PR operators now are strictly forwarding functions.

Once https://github.com/mattt/Surge/pull/105 is merged I'll do a rebase and add unit tests for the remaining inout/…inPlace functions.

@mattt mattt self-requested a review August 19, 2019 13:26
Copy link
Collaborator

@mattt mattt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing in-place variants for these operations is a great idea. The only concern I have is that the use of ___InPlace may pollute the top-level namespace unnecessarily. Instead of that suffix, what do you think of a spelling that overloads these with the regular versions of these functions? For example, public func add<L: UnsafeMutableMemoryAccessible, R: UnsafeMemoryAccessible>(_ lhs: inout L, _ rhs: R)? Would that work, or am I missing something obvious about UnsafeMutableMemoryAccessible that makes this approach untenable?

@regexident
Copy link
Collaborator Author

I used …InPlace to prevent subtle bugs introduced by accidentally mixing up producing with mutating variants and also to make the code explicit.

Just like we have + and += and not just +.

Other prior art:

Producing Mutating
n/a + +=
Ruby add add!
Rust add add_assign
Swift subtracting subtract

@regexident
Copy link
Collaborator Author

As I understand it this PR is blocking the others, right?

Calling things adding (aka +) and add (+=) would be most fitting for Swift's naming scheme, but with + already being add, etc this ship has sailed, I fear.

@mattt
Copy link
Collaborator

mattt commented Aug 28, 2019

(Really sorry for dropping the ball on this thread. I finally have another chance to work on this.)

@regexident Yeah, I made the wrong choice when I originally named the APIs (though to be fair, it predates the Swift API Design Guidelines). While it'd be idea for us to adopt a consistent add/adding for mutable / immutable pairs, I think stare decisis — not changing the underlying semantics of existing calls — wins out over idealism.

Maybe we can revisit this with the next major version, but these changes are fine for now.

The only other idea I might offer at this point is, maybe we can sidestep the issue by making the named functions themselves private? I don't know what kind of demand there is for addInPlace to begin with, but if it's addition is primarily in support of the assignment operators, then is there a strong compelling reason to export addInPlace in addition to .+=?

@regexident
Copy link
Collaborator Author

Maybe we can revisit this with the next major version, but these changes are fine for now.

The only other idea I might offer at this point is, maybe we can sidestep the issue by making the named functions themselves private? I don't know what kind of demand there is for addInPlace to begin with, but if it's addition is primarily in support of the assignment operators, then is there a strong compelling reason to export addInPlace in addition to .+=?

This sounds like a good compromise to me! 👍

I'll make them private internal and then we can see if there's demand. I'll update the inventory accordingly.

@regexident regexident merged commit 5f186f0 into Jounce:master Aug 29, 2019
@regexident regexident deleted the in-place branch August 29, 2019 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants