Differences Between Regular JavaScript and Provengo JavaScript

While Provengo’s JavaScript variant is very similar to mainstream JavaScript, some differences exist. Some of these issues are due to the fact that when working with Provengo, you create models rather than programs. This drives a lot of changes in the threading models, data comparison approach, etc.

  • BThreads should never exchange data directly or though common data structures. They can only exchange data using events or bp.store.

    • This means no changing global variables. It is perfectly OK to READ them, but don’t write to them.

      • Use bp.store if you need a common place to store mutable data.

  • In bthreads, do not use JavaScript’s arrow functions ((a)⇒bcd). Use the traditional syntax instead (function(a)\{bdc;\}).

  • let vs const

    • In the global program scope, prefer const.

    • In bthread bodies (and more generally, in code that can run within bthreads), always use let.

  • When comparing events (e.g. for a bthread deciding how to advance, when creating a script/manual test, or when evaluating an ensemble), prefer the use of contains to equals or ==. So e1.contains(e2) is better than e1==e2 or e1.equals(e2).

  • In order to maintain small scenario space, do not use let in loops. Instead, define the variable above the loop and set it to undefined. Then, set it to undefined at the end of the loop’s body.

    // bad:
    while (true) {
        let e = waitFor(any(/shmoop/));
        request(Event(e.data.moop));
    }
    
    // good:
    let e = undefined;
    while (true) {
        e = waitFor(any(/shmoop/));
        request(Event(e.data.moop));
        e = undefined;
    }
  • Using sync points as arguments to methods/boolean condition might not work (e.g. anArray.push( waitFor(es) ) fails to serialize.