Thoughts about modules
Derek Parnell
derek at nomail.afraid.org
Thu Jun 29 17:25:53 PDT 2006
On Thu, 29 Jun 2006 14:45:23 -0700, Kirk McDonald wrote:
> Derek Parnell wrote:
>> Why is FQN syntax demonstrable better than the current shortcut syntax?
> ...
> By making it mandatory, we can
> always know where any name comes from, whether they are being
> fully-qualified, or imported on their own.
>
> Now, for something like writefln, which is a well-known name that
> everyone will recognize instantly, this is a bit of a burden. You'd have
> to type it a whole extra time at the top of the file!
So to summarize ...
Mandatory fully qualified names makes it simple for a code reader to know
in which module a member is located. But because that could be a burden to
the code writer, the alias (or something similar) can be used to 'register'
the FQN once in the code and allows the writer to use a short form of the
name.
Anyhow, I tried this coding style on Build just now and ended up with
this...
------------------
import source; // Source File class
alias source.ActivateVersion ActivateVersion;
alias source.ActivateDebug ActivateDebug;
alias source.SetKnownVersions SetKnownVersions;
import util.str; // non-standard string routines.
alias util.str.SetEnv SetEnv;
alias util.str.GetEnv GetEnv;
alias util.str.Expand Expand;
alias util.str.ExpandEnvVar ExpandEnvVar;
alias util.str.ends ends;
alias util.str.begins begins;
alias util.str.enquote enquote;
alias util.str.strip ustrip;
alias util.str.stripr ustripr;
alias util.str.IsLike IsLike;
alias util.str.YesNo YesNo;
alias util.str.TranslateEscapes TranslateEscapes;
import util.fdt; // File Date-Time class
alias util.fdt.GetFileTime GetFileTime;
import util.pathex; // Extended Path routines.
alias util.pathex.GetBaseName GetBaseName;
alias util.pathex.MakePath MakePath;
alias util.pathex.CanonicalPath CanonicalPath;
alias util.pathex.AbbreviateFileName AbbreviateFileName;
alias util.pathex.LocateFile LocateFile;
alias util.pathex.IsRelativePath IsRelativePath;
alias util.pathex.FindFileInPathList FindFileInPathList;
alias util.pathex.GetInitCurDir GetInitCurDir;
import util.fileex; // Extended File routines.
alias util.fileex.CreateTextFile CreateTextFile;
alias util.fileex.FindInFile FindInFile;
alias util.fileex.GetTextLines GetTextLines;
alias util.fileex.GetOpt GetOpt;
import util.file2;
alias util.file2.FileExists FileExists;
import util.macro; // Macro processing routines.
alias util.macro.ConvertFile ConvertFile;
import util.booltype; // definition of True and False
alias util.booltype.True True;
alias util.booltype.False False;
import std.utf;
alias std.utf.toUTF32 toUTF32;
import std.file;
alias std.file.remove remove;
alias std.file.write write;
import std.regexp;
alias std.regexp.search search;
alias std.regexp.find refind;
import std.path;
alias std.path.sep sep;
alias std.path.linesep linesep;
alias std.path.getDirName getDirName;
alias std.path.getExt getExt;
alias std.path.addExt addExt;
alias std.path.getName getName;
alias std.path.getBaseName getBaseName;
import std.stdio;
alias std.stdio.writefln writefln;
import std.string;
alias std.string.find find;
alias std.string.rfind rfind;
alias std.string.format format;
alias std.string.replace replace;
alias std.string.split split;
alias std.string.tolower tolower;
alias std.string.strip strip;
version(Windows)
{
import std.c.windows.windows;
alias std.c.windows.windows.GetVersion GetVersion;
}
------------------
I had to disambiguate std.string.find and std.regex.find, plus a couple of
others, but no big drama.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
30/06/2006 9:26:58 AM
More information about the Digitalmars-d
mailing list