Programming tips
NAME
Programming tips in Extenso
DESCRIPTION
Module creation
When creating a module there is 3 different locations possible in the root.
toolbox folder is for modules that are meant to be generic and reusable on other clients.
extenso folder is for module specific to the extenso software and core. They are for functionalities of the software and not meant for the front end website.
site folder is for modules developed specifically for the client. These modules are not meant to be reused by other clients.
Modification of files in module
All Extenso module are under the directory /extenso
All Toolbox module are under the directory /toolbox
NO FILE should be modify in there directories unless tou want to create a new version of the module.
What is the difference between ne and !=
Comparaison operators in Sncode have 2 types:
- String comparaison
- Number comparaison
Number comparaison are faster than string comparaison.
It's important to use the right operator for example if we have:
i="0.0";
i ne "0"; // return true
i != 0; // return false
In the first expression i (0.0) is compare with "0" which is not the same.
In the second expression i is compare with "0" but prior the comparaison, the following is perform:
- i is cast to a float using C operator strtod
- the value 0 is then compare to this new float
- The result is the false because 0 is equal to 0.0 in arithmetic
Operators are desfribed here: https://extenso.live/en/documentation/page_operators
Log table or any other table that grow in volume
Should be clean, if possible, automatically after a certain period of time
res = sql("DELETE FROM sed_log_notification WHERE ? != 0 AND
date < CURDATE() - INTERVAL deletin MONTH",
deletein, delete);
Table name
Table name should be prefix with the name of the module.
Table name should be in english.
Table name should not habe plural.
Table name should not have uppercase character and only [a-z_]+
Variables in conf
If you put something like this in configuration file:
variable {
"force_database_engine" : "InnoDB"
}
Then, you can get the value of this variable in Sncode like this:
// In some rare case we need to force database engine 2021-04-13 laplante@sednove.com
c = config();
if c.variable.force_database_engine ne "" then
engine = " ENGINE=" .+ c.variable.force_database_engine;
endif
Error verification
Always check the return value of SQL request:
res = sql(...);
if res.sqlcode != 0 then
res.sqlerr;
stop();
endif
In a loop...
If you have code inside a loop that does not change, put it outside of the loop. For example:
for i sql(...) do
x = run_big_computation();
...
endfor
change it for:
x = run_big_computation();
for i sql(...) do
...
endfo
run_big_computation must not depend on i.
Widget & extenso documentation
quand on ajoute ou modifie un widget, il faut ajouter une description et un video ou des images.
Les videos doivent être déposés sur le site extenso.live/sn_uploads/widgets et il faut ajouter dans la description du widget:
Les vidéos pour la documentation de Extenso doivent être déposés dans extenso.live/sn_uploads/extenso.
On ne met pas les videos à l'intérieur du module car ceci prend trop d'espace disque.
<video controls="" height="480" width="100%"><source src="https://extenso.live/sn_uploads/widgets/widget-button.mp4" type="video/mp4" /> Votre fureteur ne supporte pas les vidéos</video>
AUTHOR
Written by Pierre Laplante <laplante@sednove.com>
Edit