-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Solve error() & panic() "dualism" #2030
Comments
panic() is completely different from error() panic stops the execution of the entire program, error() is for handling Result types. |
What's the real use case of |
|
True, but in the future it'll be possible to recover from panics, just like in Go. @dumblob I'll make it more clear in the docs. |
Well, this is what doesn't make much sense to me - actually having "exceptions" in the function interface is what makes V so good in writing correct programs. But by introducing recover for panic all this endeavor will slip in the languages mainstream and there won't be much to praise V for. In this case I would plead you to think about this twice before you'll allow recovery from panics. How I see it, V has an exception-like mechanism - it's called "optionals", uses What is I have to admit, I'm totally lost by hearing about |
@medvednikov oops, I just woke up.. didn't mean to close it :D, yeah recover was a bad choice of words, since recovering from exceptions is a thing :D Sometimes you need to be able to recover, like if your calling a function you didn't write which panics, but you cant have your program exiting. Something running in a thread might even panic then your up the creek, especially if you keeping count or haven't unlocked a mutex, or any number of nasty things could happen. Of course your really should try not to design your programs like that, sometimes you don't have a choice. |
@joe-conigliaro this must be a misunderstanding, because I totally agree with your last comment with no exceptions 😉. I guess the misunderstanding is on my side in how
Do I understand everything correctly? |
@dumblob your idea about unrecoverable panics is interesting. I'll think about it.
The compiler does not insert |
@medvednikov the compiler could take the "pessimistic" approach by default and expect any code-block potentially to fail (let it be a RAM failure, where some bits shift w/o ECC - I know normally this shall be handled by the Kernel) then it would be safe to add And for panic() I think better would be something like os.exit() with optional err_code/msg |
That's why V should support RAII, so the mutex automatically unlocks before the panic. Doing that by recovering in a higher scope to the one locking the mutex is messy. I think V should allow intercepting a panic, reacting to it in a callback but then the thread that panicked should end. The parent thread can inspect any data written from the panic callback and then |
From my experience I'd say it's vice versa (this concept is widely used in Dao and Go etc. and proved way better than any other concept) - especially if function declaration can be done inside of another function declaration. If "recovering in a higher scope" is the only contra-argument, then I'd say it actually confirms its robustness and viability. Other concepts (including RAII) are hard to optimize if done properly and always clutter the language (this second thing is less important than the optimization issue IMHO though). But V is a simple language, so any complicated concepts are IMHO not a good fit. |
So you're essentially saying that one should be able to observe a |
Found this discussion interesting, but wonder how you could avoid For example, let's say you try to access a element outside an array : a := [1, 2, 3]
println(a[3]) The |
you can now do |
Great, but if you don't do it, What I wanted to know is what would @dumblob suggest to completly remove |
As @Delta456 points out, it actually does return an optional (but if I'm not mistaken, unlike "standard" optional return values, this case is an exception and the handling as optional is not being enforced and thus leaving out If an optional won't work, then there is a simple and clear (well defined) construct - namely runtime |
As I see it, panic() implementation is quite similar to what |
First of all, It's nearly impossible to make Second, V has the there is only one way of doing things mantra which doesn't work here. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
V version:
latest from git
OS:
any
What did you do?
Used "optionals" as return types.
What did you expect to see?
Sane, logical and simple behavior.
What did you see instead?
Weird inconsistency, bloat, etc.
Ideas, suggestions, clarifications, ...
Why do does this "dualism" of
error()
andpanic()
exist? Doesn'tpanic( arg )
behave just likereturn error( arg )
, but being differently type checked thus leading to unnecessary issues?If
panic()
doesn't bring anything new, but offers way less flexibility thanreturn error( ... )
, then I'd definitely advocate for removal ofpanic()
as it's confusing, leads to type checking issues and doesn't bring anything except for complexity.The text was updated successfully, but these errors were encountered: