webui-dev / v-webui

Use any web browser as GUI, with V in the backend and modern web technologies in the frontend.
https://webui.me
MIT License
112 stars 11 forks source link

Endorse error handling by default #53

Closed ttytm closed 1 year ago

ttytm commented 1 year ago

The proposal utilizes V's function result returns for the wrapping of the C functions that return a boolean that resembles if the function was successfully called.

E.g. a function that might fail, could handle the error simpler and would have to ignore it explicitly.

Current:

// Handle error example:
// Show the window, panic on fail
if !w.show(doc) {
    panic('The browser(s) was failed')
}

// Ignore error:
// Without using the bool return it isn't clear that the function could fail.
w.show() 

Proposed:

/// Handle error example:
// Show the window, panic on fail
w.show(doc) or { panic(err) }

// Ignore error:
w.show(doc) or {}

I think this is a more V native way to handle functions that can fail and would endorse error handling by default and better safety.

hassandraga commented 1 year ago

Thats great. This PR makes the V code smaller and more straightforward.