Detect (more) errors on compile

  1. 5 years ago

    Marc

    13 Mar 2019 User since 2018

    Scenario:

    1. I add a reference to a control in code; eg.: windowTest.buttonTest.
    2. I reorganise the lay-out which results in inserting an extra container ("viewTest") that will have buttonTest as a child; eg.: windowTest.viewTest.buttonTest.
    3. Run or Compile don't complain about this and now I only encounter the error when I do something that triggers that part of the code. This makes it a bit hard to test.

    So it would be nice if these types of errors would be found when doing a compile.

    NB: I have check "Report errors on Null values".

  2. marco

    13 Mar 2019 Administrator User since 2016

    Hi @Marc it would be easier to do in a statically typed language but Gravity is dynamically typed so it is a lot harder and not always possible. For example consider this pseudo code:

    func test() {
       if (isSunday) return 1;
       else return "Hello World";
    }
    
    func main() {
       var s = test();
       return s.length;
    }

    That code cannot be checked at compile time but only at runtime and it will work all the days except on Sunday (because the number type does not have a length property).

    The good news is that a Manifest/Incremental typing will be added to Gravity so more static checks will be performed (typing is necessary if we want to export Gravity code to Swift/Kotlin).

  3. Marc

    13 Mar 2019 User since 2018

    @marco Hi @Marc it would be easier to do in a statically typed language but Gravity is dynamically typed so it is a lot harder and not always possible. For example consider this pseudo code:

    func test() {
       if (isSunday) return 1;
       else return "Hello World";
    }
    
    func main() {
       var s = test();
       return s.length;
    }

    That code cannot be checked at compile time but only at runtime and it will work all the days except on Sunday (because the number type does not have a length property).

    The good news is that a Manifest/Incremental typing will be added to Gravity so more static checks will be performed (typing is necessary if we want to export Gravity code to Swift/Kotlin).

    I understand that. But this scenario has occurred to me several times already. I don't mind the problem scenario in your pseudo code. Maybe you could somehow check breaking code after moving controls; eg. via a warning.

  4. Marc

    15 Mar 2019 User since 2018

    @marco The good news is that a Manifest/Incremental typing will be added to Gravity so more static checks will be performed (typing is necessary if we want to export Gravity code to Swift/Kotlin).

    In the meantime it has bitten me a number of times more. Dynamic typing does seem to make things easier, but honestly it's making it harder as it's much more difficult to prevent (runtime) bugs.

    In other words: can't wait till static typing is there (as much as possible) ..... ;)

or Sign Up to reply!