-
Notifications
You must be signed in to change notification settings - Fork 125
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
Move file-specific options under OutFile #529
Conversation
I'm having second thoughts about this. While it makes sense for the options to be part of OutFile, it does make it more cumbersome to use with no real benefit. I'll convert to a draft and see if anyone else wants to weigh in. |
I think this refactor makes sense in the context of applications that use OxiPNG as an intermediate optimization engine, which is a use case that the new raw API supports quite well. Asking those applications to pass options about whether to back up files when there are no files to begin with is semantically odd. How do you think users will be affected by this refactor? If it only slightly complicates internal OxiPNG code, I think the cleaner client code it allows in some cases is worth it. |
My concern was that while the Options can just be filled with defaults (so you don't have to explicitly set everything), the associated values on an enum variant necessarily have to be provided. So if you're using the oxipng file API, you're now required to set those explicitly whereas before you weren't. This isn't an issue for the Pretend option, just the backup and preserve_attrs. We could always go ahead with changing Pretend and leave the others for now, if we wanted. |
Right, I hear your concern. How about moving the inner enum variant fields to their own structs, as this StackOverflow question suggests? If you find that approach too unergonomic, perhaps adding constructor functions like |
I actually did add I just had another thought though: What if we deprecate/remove the backup option entirely? I feel it's a little archaic and unlikely that people actually use it. It's really a separate issue, but if it is something we want to do then it would affect what happens in this PR. |
I'd support removing the backup option, as I think backups are handled by other programs better than OxiPNG could ever do, but it'd be nice to gather some user feedback about that. I have the feeling that users of Unix-like OSes would approve that, while Windows users are more used to the "every program must do every feature any reasonable user could want from it" way of defining scope. |
Alright, I've reverted the backup flag so it remains in the Options struct. That makes OutFile::Path a little simpler and I do feel better about it now. We can discuss removing backup separately. |
@shssoichiro This PR and #546 are the last things on my to-do list for the next release. Once these are either merged or closed (depending on how you feel about them), I think we can do another release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these changes are good overall, but I'd like to address the potential removal of the backup
option, which directly affects them.
My reading of the current state of the RFC at #542 is that there is no strong user opinion for or against removing backup
, with the slightly more popular opinion being that it's okay to remove backup
. There may be some use cases where it is useful, and the only technical concern with it at the moment is that it makes the OutFile::Path
anonymous struct more complex.
However, this struct already contains two fields, and refusing to add more because of complexity is not a precedent that scales well. A third backup
field should make no ergonomic difference, and thus it should not be a reason to remove backup
. I think the from_path
convenience function takes care of this well enough.
I do still think that backup
is mostly unnecessary these days, but all of this makes me feel it would be better to either not remove it, or to deprecate it for removal at the next release after the upcoming one. With a deprecation notice, we could hopefully get more user feedback about it, and give any folks out there who depend on it time to move on.
Since the backup code is otherwise simple and unlikely to be a source of future maintenance effort, unlike deprecating an option for removal, I think it's best for everyone if we move backup
to this struct and leave it alone.
Thanks for the review @AlexTMjugador! You make some good points.
This is true. The ergonomics wasn't so much a motivating factor for removing backup though, it was just what prompted the thought. If we do want to keep it, it could certainly go in here. I guess regarding scaling, enum options with associated values inherently don't scale well. Adding a new option is necessarily a breaking change, whereas with the main options it generally isn't. If we want this to be scalable we should probably go the embedded struct route you suggested earlier, but at this point I think that may be overkill.
Yeah, deprecation could be a good option. Though I think if we do deprecate it, with expectation to remove in a future version, it would seem awkward to move it in the interim. I'm not sure it's reasonable to mark associated values in an enum variant as deprecated, since you're still forced to provide them (at least if you're not using I'm not hugely opinionated on any of this one way another though. We could just close both PRs and keep the status quo if it's easier than figuring out what's best 😆 |
I thought a bit more about the whole idea of removing the I'd be bold and go ahead with moving |
Ah, so you don't want to deprecate it? I still think it would be good to get rid of it someday, even if not today. We could still mark it deprecated in the CLI regardless of what we do in the API, to gather more feedback like you said (no API user in their right mind would be using it 😂). |
Hmm, I certainly didn't entertain the possibility of separating the API from the available command-line flags. From an API perspective, I'd just remove the flag (it's barely useful there as you said), while from a CLI perspective I'd be more conservative. How easy do you think it'd be to make the API interface less coupled with the CLI switches? If it's elegant to do, I think the best way forward would be to deprecate it in the CLI, and remove it altogether from the API. |
Ooh, that's a good idea. I think that could be done for the backup switch, I'll give it a go. |
My 2¢ as a CLI user: |
Yeah, that's also a good point. And even without I think those are our two best options right now. To sum up:
Either way it wouldn't be in the API. Which means this PR is probably good to go as-is, since changes to backup would be unrelated. |
Another reason to remove backup: It currently crashes if the input file has no extension 😂 |
I like that idea, especially given that this feature also has the somewhat glaring bug you have just described, and fixing it would likely prompt a debate on how to handle files without extensions 😂
Yeah, I think so too. I'll go ahead and merge this! |
This PR is addressing shssoichiro#220. It's not super important but it's a breaking change, so if it's something we want to do then I thought I should get it in now before the next release. - [x] pretend can become another variant of OutFile, probably OutFile::None, as that's what it essentially is - just another output destination and not a separate option - [x] ~~backup and~~ preserve_attrs should become properties of OutFile::Path variant (so that it would contain Path { path, ~~backup,~~ preserve_attrs }) as they don't have any effect on any other output and so semantically belong there best Closes shssoichiro#220
This PR is addressing #220. It's not super important but it's a breaking change, so if it's something we want to do then I thought I should get it in now before the next release.
backup andpreserve_attrs should become properties of OutFile::Path variant (so that it would contain Path { path,backup,preserve_attrs }) as they don't have any effect on any other output and so semantically belong there bestCloses #220