Some of the newer languages require the name of the library (object file) be typed before every instance of a function defined in the library.
log(x) vs math.log(x) |
Over a number of years, I have come up with *a* scheme for naming things that I plan to reuse in multiple projects.
Some of my older code does not follow these guidelines.
The Problem
Unit xxSomename object TxxSomename = class ... |
Unit xxSomename object Txx_Somename = class ... var xx_Somename : Txx_Somename; |
Unit xxSomename object T_xxSomename = class ... |
type TForm1 = class(TForm) _xxSomename1: T_xxSomename; // Starts with an underscore private |
However, I always use an underscore before a trailing branding identifier. See Global Constants and Functions (below) for examples.
Units
Language | Package Name | Comment |
---|---|---|
Delphi | Unit | A combination of the c-style object files and the c-style header files |
C++ | Object | Compiled files, ready to be linked. Requires a separate header file. |
Java | Library | Partially compiled Class files |
Action Script 3 | Package | Text files in a well defined directory structure - The package name is the directory path. |
While it is possible to distribute units (name.dcu) without any source, Delphi has made this difficult. Unfortunately, a different version of the dcu file is required for each version of Delphi.
I name the units by using a 2-letter prefix.
unit mcCommon; mcCommon.pas Source file mcCommon.dcu Delphi Compiled Unit |
Global Constants and Functions
from mcCommon.pas const // These "end" in "_mc" to make them easier to find in the help CRLF_mc = #13#10 ; // CR/LF - Carriage Return/Linefeed CR_mc = #13; // CR 0Dh #$0D LF_mc = #10; // LF 0Ah function Left_mc (s: string; NumOfCharacters : integer):string; overload; function Right_mc (s: string; NumOfCharacters : integer):string; overload; |
procedure mc_CopyText_and_Formating(Src, Dest: TRichEdit{TCustomMemo}); procedure mc_SetCaretPos(Memo:TCustomMemo; Line: integer; Char: integer=0); function mc_DateTime_to_24hr(DateTime: string='now'): string; overload; |
Object Names
Single Global Objects
From unit mcExtras,
type Tmc_File_Version_Info = class private public constructor Create; virtual; // the details don't matter on this page end; function mc_File_Version_Info: Tmc_File_Version_Info; implementation var Fmc_File_Version_Info : Tmc_File_Version_Info; function mc_File_Version_Info: Tmc_File_Version_Info; begin if Fmc_File_Version_Info=nil then begin Fmc_File_Version_Info := Tmc_File_Version_Info.Create; end; result := Fmc_File_Version_Info; end; { end mc_File_Version_Info } initialization // required so that *finalization* can be defined finalization Fmc_File_Version_Info.Free; |
unit mc_LogFiles; type Tmc_LogFiles = class(TObject) // the details don't matter on this page end; var mcLogFiles: Tmc_LogFiles; implementation initialization mcLogFiles := Tmc_LogFiles.Create ; finalization mcLogFiles.Free; |