The most important thing of standards is being consequent,
always
using the same choices of naming, code structure, etc.
Your code will be easier to understand and to write, you will easier
remember variable, type and procedure names.
So, we don't force you to use the following standards, it's ok if you
create your own and follow them. Only be consequent.
The most commonly used (and widely accepted) standards are marked
in bold.
CONST ARRAY_SIZE = 15; => constants: all capitals, seperated by underscores
TYPE DayEn = (MON_DAY, TUE_DAY,...);
=> enums:
suffix 'En'
=> enum constants: all capitals, seperated by '_'
optional: use a unique suffix for that type
TYPE HoursSb = [0...24]; => subranges: suffix 'Sb'
TYPE CalendarAr =
ARRAY[1..ARRAY_SIZE]
OF DayEn;
=> types: suffix 'Ar'
PROCEDURE DoThis (inputVar:
CARDINAL);
=> procedures: start with a capital
=> parameters: start
with a small letter
VAR toReturn:
INTEGER;
nbr_items:
CARDINAL; => local
variables:
use underscores
BEGIN
...
RETURN toReturn;
END Dothis;
PROCEDURE Calculate_Nbr(...) =>
local
procedures: use underscores
...
VAR gChoice:
INTEGER; => global
variables: use prefix 'g'
startHour:
HoursSb; =>
local
variables (only used in the module or procedure): start with a
small
letter, each new 'word' with a capital
partA_Parameter:
HoursSb; => use underscores between
capitals
BEGIN
...
END ModuleName.
Indent with 2 or 3 spaces (or with a TAB - you can edit the tab size in the modula-2 editor to your own taste):
VAR a:...
PROCEDURE Test(...);
VAR i:...
BEGIN
i := 1;
END Test;
BEGIN
a := Test...
WrStr...
END Bla.
Back to the top