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;\}
) (yeah, we know, we’re working on it). -
let
vsconst
:-
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
toequals
or==
. Soe1.contains(e2)
is better and more robust thane1==e2
ore1.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 toundefined
. Then, set it toundefined
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) )
might not work well withanalyze
.