Giter Site home page Giter Site logo

Comments (3)

heuer avatar heuer commented on September 23, 2024

See also #135

from pywlroots.

flacjacket avatar flacjacket commented on September 23, 2024

Hi @heuer, thanks for the feedback here! The rationale I had for raising an exception here rather than using a return code is channeling Raymond Hettinger's "Beyond PEP 8" PyCon talk, in that we have more naturally suited tools in Python for reporting and handling errors than the underlying C library than return codes. Ensuring return codes are always checked in all clients is more error prone, and if there is clean-up that needs to be done on failure we can encapsulate that here for every use case rather than needing to have that repeated everywhere. Certainly if there are things that we are doing in the attempted clean-up that wouldn't necessarily be the thing that we want to always have happen we can go about changing that.

That said, I'm sure there are cases where return codes would come in handy. In the cases you mention, what would be the benefit of having the return code rather than the exception?

from pywlroots.

heuer avatar heuer commented on September 23, 2024

Thanks for your reply. Acc. to my understanding all applications have to catch the exception since a wayland.Display was already created which have to be destroyed as well:

try:
    server.backend.start()
except RuntimeError as ex:
    # backend was destroyed already, more cleanup necessary
    server.display.destroy()
    raise ex

If Backend.start() just returns a boolean value, it would lead to more, at least in my opinion, elegant code which communicates the intention better.

if not server.backend.start():
    server.backend.destroy()
    server.display.destroy()
    raise RuntimeException("Problem starting backend")

And it would be closer to the wlroots API. At least the fact that the backend tries to destroy itself in case of an error was very surprising for me.

from pywlroots.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.