-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
ValueType trait should have a non-panic-ing method #113
Comments
Yes I agree to have a |
Maybe I'm getting it wrong, but the unwrap method isn't used only internally? I feel like using panic-ing code is a bad pratice and shoudn't be suggested, anyway it's a philosophical argument and the deprecation isn't the core of the issue |
Yes. I think if people are using SeaQuery directly, then they'd unwrap() on a Value. let a: i32 = val.unwrap(); And I think it's just like using |
Yes, it's not a best practice but I understand, the difference is that you can check an Option isn't None before unwrapping, can you check a Value before unwrapping? |
Yes, there are some methods |
Ok, like serde_json::Value, there it has also some as_json, as_date_time, etc... methods that returns Option, can be useful to implement, this way people can use directly Ok, you can say those are development problems, I see the panic, fix the error and run again, but if unfortunately I don't find the error before deploying, I'll have panics in production, that isn't a good thing... What I'm trying to say is that developers often do bad things, but it must their fault, not crate's fault for not having given them a way to enforce best practices. At the end we ended up in philosophical... |
Yes sure, this is quite philosophical. I agree with all your points indeed. Having unpredictable panics sounds pretty bad. I'd agree with this proposal. I personally tend to be less opinioned. For example, that's why SeaQuery has support for sqlx, as well as the postgres crate and rusqlite at the same time. |
Sorry for opening so many issues in those days...
Actually the code looks like this:
What I'm proposing is to change it into something like this:
It's never good having panic-ing code around, it's better to have an error type, even if unused on basic operations.
This impl permits retrocompatibility with actual code but gives a deprecation notice, later it should become
Forcing people to switch to the new impl, meanwhile the crate code should have migrated to the Result version of the trait.
Another suggestion, to write and request less code, could be
This would also solve the problem with foreign types implementation (I can't
impl ValueTypeDefault for Option<Something>
because I don't own Option nor ValueTypeDefault), but opens a philosophical question about None being always the correct default forOption<T>
The text was updated successfully, but these errors were encountered: