Skip to content

Allow non-deprecated removeMember/removeIndex with null return pointer #689

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

Closed
wants to merge 1 commit into from

Conversation

wolframroesler
Copy link
Contributor

Sometimes we just want to remove something we don't need anymore. Having to supply a return buffer for the removeMember/removeIndex function to return something we don't care about is a nuisance. There are removeMember/removeIndex functions that don't need a return pointer but they are deprecated. This commit allows the non-deprecated versions to be called with a null pointer as the last argument to simplify things for callers who don't need to get something back.

For example:

Json::Value j;

j.removeMember("name"); // nice but deprecated

Json::Value r; j.removeMember("name",&r); // possible but annoying

j.removeMember("name",nullptr); // possible with this commit

Note: Implementation only (albeit very trivial), no test coverage.

Sometimes we just want to remove something we don't need anymore. Having
to supply a return buffer for the removeMember/removeIndex function to
return something we don't care about is a nuisance. There are remove-
Member/Index functions that don't need a return pointer but they are
deprecated. This commit allows the non-deprecated versions to be called
with a null pointer as the last argument to simplify things for callers
who don't need to get something back.

For example:

Json::Value j;

j.removeMember("name"); // nice but deprecated

Json::Value r; j.removeMember("name",&r); // possible but annoying

j.removeMember("name",nullptr); // possible with this commit
@BillyDonahue
Copy link
Contributor

I feel it would be better to just un-deprecate the unary member functions if they're useful.
Optionally-null pointer parameters produce more a complex contract and leave cold branches.

@wolframroesler
Copy link
Contributor Author

@BillyDonahue I agree :) but I'm afraid they were deprecated for a reason. OTOH, the functions that receive the removed pointer should handle nullptr gracefully regardless of the unary functions, because why would they take a pointer instead of a reference in the first place?

@BillyDonahue
Copy link
Contributor

Well, there are lots of invalid pointers in the memory space, and we can't handle them all gracefully, so I don't like going out of my way to Nerf just the invalid nullptr argument.

As for why it's a pointer instead of a reference, I suspect it was just a style choice to make the mutability more obvious at the call sites (matching, e.g. Google style).

I wonder about the deprecation. I can't think of a reason for it so maybe it's reversible. That's a better API change than adding a new function IMO because it's not really an API change at all!

@cdunn2001
Copy link
Contributor

I'm not positive, but I think those were deprecated because of their misleading return values. They returned nullValue if missing, but that is a valid value.

I guess we could undeprecate, but only to return nothing. I gues returning bool would be ok too, but since the old version returned a real thing, I think void is better. If you actually want the removed value, then pass a pointer. (A reference would obscure the side-effect.)

@wolframroesler
Copy link
Contributor Author

Can we simply change the functions to return void instead of a value? This could break client code. If it's ok by you, I'll submit it as a new pull request.

@cdunn2001
Copy link
Contributor

If I were you, I would simply re-use this branch and this pull-request, after rebasing. git push -f origin master

@wolframroesler
Copy link
Contributor Author

I'm a bit reluctant to force push a branch that was pushed already. Also, should have used a branch in the first place, instead of editing on master. Submitted a new pull request: #693

@cdunn2001
Copy link
Contributor

@wolframroesler, yes, if you use feature-branches, then you'll have less worry about a force-push. Anyway, I'll merge the new PR after the minor bug is fixed and the tests pass. Thanks.

@cdunn2001 cdunn2001 closed this Oct 16, 2017
@wolframroesler
Copy link
Contributor Author

Too good I decided not to follow your advice about the force push ... :-)
http://www.monkeyuser.com/2017/it-hell/

cdunn2001 pushed a commit that referenced this pull request Oct 18, 2017
* Un-deprecate removeMember overloads, return void

Sometimes we just want to remove something we don't need anymore. Having
to supply a return buffer for the removeMember function to return something
we don't care about is a nuisance. There are removeMember overloads that
don't need a return buffer but they are deprecated. This commit un-deprecates
these overloads and modifies them to return nothing (void) instead of the
object that was removed.

Further discussion: #689

WARNING: Changes the return type of the formerly deprecated removeMember
overloads from Value to void. May break existing client code.

* Minor stylistic fixes

Don't explicitly return a void value from a void function. Also, convert
size_t to unsigned in the CZString ctor to avoid a compiler warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants