How to program in Grimport?

Ask us for help with programming in Grimport TRANSLATE THIS PAGE

To Go Further

 

Good coding practices


Naming a variable correctly

The name of your variable should represent its content:

  • Use clear names even if they are long.
    If you need to create a variable of a quantity of items in stock, instead of quantity, write quantity_in_stock
  • Follow a common naming convention.
    • Use underscores (_) for variables consisting of multiple words, such as number_of_cars, final_response, etc
    • You can also use the CamelCase notation for variables which consists in starting each word with a capital letter: MyVariableWillBeWrittenLikeThis
  • Use only alphanumeric characters and underscores... and no accents!
    For example, write hello_1 but not hello_#1
  • Remember that variable names are case sensitive.
    age, Age and AGE are three different variables
  • Copy and paste variable or function names rather than rewriting them (avoids typos).
  • Do not use the same name for two local variables in different blocks.

 

Code layout

To easily find your way around your code, it is advisable to make a good layout. Here are some tips:

  • Put spaces after commas and space out multiple parentheses
    phpBigCommand( functionNow("all_product", [id_categorie_product, global.get("references"), id_supplier, 3, "stock_to_0", true]) )

    Instead of:

    phpBigCommand(functionNow("all_product",[id_categorie_product,global.get("references"),id_supplier,3,"stock_to_0",true]))
  • Indent the code correctly: within each block, use Tab (Shift+Tab for reverse)
  • Uniformity of the blocks: the brace comes under the if/for/while and not at the end of the line
    //We prefer to write 
    if (condition)
    {       
    	...  
    }
    
    //instead of
    if (condition) {  
       ...  }

    For the each, it is the same principle

    //We prefer to write 
    cleanSelectAll("p").each   
    { paragraphe->  
        ....
    }
       
    //instead of
    cleanSelectAll("p").each{ paragraphe-> 
         ....   
    }
  • and don't forget to comment

 

 


❮ Previous