HISE Logo Forum
    • Categories
    • Register
    • Login

    Breaking change: Remove unqualified definitions & new operator

    Scheduled Pinned Locked Moved Scripting
    2 Posts 1 Posters 503 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Christoph HartC
      Christoph Hart
      last edited by Christoph Hart

      I've been working on the scripting engine for the last days (implementing proper callstacks and local variable dumps when using breakpoints). As a side effect of these efforts, I've removed the possibility to define global variables without the var keyword. So this code:

      var someFunkyVariable = 5;
      
      
      /// hundreds of lines later
      someFunkYVariable = 10;
      
      // hundreds of lines later
      if(someFunkyVariable == 5)
      {
          CrashAndDeleteRootUser();
      }
      
      

      will throw a script error at the second definition:

      Line 5, column 3:  Unqualified assignments are not supported anymore. Use `var` or `const var` or `reg` for definition
      

      . This will help to avoid nasty bugs which are extremely annoying to track down (plus enforce a better coding style). This however is not standard Javascript behaviour (but there is a dialect of Javascript called "strict" Javascript which does the same thing.

      One caveat is that the standard for loop syntax

      also throws an error message, because i = 0 is a unqualified definition. The solution is to just define i once (or as local variable to be 100% thread-safe):

      var i = 0;
      
      for(i = 0; i < 200; i++)
          doSomething();
      
      
      for(i = 375; i < 500; i++)
          doSomethingElse();
      
      
      inline function runsOnThreadOne()
      {
          // Using local variables makes sure that the iterator value is not
          // changed by the other thread
          local i = 0;
      
          for(i = 0; i < 200; i++)
              doSomething();
      };
      
      inline function runsOnThreadTwo()
      {
          local i = 0;
      
          for(i = 0; i < 200; i++)
              doSomethingElse()
      };
      

      I also removed the new operator because it seducts people to use the weirder parts of the Javascript language.

      1 Reply Last reply Reply Quote 1
      • Christoph HartC
        Christoph Hart
        last edited by

        OK, I admit the for loop thing was one bit too much, so I reverted this :)

        You can still use the standard for(i = 0... syntax...

        1 Reply Last reply Reply Quote 2
        • First post
          Last post

        15

        Online

        1.7k

        Users

        11.8k

        Topics

        102.6k

        Posts