-
Notifications
You must be signed in to change notification settings - Fork 46
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
Panic feature flag #80
Comments
I personally consider the usage of unwrap/panic inside a library a grave anti-pattern. It hides error states that should be explicitly checked or accounted for by the user without him knowing using the API (since the unwrap/panic is onyl visible inside the library code or in the best case documented in the API documentation). The current
Both variants of
|
Since you're linking guidelines from 6 years ago, my view on the topic aligns with nikomatsakis' comment in the RFC (emphasis mine):
I think the ecosystem in which shipyard will mostly be used also has its importance. Rapid prototyping that panics is a valid use case. The
That's not the way the std or the Rust ecosystem in general works though, even the RFC you linked suggests:
In shipyard, almost all errors are "contract violation"s, except when it's related to a storage borrow. Even in case of storage borrow errors, I'd argue it's still a contract violation most of the time since you control the whole application and you should make sure not to make an invalid borrow even across threads. That's what workloads automatically do after all. For
I want
I don't understand. The new api-guidelines are more moderated about what they advise to do, it's not an easy topic after all. |
People can just call
I would say that using
Even if it's a contract violation, it could we very well be that it's cause by faulty business logic and you don't want to bring down your whole server system because of this. I think my biggest problem with this is the implicity of the faulty operation (and me not expecting
This could indeed work.
I think I meant that Sorry if I worry too much, but I have a deep background in writing server software and implicit behavior that could bring down a system is a big pain point of mine. I have to agree that my use case of shipyard is very specific and that my deep background in GO doesn't help either... There the usage of I feel like I'm the devils advocate yet again. |
It can't sadly, pub trait Index<Idx: ?Sized> {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
} But when a tuple is returned the reference is in the inside, it can't be modeled with Not using While an ECS is flexible it's still mainly meant for games and the api will facilitate this usage more than others. If panics are such a big deal for you, this issue should be a plus for you, no? |
@leudz I refactored my codebase to After having slept the night over it, I just wished that a potential unsafe function should be marked so in the function signature. So the default is the safe function, but if somebody needs to have an unchecked version that could panic (that could be potentially faster?), call the |
I had the same conversation with @colelawrence on zulip a couple of days ago. I think there are instances where the panic version will be faster but I can't remember which function. |
Shipyard offers alternative
try_*
version of all fallible functions.However it's not always easy to spot a function that could panic while reading code or during code review as @colelawrence pointed out.
It's especially bad in some cases like
get
when a function with this name usually doesn't panic.To solve this problem all functions that could panic will be feature gated.
It will be a default feature so all users that don't disable them won't see any change.
The text was updated successfully, but these errors were encountered: