1 / 23

Conventions to be used in Modgen models

Conventions to be used in Modgen models. by Claude Charette Claude.Charette@statcan.ca Workshop for Modgen users May 27th, 2008 www.statcan.ca/english/spsd/Modgen.htm. Goals of usage of conventions. Better understanding of code Team work Cooperation between different teams

micheal
Télécharger la présentation

Conventions to be used in Modgen models

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Conventions to be used in Modgen models by Claude Charette Claude.Charette@statcan.ca Workshop for Modgen users May 27th, 2008 www.statcan.ca/english/spsd/Modgen.htm

  2. Goals of usage of conventions • Better understanding of code • Team work • Cooperation between different teams • Bugs waiting to happen

  3. Categories of conventions • Names of Modgen symbols • Names of variables • Code layout • Other layout conventions specific to Modgen • Bugs waiting to happen

  4. Names of Modgen symbols • Principles to follow when choosing conventions: • Must help avoid collisions between names of different symbols • Must help in recognizing kind of symbol • Must not pollute the model’s interface

  5. Symbol categories

  6. Names of variables • Local variables, global variables, function arguments

  7. Code layout • Only one instruction per line • Indentation • Using curly brackets • Meaningful names

  8. Code layout (continued) • Only one instruction per line Bad example: voidSimulation(){int nCase;for ( nCase = 0; nCase <CASES() &&!gbInterrupted &&!gbCancelled &&!gbErrors;nCase++ ){StartCase(); CaseSimulation(); SignalCase(); }} Good example: voidSimulation(){ int nCase; for ( nCase = 0; nCase <CASES() &&!gbInterrupted &&!gbCancelled &&!gbErrors;nCase++ ){ StartCase(); CaseSimulation(); SignalCase(); }}

  9. Code layout (continued) • Indentation • Blocs left aligned • Subblocks shifted to the rigth Bad example: classification LANGUE2 {//EN francophoneL2_FRANCO,//EN non francophoneL2_NON_FRANCO}; Good exemple: classification LANGUE2 { //EN francophone L2_FRANCO, //EN non francophone L2_NON_FRANCO};

  10. Code layout (continued) • Using curly brackets • Opening bracket on separate line • Brackets left-aligned with parent block Bad example: classification LANGUE2 {//EN francophoneL2_FRANCO,//EN non francophoneL2_NON_FRANCO}; Good exemple: classification LANGUE2 { //EN francophone L2_FRANCO, //EN non francophone L2_NON_FRANCO};

  11. Code layout (continued) • Using curly brackets Bad example: voidSimulation(){ int nCase;for ( nCase = 0; nCase <CASES() &&!gbInterrupted && !gbCancelled &&!gbErrors;nCase++ ){StartCase(); CaseSimulation(); SignalCase(); }} Good example: voidSimulation() { int nCase;for ( nCase = 0; nCase <CASES() &&!gbInterrupted && !gbCancelled &&!gbErrors;nCase++ ) {StartCase(); CaseSimulation(); SignalCase(); }}

  12. Code layout (continued) • Meaningful names Bad examples: Variables: int nJ; Symbols: classification TYPE2 { UL_VS_MARIE, HU_VS_MARIE };

  13. Layout conventions specific to Modgen • Abbreviations • Choosing a single working language • Two-letter language codes • Initializing variables and states using curly brackets • Meaningful numbering

  14. Layout conventions specific to Modgen (continued) • Abbreviations • Hard to understand for the non-initiated • To be avoided as much as possible • Documentation mandatory Example: ULHU

  15. Layout conventions specific to Modgen (continued) • Choosing a single working language • Easier to translate • Used also for abbreviations Example: vismin • Two-letter language codes • Industry standard • EN for English • FR for French • Meaningful numbering

  16. Bugs waiting to happen • Initializing all variables • Avoiding global variables • Using curly brackets in conditional blocks • Using constants • Using variables for temporary state values in events

  17. Bugs waiting to happen (continued) • Initializing all variables • Value of a non-initialized variable depends on memory state of the system • Can cause bugs that are not reproducible • Always initialize using curly brackets • Not necessary to initialize symbols

  18. Bugs waiting to happen (continued) • Using global variables • Should be avoided • Will cause problem if more than one simulation thread • Using model-generated parameters is prefered

  19. Bugs waiting to happen (continued) • Using curly brackets in conditional blocks • Prevents errors when code added Bad example: if (dAleatoireAnniversaire <= dProbul) etat_mat = EM_UNION_LIBRE; else etat_mat = EM_MARIE; Good example: if (dAleatoireAnniversaire <= dProbul) { etat_mat = EM_UNION_LIBRE; } else { etat_mat = EM_MARIE; }

  20. Bugs waiting to happen (continued) • Using constants • Mostly used for: • Initializing variables or states • Comparisons Example: if (nAge != 111) { nAge = nAge + 1;} • Other options: • Declared constants Example: constint nAgeMax = {111}; • MIN and MAX macros Example: if (nAge !=MAX(AGE_MORTALITE)) { nAge = nAge + 1;}

  21. Bugs waiting to happen (continued) • Temporary state values in events • Weird results in BioBrowser • Using a local variable is preferred

More Related