Skip to content

Conversation

@patrickfreed
Copy link
Contributor

@patrickfreed patrickfreed commented Apr 15, 2019

SWIFT-268

As part of this update, I refactored the public oid property on ObjectId that returns the string representation to hex, which is more descriptive. It also aligns with Go driver's Hex() and Java driver's toHexString().

I also refactored init(fromPointer:) to init(copying:), similar to the memory leak fix refactors.

@patrickfreed patrickfreed requested review from kmahar and mbroadst April 15, 2019 21:51
Copy link
Contributor

@kmahar kmahar left a comment

Choose a reason for hiding this comment

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

code changes lgtm, couple questions


/// Initializes an `ObjectId` from the provided `String`. Assumes that the given string is a valid ObjectId.
/// - SeeAlso: https://github.com/mongodb/specifications/blob/master/source/objectid.rst
public init(fromString oid: String) {
Copy link
Contributor

Choose a reason for hiding this comment

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

any opinions on whether we should keep this parameter label? I feel like just from is more in line with the rest of the driver, and the String isn't needed to disambiguate from the decodable initializer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree fromString should probably be replaced. In fact, I kind of think the entire initializer should be removed, and init?(ifValid: String) should be the only one, with the ifValid label being replaced with either from or hex or fromHex.

The libbson docs do not mention what happens if bson_oid_init_from_string is called with an invalid string, so I guess we can say it's undefined behavior. I really think we should minimize the amount of UB easily available through our API if at all possible. Thoughts?

Copy link
Contributor

@kmahar kmahar Apr 16, 2019

Choose a reason for hiding this comment

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

I like the idea of having a single failable initializer in the public API. that is consistent with how we handle Decimal128s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored init?(ifValid: String) to just init?(_: String). Let me know if you think it'd be better with a label. Also, removed the un-failable init.

Copy link
Contributor

Choose a reason for hiding this comment

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

I could go either way.... it might be useful as an indicator about the type of string, but maybe that's not that necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mbroadst any strong opinions on this one? I feel like I could go either way too. The one benefit of doing it without a label is that it looks just like it would in the shell, though I doubt we generally make many driver design choices based on how the shell behaves.

Copy link
Contributor

@kmahar kmahar left a comment

Choose a reason for hiding this comment

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

lgtm

@patrickfreed patrickfreed merged commit 8d5eb8b into master Apr 18, 2019
@patrickfreed patrickfreed deleted the SWIFT-268 branch May 7, 2019 16:13
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.

4 participants