This standard is based on Econos Coding Standard Document.
- Indenting will be two spaces per level. You can indent by selecting text in SCAR and pressing Ctrl+Shift+U and Ctrl+Shift+I.
- Margins will be set to 80 characters. Try not to make too long lines.
- The begin statement appears on its own line. The end statement always matches the begin statement by columns.
- Do not combine two or more statements on a single line. Write each on its own line.
- Use semicolons at the end of the lines where appropriate. SCAR allows lines without semicolons but you should use them everywhere, except after var, begin, then, else repeat, do and before else.
- Use spaces after commas and arithmetical signs.
i:= (a + 4) * 6;
SetMushroomSize(i, 4, 11);
- There shall never be white space between an open parenthesis and the next character.
if(I = 42)or(J = 42)then
- Object Pascal language reserved words and key words shall always be completely lowercase. Never capitalize words that SCAR displays in bold. It's completely unnecessary and looks ugly!
- Routine names shall always begin with a capital letter and be camel-capped for readability.
- Routines shall be given names meaningful to their content. Routine name DoStuffWithSyAndSy is not meaningful, but name OutputProgressReport is.
- Where possible, procedure and function formal parameters of the same type shall be combined into one statement
procedure Foo(Param1, Param2, Param3: Integer; Param4: string);
- All formal procedure and function parameter names will be meaningful to their purpose.
- All functions should always return some value. Do not rely on SCAR initializing procedure return value automatically!
- Variables will be given names meaningful to their purpose. That includes local and loop control variables, although in this case single character names are acceptable.
- Boolean variable names must be descriptive enough so that their meanings of True and False values will be clear.
- Variable declarations start in next line after var statement and are indented.
x, y: Integer;
- Use of global variables is discouraged. However, they may be used when necessary. Global variable naming rules are as follow:
Forms and controls are prefixed with their individual prefixes. Examples: frmMainForm, lblUser, txtPassword, imgPreview etc.
DTMs will be marked with dtm prefix as in dtmFishingSpot.
Character sets will be marked with chr prefix as in chrChatChars.
Bitmaps will be marked with bmp prefix as in bmpFishingNet.
Include global variables will be marked with g prefix then include initials as in gOsiStartTime.
Normal global variables will be marked with g prefix as in gNumFishCaught.
- Type names that are reserved words shall be completely lowercase as in string. For other variable names, the first letter shall be uppercase, and the rest shall be camel-capped for clarity as in Integer.
- The most likely case to execute in an if/then/else statement shall be placed in the then clause, with less likely cases residing in the else clause(s). This improves performance as well as readability.
- If multiple conditions are being tested in an if statement, conditions should be arrange from left to right in order of least to most computation intensive. If condition statement is complex, replace it with function or Boolean variable with a meaningful name. This improves readibility and makes code self-documenting.
- Use of informational file header is encouraged for all script and include files. Use Script > Script Properties from SCAR menu to enter script information.
These standards ensures readability of your code and enables easier maintaining of scripts written by other people.