Home
Alphabetical
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

About Naming Conventions

 

My naming conventions for writing program code:

I normally use Revolution Transcript.  Transcript is a programming language derived from HyperTalk, itself inpired by SmallTalk and that again by Simula.  It is an object oriented system that uses a very English-like syntax.  Here is an example Transcript statement:

if the last word of field "UserInput" is not an integer then beep

This looks more like a sentence about a program than a piece of actual program code.  Yet it is still formed according to strict rules.  I like programming in Transcript for the reasons I give for choosing a programming language.  Of course, even in Revolution one can write less readable pieces of code:

repeat with i=1 to abs(fDifference)

add lDelta to line iLine of lV[1]; subtract 1 from iLine

end repeat

Nevertheless, Transcript is so nice that I could not resist writing a few tutorials.

Naming conventions

Identifiers start with a capital and each word in the name also has a capital.  Underscores are not used.
There may be a prefix letter, which then is lower case.  I chose these prefix letters:

c constant

f formal parameter

g global variable

i index (loops, arrays)

l local variable (if all other prefixes are respected, this one might be dropped)

n numbers of things

p custom property

h label field name (heading)

The use of these prefix letters significantly reduces the number of different names to be invented by allowing meaningful variants on a base name.

For example, the base name Line could be used in fLines (formal parameter), lLines (local temporary copy), iLine (index into fLines or lLines), nLines (the number of lines in fLines) and so on.

Transcript unfortunately does not allow procedure nesting.  For handlers that should be nested I use names prefixed with those of the handler they should be in.

Examples:

constant cMaxWindowWidth = 350

global gFolderPath, gList

 

function MakeList fFolderPath

set the width of this stack to cMaxWindowWidth

set the defaultfolder to fFolderPath

put the folders into lFolders

put the number of lines of lFolders into nFolders

repeat with iLine = 1 to nFolders

MakeListInsertFile iLine of lFolders

end repeat

end MakeList

 

on MakeListInsertFile fFileFolderName -- a subroutine of function MakeList

put fFileFolderName&return after gList

end MakeListInsertFile

Coding conventions

If a number of statements should not be broken up because they are part of an "atomic" sequence, they are written on the same line (separated by semicolons).
E.g. a swap:

put a into temp; put b into a; put temp into b -- swap a and b

Nothing should be inserted between these statements, they are in fact a single statement.

Another one:  in Revolution it is impossible to change chunks of custom property values:

-- this does not work:

put "a" after line i of the pProp of me

-- this works, but the three statements must be kept together:

put the pProp of me into lv; put "a" after line i of lv; set the pProp of me to lv

Statements may also be put several on one line in order to make code more compact:

if something then put "A" into lv1; put false into lFound; else exit mouseup end if

There must always be a good reason to put more than one statement on a line, but there sometimes is!


Valid XHTML 1.0 StrictValid CSS

next planned revision: 2010-11