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

Consider renaming Buf::bytes() and BufMut::bytes_mut() #447

Closed
carllerche opened this issue Dec 7, 2020 · 21 comments · Fixed by #450
Closed

Consider renaming Buf::bytes() and BufMut::bytes_mut() #447

carllerche opened this issue Dec 7, 2020 · 21 comments · Fixed by #450
Assignees
Milestone

Comments

@carllerche
Copy link
Member

carllerche commented Dec 7, 2020

These two functions are named in a way that implies they return the entire set of bytes represented by the Buf/BufMut.

Some options:

  • window() / window_mut()
  • chunk() / chunk_mut().
  • fragment() / fragment_mut()
@carllerche carllerche added this to the v1.0 milestone Dec 7, 2020
@carllerche
Copy link
Member Author

@tokio-rs/maintainers Anyone have thoughts? If there isn't any support for a change here, I am inclined to just let it be.

@Ralith
Copy link

Ralith commented Dec 15, 2020

I agree that the current name could be misleading, and my knee-jerk reaction to window is positive--it's at least ambiguous enough to prompt careful examination.

@Darksonn
Copy link
Contributor

I support changing it to chunk. This is consistent with the naming in std on the slice::windows and slice::chunks methods since our chunks are not overlapping.

@rcoh
Copy link

rcoh commented Dec 17, 2020

As a data point, this personally bit me because I didn't read the docs. It doesn't help that if you have a Chain, I don't think you see the doc on bytes easily from an IDE. I certainly expected .bytes() with no context specified to "magically" give me all the bytes.

Maybe next_bytes()? although that perhaps carries the unwanted connotation that it will advance it

@dekellum
Copy link

NP-hard Question: Is the sum of time saved for new users (by reduced confusion) strictly greater than (>) the one time cost of all downstream existing users changing call names?

@rcoh
Copy link

rcoh commented Dec 17, 2020

I would bet that there are downstream users that will discover buggy code when the name changes...

@dekellum
Copy link

Can we deprecate aliases of old names, to amortize the cost for downstream?

@Darksonn
Copy link
Contributor

We are not going to publish bytes v1.0.0 containing a deprecated method. That's just silly.

@hawkw
Copy link
Member

hawkw commented Dec 17, 2020

We are not going to publish bytes v1.0.0 containing a deprecated method. That's just silly.

I think the idea is that we would publish a point version of 0.6 that adds the new names as aliases to the old ones, and deprecates the old ones, as an "advance warning" to users prior to upgrading to 1.0?

@Darksonn
Copy link
Contributor

That's fine with me.

@dekellum
Copy link

dekellum commented Dec 17, 2020

Yeah, like in the same way that following Semver is silly? My idea was/is to include it deprecated in 1.0, silly be damned. The confusion avoidance is still achieved that way, possibly with even more context to show that the name has changed.

Edit: And your idea, @hawkw, is compatible with mine, but I don't know if that is worth the trouble.

@carllerche
Copy link
Member Author

@rcoh I did consider next_bytes() some. I am worried about the association with Iterator::next which implies that calling the fn implies advancing the cursor.

@rcoh
Copy link

rcoh commented Dec 17, 2020

peek_bytes()?

@Darksonn
Copy link
Contributor

In that case, what about peek_chunk()?

@carllerche
Copy link
Member Author

why not just chunk() and chunk_mut()?

carllerche added a commit that referenced this issue Dec 18, 2020
The `bytes()` / `bytes_mut()` name implies the method returns the full
set of bytes represented by `Buf`/`BufMut`. To rectify this, the methods
are renamed to `chunk()` and `chunk_mut()` to reflect the partial nature
of the returned byte slice.

Closes #447
@dekellum
Copy link

I would bet that there are downstream users that will discover buggy code when the name changes...

Maybe, but for every one of those, there will be two more silly users that will just blindly search and replace rename the method calls. That's certainly my plan! 🥇

Similar to the busy work inflicted by #433, in practical terms.

@seanmonstar
Copy link
Member

We can't save everyone. But, if the changelog entry about the rename mentions "this change was motivated by noticing users frequently misunderstanding how it works", that might convince some of those to consider if they should analyze each place they used it.

@dekellum
Copy link

But if there was a deprecation warning on compile, that warning could say the same, and that might be more noticeable to the more silly users?

@dekellum
Copy link

dekellum commented Dec 18, 2020

Its a trait, so is the deprecation suggestion being ignored more so because its hard to pull off with a trait method?

@seanmonstar
Copy link
Member

I'd be in favor of a deprecation warning, for sure! I think it's trickier for this trait method, since we have to add a default for the new method, and implementors need to include the implementation (I think adding #[allow(deprecated)] on it?)...

@dekellum
Copy link

Well, if its reasonably easy to do, I'm in favor of doing it. +2¢

carllerche added a commit that referenced this issue Dec 18, 2020
The `bytes()` / `bytes_mut()` name implies the method returns the full
set of bytes represented by `Buf`/`BufMut`. To rectify this, the methods
are renamed to `chunk()` and `chunk_mut()` to reflect the partial nature
of the returned byte slice.

`bytes_vectored()` is renamed `chunks_vectored()`.

Closes #447
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants