Style

Prior | Next

Developing a good programming style will reduce mistakes, make debugging easier, and make code easier to maintain. Please embrace these suggestions so we are standardized as a community of ESPL programmers.

Capitalization
ESPL is not case-sensitive. Uppercase and lowercase is used for clarity.  Do not capitalize ESPL statements such as procedure, function, var, begin, end, for, if, then, writeln, boolean, and string. Capitalize variable, procedure and function names for clarity:

  procedure thisprocedurenameishardtoread;
  procedure ThisProcedureNameIsEasierToRead;

Naming Conventions
Variables should begin with a lower case letter that indicates their type:


b - boolean
i - integer
r - real
s - string
t - TDateTime
w - word
Global variables should be descriptive words, capitalized for clarity. Add the letter g at the beginning to indicate that the variable is global. Examples:

  grInterestRate {The g indicates this variable is global. The r indicates it is a real}
  sFileName {Since g is absent, assume the variable is local. The s indicates it is a string}

Single letter variables should be local.  The first choice for a local single letter boolean variable would be the letter b. The first choice for a local single letter string variable would be the letter s.

Frequently single letter integer variables are used in for loops.  The first choice for a local single letter integer variable would be the letter i, with j and k being the next two preferred choices.  Example:

  for i := iStartValue to iEndValue do DoSomething;

Indentation
Tab indent all statements that belong to a block of code or var section.  The end; statement for a block of code should be aligned with the statement that starts the block.  Tab indent compound statements as illustrated.  Example:

procedure SomeProcedureName;
var
  {indent all variable declarations}
begin
  {indent all statements here}
  for i := iStartValue to iEndValue do begin
    {multiple statements are indented here}
  end;
  if i = 7 then begin
    {multiple statements are indented here}
  end
  else begin
    {multiple statements are indented here}
  end;
end;

Prior | Next