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

Position is actually not optional #359

Closed
wants to merge 1 commit into from

Conversation

fraillt
Copy link

@fraillt fraillt commented Apr 10, 2024

Hello,

While investigating in which cases it is safe to unwrap position , I came to conclusion that it is actually always present.
There's exactly two places that it was None before:

  • while creating ByteRecord - now it defaults to Position::new() which totally makes sense
  • while returning ErrorKind::UnequalLengths from writer - I wrote a comment on a type, that for writer position is not tracked.

Even though it makes things easier to use and reason about (no need to unwrap anything, or handle None case that will never happen), this is however breaking change for the end user...

@BurntSushi
Copy link
Owner

This is a plausible choice to make in the design of this crate, but I felt it was more important to represent absence of a position rather than lie about it if the position isn't available or hasn't been set yet. The alternative isn't really this PR IMO, but rather, to make construction of a record require a Position provided by the caller. But that's somewhat annoying too, and not always relevant.

But even separate from the design question, even if I conceded this PR was 100% unambiguously better, there's no way I'm putting out a csv 2 just for this change. In general, you should discuss breaking changes before submitting PRs for them. Especially for projects with a non-zero major version.

I'd suggest opening an issue about this and talking about the trade offs. I can consider it if and when a csv 2 is ever released.

@BurntSushi BurntSushi closed this Apr 10, 2024
@fraillt
Copy link
Author

fraillt commented Apr 11, 2024

Everything is fine, I didn't expected it to land either, I just wanted to bring attention about it :)
Sometimes it makes things easier to discuss when you can evaluate work needed and what exactly is affected in advance.
Just in case, it's not clear, it was mostly compiler-driven-development, so it's really low effort PR.

Regarding creating an issue I'll leave it up to you :)

If you already have a list of "nice-to-have" breaking changes for csv 2, I would strongly suggest to remove optional from position as well, as it makes user code a lot cleaner and simpler (there are code bases, that doesn't allow to unwrap things, so you can imagine the burden on end users to always handle situation, that never happens.)

In my opinion, this PR also suggest that splitting ErrorKind (or part of it) for writer and reader would also be "nice-to-have", if you don't want to "lie about it if the position isn't available".

@BurntSushi
Copy link
Owner

Aye understood. Makes sense. I appreciate it.

there are code bases, that doesn't allow to unwrap things

Yeah, I don't really think this is good practice. And I don't ever plan to spend any effort making this sort of thing easier or nicer. See: https://blog.burntsushi.net/unwrap/

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.

2 participants