Skip to content

CXX-1817 Rename get_utf8() to get_string() to make it more user-friendly #721

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

Merged
merged 6 commits into from
Sep 14, 2020

Conversation

rayangler
Copy link
Contributor

@rayangler rayangler commented Sep 9, 2020

Most of the changes include switching most calls to get_utf8() with get_string().

There are instances where BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN (and its corresponding closing macro) were used on calls to get_utf8() (or get_##name()) in order to not trigger the deprecation warnings/errors on Evergreen.

@rayangler rayangler marked this pull request as draft September 9, 2020 21:31
@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2020

Codecov Report

Merging #721 into master will decrease coverage by 1.26%.
The diff coverage is 95.38%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #721      +/-   ##
==========================================
- Coverage   94.28%   93.01%   -1.27%     
==========================================
  Files         357      357              
  Lines       18655    19142     +487     
==========================================
+ Hits        17588    17805     +217     
- Misses       1067     1337     +270     
Impacted Files Coverage Δ
src/bsoncxx/builder/core.cpp 87.31% <ø> (ø)
src/bsoncxx/test/bson_get_values.cpp 100.00% <ø> (ø)
src/bsoncxx/types/bson_value/view.hpp 100.00% <ø> (ø)
src/bsoncxx/types/private/convert.hh 97.56% <ø> (ø)
src/mongocxx/index_view.cpp 93.02% <0.00%> (-2.22%) ⬇️
src/mongocxx/test/spec/crud.cpp 91.13% <80.00%> (ø)
src/mongocxx/test/spec/util.cpp 89.39% <85.71%> (ø)
src/mongocxx/test/spec/command_monitoring.cpp 87.23% <90.00%> (ø)
examples/bsoncxx/view_and_value.cpp 97.29% <100.00%> (ø)
examples/mongocxx/get_values_from_documents.cpp 91.30% <100.00%> (ø)
... and 43 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3126f18...eb722a6. Read the comment docs.

@rayangler rayangler marked this pull request as ready for review September 14, 2020 14:37
Copy link
Contributor

@bazile-clyde bazile-clyde left a comment

Choose a reason for hiding this comment

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

Great work! LGTM!

@@ -646,12 +647,15 @@ core& core::concatenate(const bsoncxx::document::view& view) {

core& core::append(const bsoncxx::types::bson_value::view& value) {
switch (static_cast<int>(value.type())) {
// CXX-1817; deprecation warning suppressed for get_utf8()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

BSONCXX_DEPRECATED types::b_utf8 get_utf8() const;

///
/// Getter for elements of the b_utf8, or string, type. This function acts as a
Copy link
Collaborator

Choose a reason for hiding this comment

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

The spirit of the requested change is to make it easier for users to find out how to get strings from BSON documents.

There are other types / enums with utf8 in the name:

  1. The bsoncxx::b_utf8 struct
  2. The k_utf8 value in the bsoncxx::type enum (generated by including src/bsoncxx/enums/type.hpp)
  3. The k_need_element_type_k_utf8 and k_cannot_append_utf8 error codes (also generated by including src/bsoncxx/enums/type.hpp)

We could deprecate (1) in favor of a newly named bsoncxx::b_string struct. But I'm not aware of a portable C++11 way to deprecate enum values for (2) and (3).

I think we should do one of two things:

  1. Deprecate the b_utf8 struct for a new b_string equivalent. And add *_k_string equivalents for the error codes and enum value. Otherwise we'll have element::get_utf8() deprecated, but users will still be required to use types / error codes with utf8. The error codes and enum value would need to be equal to avoid a backwards breaking change
  2. Leave get_utf8() undeprecated and just have get_string as an alias.

I have a slight preference for (2). My rationale is that it is extra work for users to move from deprecated to undeprecated API. Having the get_string helper still makes it easier for new users to find the API they want. And we can always choose to deprecate it later if need be.

Happy to chat about this further in slack/zoom.

Copy link
Collaborator

Choose a reason for hiding this comment

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

After discussion, we'll do option 1, but as follow-up work in CXX-2109.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM!

@rayangler rayangler merged commit 7ccc2d4 into mongodb:master Sep 14, 2020
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