Namespaces

From Free Pascal wiki
Revision as of 13:36, 26 July 2010 by Ggeldenhuys (talk | contribs) (New page: == Namespaces in FPC == This page contains proposals and ideas, which could lead to the a better implementation of namespaces that what Delphi currently has. == Why? == Namespaces are not...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Namespaces in FPC

This page contains proposals and ideas, which could lead to the a better implementation of namespaces that what Delphi currently has.

Why?

Namespaces are not perfect, but they do work, and they do greatly reduce the chances for unitname or classname conflicts. Other languages and frameworks (Java, .NET, C++ etc) have already seen the problem and introduced namespace support.

How visible is the unit name conflict problem? Just think, how many projects are there that use the unit names (or would like to use these common names):

 constants.pas
 utils.pas
 etc...

Extremely common names, and are really good names for what they contain (they describe the purpose of the unit clearly), so why can't we use them in our projects? Namespaces will resolve such problem.

  • To reduce the chances of conflicting unit names
  • Allow developers to use ideal names for units without the worry of conflicting unit names with the FPC compiler or other component libraries. eg: constants.pas or utils.pas or strutils.pas
  • No need for cryptic 2 or 3 letter prefixes to unit names.

Interested Parties

  • Graeme Geldenhuys


Usage Examples

Please add any new ideas to the end of the list.

Suggestion 1 - "dotted unit name notation"

Use the same style as implemented in Delphi 2009 onwards.

Pros

  • Delphi compatible

Cons

  • The force rather long unit names. eg: freepascal.rtl.classes.pas
  • Unit names now contain a '.' character which doesn't make them truly valid identifiers.
  • Ambiguities couldn't appear, but they are rather easy to overcome with a simple language rule. Object Pascal already have many language rules, this will just be a new one. See the following Mantis report for details:
   http://bugs.freepascal.org/view.php?id=14439


Suggestion 2 - new keyword & new compiler parameter

Pros

  • ?

Cons

  • ?

Suggestion 3 - directory layout

Pros

  • ?

Cons

  • Similar to what JAVA does, though I see lots of issues with this idea because FPC supports multiple search and library paths per project.