Giter VIP home page Giter VIP logo

Comments (2)

DirkSonguer avatar DirkSonguer commented on May 13, 2024 1

Errors out of constructors are Exceptions 😅

Exceptions are only magic if you use them only once or twice and they come as a surprise. If you are using them throughout then they can be expected and people should code for it. As for error codes: This is what exception types are for.

If you want to avoid them at any cost, then I agree that having a separate StereoKitApp.Init() function would better mirror the C behavior:

        public StereoKitApp()
        {
                // This would be empty now? 
        }

        public Init(string name, Runtime runtime)
        {
            return sk_init(name, runtime);
        }

Then I would appreciate blocking any other functionality until the initialization is done, so some kind of public bool isInitialized for me to check.

What do you think?

from stereokit.

maluoi avatar maluoi commented on May 13, 2024

Something is definitely needed here! I remember writing that example and thinking, 'Huh, I can't check errors out of a constructor, can I?'. Then I moved on. There's definitely a lot of error checking I've deferred so far, it would be really nice to have a good logging system too.

I'm not a fan of catching exceptions, it falls into the realm of 'Magic! Where Did That Functionality Come From?' to me. So I generally try to avoid throwing them unless I actually intend to crash an application. I much prefer error codes!

So I think the core trouble here is that the constructor is doing a little too much work! I think my preference would be either a static StereoKitApp.Create() that can return null, or an instance member StereoKitApp.Initialize() that can return an error code. That and better logging :)

from stereokit.

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.