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

Create class ByteVecValue from typedef #2368

Merged
merged 5 commits into from
Jul 1, 2021

Conversation

eric-hughes-tiledb
Copy link
Contributor

@eric-hughes-tiledb eric-hughes-tiledb commented Jun 19, 2021

This PR is a transitional change toward eliminating untyped variables. It converts typedef ByteVecValue into a class. It has a number of methods to substitute for existing patterns of use, hiding implementation details and highlighting the results. Not all of these can be changed in this initial PR. In some cases no class exists that would adequately capture how the variable is being used. In other cases there are interactions with untyped read/write from buffers that need modifications in those classes.

A number of vector methods are forwarded for legacy behavior. Not all of them could be, but notably there's no more use of operator[]. It is not a goal of this PR to eliminate all of them; it will have to be a multi-step process.

The scope of this PR is to make just the changes already here. It's intent is to be pure refactoring, with zero changes in behavior.


TYPE: IMPROVEMENT
DESC: Create class ByteVecValue from typedef


class ByteVecValue {
typedef std::vector<uint8_t> Base;
std::vector<uint8_t> x;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the tiledb convention is to always use underscore suffixed member variable names, i.e. 'x_'.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed this is the convention elsewhere in the code.

explicit operator bool() const noexcept {
return !x.empty();
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal Opinion...
I personally find the code making use of this operator bool() less readable than the ref's to some mnemonic function (as with the prior use of ref's to '.empty()' or its negation) would be (was.)
Unless there's some well-known convention I'm simply not familiar (enough?) with (intuitiveness being really related to what one is familiar with), it's generally not intuitive to the world at large (or is it just me?) what assert()ing or if()ing a given variable may really mean, so reading code, it's necessary to know/remember what that operator bool() was actually coded to represent, i.e. what does 'true' or 'false' actually mean for some arbitrary (typed) variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Conversion to bool has been embraced by C++ generally. "True" means "present" and "false" means "absent". It's a generalization of the use of a pointer as a boolean. It's now also used in the standard library for smart pointers and optional, both of which define operator bool.

More importantly, this class is transitional. None of these uses should be here at all within a few months.

@eric-hughes-tiledb eric-hughes-tiledb force-pushed the eh/create-transitional-ByteVecValue branch from e2e0340 to c2b5cd4 Compare June 24, 2021 12:55
Copy link
Member

@Shelnutt2 Shelnutt2 left a comment

Choose a reason for hiding this comment

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

One minor comment besides that lgtm. This is a great incremental patch as we work towards the larger refactoring, thanks!

@Shelnutt2 Shelnutt2 merged commit 91ddacc into dev Jul 1, 2021
@Shelnutt2 Shelnutt2 deleted the eh/create-transitional-ByteVecValue branch July 1, 2021 13:32
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.

None yet

3 participants