PhixFlow Help

Scripting Style

Adopting a common, shared, standard layout for all the scripts that are written makes it easier to "read" the scripts and quickly understand what they are doing. In general PhixFlow ignores all spacing around the functional elements however spacing and layout makes the meaning much clearer for human readers!

This page provides recommended styles for key functional elements.

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. Anybody looking at a model will first look at the descriptions of the elements. They should be able to discern the flow and the high level logic of the model just from the descriptions. Any use of Input or Output Multipliers should be noted in the stream description (as 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

The names of all local variables (variables start with a $ character) 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()

Simple

For simple if() statements we recommend the following style of layout:

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

// Example code layout 
if( condition expression,
    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)

Complex

For more complex if() statements we recommend the following style and that comments are added:

// Short description on what is being achieved when the if statement is true
if ( $foo > 10 &&
     $bar == "X" &&
      ( $baz == "Y" ||
         $qux == "Z" ),

			// description of what the statement is doing
      		do (
      				Statement 1
      		),

// else, description of what the statement is doing
	Statement 2
)

Layout for switch()

Simple

For simple switch statements we recommend the following layout:

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

// default
    _NULL
)

switch( 
	[ $foo > 100, $x = "HIGH" ],
	[ $bar > 50,  $x = "MEDIUM" ],

	// default
    $x = "LOW",
)


Advanced

For switch statements that perform more advanced activities we recommend the following layout:

switch (
      // description of what the statement is doing
      [$foo == 100,
           $x = "HIGH"
      ],

      // description of what the statement is doing
      [$bar == 50,
           do (
                 $x = "Medium",
				 $x = toUpper($x)
           )
      ]
      
      // default
      do (
           $x = "LOW"
      )
)





Please let us know if we could improve this page feedback@phixflow.com