Post a Reply
3628 views

Detect (more) errors on compile

  1. 5 years ago

    marco

    Show in context 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).

  2. Marc

    Show in context 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.