Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Adopting a common, shared, standard layout style for all the scripts that are written expressions, scripts and macros makes it easier to "read" the scripts them and quickly understand what they are doing.

In general, PhixFlow ignores all spacing around the functional elements however . However spacing and layout makes the meaning much clearer for human readers!

This page provides recommended styles for key functional elementswriting expressions.

General

  • Add comments (// and /* ... */) to scripts
  • Include blank lines between statements
  • Use spaces within expressions
  • Indent sub-clauses by 4 spaces
  • Ensure that attributes which represent the same thing in different Streams, have the same name - this is necessary when doing a Union in a calculate stream but is also important in other types of merge
  • Add descriptions to all models
  • Add descriptions to all model elements. Item properties
    • All items in PhixFlow have a description property. We recommend you add a description to any item you create.
      Anybody looking at a model or application will first look at the descriptions of the
    elements. They
    • items within it.  For example, in an analysis model, they should be able to discern the flow and the high-level logic of the model just from the descriptions.
    Any
    • In analysis models, the stream description should explain the use of
    Input or Output Multipliers should be noted in the stream description (as this
    • input or output multipliers. This it typically a significant part of any model
    )
    • .

Naming conventions

Attribute names should be in camel case starting with an Upper Case Letter i.e. upper case letter for every "sub-word". E.g. MainCompanyName

...

    • Ensure that attributes that represent the same thing in different streams have the same name. PhixFlow needs this when processing merges and for a union in a calculate stream.
  • Formatting expressions
    • Add comments to document your expression using:
      • // for a single line comment
      • /* ... */ to enclose multiline comments
    • Include blank lines between statements
    • Use spaces within expressions
    • Indent sub-clauses by 4 spaces

Naming Conventions

Multi-word stream attribute and pipe names should be in camel case i.e. lower case 1st letter and then an upper case letter for every "sub-word". E.g. $companyOldAddress, inPipe

The names for "global" variables (variables start with a $ character) i.e. variables which have a scope beyond the current expression and are used in subsequent expressions. Global variables should have an upper case first letter e.g. $CompanyLocationCounter.

Layout for if()

if( condition, Statement 1 , // else Statement 2 )

Note that when a statement in an if() clause is more than 1 line, wrap them in a do() e.g.:

if( condition, do ( Statement 1, Statement 2, .... Statement n ) , // else Statement A )

Note that closing brackets should always line up with the start of the statement (see the do() and if() statements above)

Layout for switch()

switch( [ condition expression 1, Statement 1 ], [ condition expression 2, Statement 2 ], // default _NULL )

Note that the _NULL statement is currently required

...

.

Excerpt
  • All user-defined variables must start with the $ character. 
  • For multi-word variable names, use no spaces and camel case.
  • It can be useful to know whether a variable is used in other expressions. As there is no way to check this, we recommend using the following naming convention:
  • To distinguish between $-variables that are:
    • only used in the current expression or attribute, use a lowercase first letter, for example $percent
      These are sometimes called local.
    • used in other expressions or attributes, use an uppercase first letter, for example $Percent.
      These are sometimes called global


Examples
stream attributeMainCompanyName
pipeinPipe
global $-variable$CompanyLocationCounter
local $-variable$companyOldAddress


Tip

Camel case uses an uppercase letter for the start of each sub-word, for example $ThisIsCamelCase. As we recommend having no spaces, this makes the name readable.

Adding Comments

It is always a good idea to add comments to your scripts to explain its steps. Comments help anyone who needs to modify the script in future.

There are two ways to tell PhixFlow that a line is a comment, and can be ignored.

NotationUse for
//

 short comments up to 1 line

/* <comment> */multi-line comments

Comments are not evaluated when the code is run.

Code Block
titleExample 1
/* Get the discount rate that should apply to 
the calls that match the filter conditions */

$discountRate = discount.rate,

// Now apply the discount

$value = $value * ( 1 - $discountRate)


Code Block
titleExample 2
if(_out.AppleHarvestDate < _toDate('20210101'), 1,
    /* Evaluates to 1 if AppleHarvest Date is Before 1st January 2021*/

0
    /* and to 0 if it is not */

)

Layout for if() 

if( condition, Statement 1 , // else Statement 2 )

Code Block
if( condition, Statement 1, 
// else 
    Statement 2 
)

When there is more than one statement in an if() clause, wrap the statements in a do().

Code Block
// Example code layout 
if( condition,
    do(
        Statement 1,

        Statement 2,

        .... Statement n
    ),

// else
    Statement A
)

To make it easier to see that statements are correctly bracketed, the closing bracket should always line up with the start of the statement.

Layout for switch()

Code Block
switch( 
    [ condition expression 1, Statement 1 ], 
    [ condition expression 2, Statement 2 ], 

// default _NULL 
)

The _NULL statement is required.