Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-04

OT: Namespaces?

18 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hans-Peter Diettrich

From a discussion I want to present this idea:

FPC (and Delphi) could extend the Uses syntax to
USES <unitname> [IN <filename>] [AS <identifier>]

The optional AS part would allow to create an alias (shortcut...) for units of possibly conflicting (same) name. IMO a simple implementation of the most important benefits of namespaces, that does not require the introduction of orthogonal namespaces in addition to units.

While this suggestion is not related to Lazarus, I still would appreciate comments from the community.

DoDi

Reply by email

dmitry boyarintsev
to Hans-Peter Diettrich
E.g. when you have multiple third-party units of the same name.

there's a good ways to handle this: rename your units (adding my prefixed, like my_* to unit name). Usually 3d party units (usually libraries) do this, prefixing their names.

after all, aliasing is dangerous, because, you might cause the worser name conflict:

let's say you've bound some unit with alias name

program
users

  SomeUnit as "NewUnit";

but some 3d party unit uses different unit, that actually matches the allias name:
uses

   NewUnit;

how should compiler behave in this way? This case is worse, because you'll have to study other lib for units name usage.

Thanks,
Dmitry

Reply by email

Marco van de Voort
to Hans-Peter Diettrich: From a discussion I want to present this idea: FPC (and Delphi) could extend the Uses…
Hans-Peter Diettrich wrote 9 lines
From a discussion I want to present this idea: FPC (and Delphi) could extend the Uses syntax to USES <unitname> [IN <filename>] [AS <identifier>] The optional AS part would allow to create an alias (shortcut...) for units of possibly conflicting (same) name. IMO a simple implementation of the most important benefits of namespaces, that does not require the introduction of orthogonal namespaces in addition to units.

With full path? That is generally frowned upon, since it makes projects unrelocatable.

Without full path is not possible, since that would interfere with how the compiler finds files

While this suggestion is not related to Lazarus, I still would appreciate comments from the community.

The problem is that most systems with namespaces naturally allow duplicate entries because they map somewhere to a hierarchy, making items with duplicate names unique because of their location in their hierarchy. (iow System.objects.bla system.bla)

FPC/Delphi have free search of files, which conflicts with that, and a filename would be a bad hack to introduce that. Any other solution requires either a hierarchy, or scanning the internals of all files (to recover the qualification) in the path
before every compile.

IMHO these are hacks that are worse than the problem, specially for an open source project, where most units aret available in source.

Reply by email

Hans-Peter Diettrich
to Mattias Gärtner
Show quoted text 6 lines
>> why aliases units names are required? > E.g. when you have multiple third-party units of the same name. Isn't that already supported by the 'in' modifier? For example: uses unit1, unit1B in '../test/unit1';

Heureka :-)

While Delphi 7 requires that the unit name matches the file name, even when using IN, and AFAIR allows for IN only in the project file (*.DPR), FPC imposes no such restrictions.

Now we can go on-topic: While FPC already supports true unit alias, Lazarus (code completion...) cannot handle unit1B in your example :-(

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
Show quoted text 17 lines
Mattias G?rtner schrieb: >>> why aliases units names are required? >> E.g. when you have multiple third-party units of the same name. > > Isn't that already supported by the 'in' modifier? For example: > > uses unit1, unit1B in '../test/unit1'; Heureka :-) While Delphi 7 requires that the unit name matches the file name, even when using IN, and AFAIR allows for IN only in the project file (*.DPR), FPC imposes no such restrictions. Now we can go on-topic: While FPC already supports true unit alias, Lazarus (code completion...) cannot handle unit1B in your example :-(

Have you updated to svn 19249?
If yes: please provide an example.

Mattias

Reply by email

Mattias Gärtner
to Hans-Peter Diettrich: Heureka :-) While Delphi 7 requires that the unit name matches the file name, even when…

Zitat von Hans-Peter Diettrich :

Show quoted text 16 lines
Mattias G?rtner schrieb: >>> why aliases units names are required? >> E.g. when you have multiple third-party units of the same name. > > Isn't that already supported by the 'in' modifier? For example: > > uses unit1, unit1B in '../test/unit1'; Heureka :-) While Delphi 7 requires that the unit name matches the file name, even when using IN, and AFAIR allows for IN only in the project file (*.DPR), FPC imposes no such restrictions. Now we can go on-topic: While FPC already supports true unit alias,

FPC supports unit alias in a unit, but it does not support two different ppu with the same name. At least 2.2.3 does not.
You will get linker errors, because identifiers of the second unit1 have still the same prefix.
It is probably a bug, that FPC does not check and gives an error in this case.

Lazarus (code completion...) cannot handle unit1B in your example :-(

Mattias

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Mon, 06 Apr 2009 20:28:27 +0200 Have you updated to svn 19249? If yes: please provide…
> Now we can go on-topic: While FPC already supports true unit alias, > Lazarus (code completion...) cannot handle unit1B in your example :-( Have you updated to svn 19249?

I've just updated to svn 19273, and the problem persists. Though, Lazarus says SVN 19172 in the About dialog, after a full rebuild?

If yes: please provide an example.
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
   Classes, SysUtils, Forms;
function MyText: string;
implementation
uses
   myform in 'unit1.pas';
function MyText: string;
begin
   Result := myform.Form1.Edit1.Text + '+';
end;
end.

Unit1 is a simple form with an edit control.

In the above line, starting from myform none of the identifiers is recognized. No jump to declaration, no code completion, nada :-(

DoDi

Reply by email

Marco van de Voort
to Mattias Gärtner: Zitat von Hans-Peter Diettrich : FPC supports unit alias in a unit, but it does not…
Mattias G?rtner wrote 8 lines
> > Now we can go on-topic: While FPC already supports true unit alias, FPC supports unit alias in a unit, but it does not support two different ppu with the same name. At least 2.2.3 does not. You will get linker errors, because identifiers of the second unit1 have still the same prefix. It is probably a bug, that FPC does not check and gives an error in this case.

Isn't the ..IN.. syntax is more created to correct case differences between unitname and filename ?

Reply by email

zeljko
to Mattias Gärtner
Mattias G?rtner wrote 5 lines
AFAIK under Delphi the 'in' modifier has two purposes: - mark the unit as part of the project - use a unit from a directory which can not be added to the unit search path, because there is a duplicate.

Lazarus uses same logic isn't it ? I already have such projects where I must use "in" like in delphi.

Reply by email

Mehmet Erol Sanliturk
to Mattias Gärtner: Zitat von Hans-Peter Diettrich : FPC supports unit alias in a unit, but it does not…
am Mattias G?rtner wrote 16 lines
Zitat von Hans-Peter Diettrich : > Mattias G?rtner schrieb: FPC supports unit alias in a unit, but it does not support two different ppu with the same name. At least 2.2.3 does not. You will get linker errors, because identifiers of the second unit1 have still the same prefix. It is probably a bug, that FPC does not check and gives an error in this case. Mattias

In Free Pascal configuration files ( .CFG ) there is no any unit alias name definition facility ( or I could not find information about it ) .

Such a facility may be useful because by using that , it may be possible to redefine different names for the different platforms , such as , for example

-Alias Linux = Windows
-Alias Unix = Windows

etc .

At present , it seems that it is necessary to use {$ifdef statements to give different names for different platforms .

Another problem is .LPI files . When a project is developed in , let say Windows , it is NOT usable in Linux or FreeBSD because their FPC and Lazarus installation directory structures are very ( actually WILDLY ) different .

For large programs spanning a large number of directories it is becoming to enter related directory names ( including FPC and Lazarus directory names ) once more to re-generate .LPI files .

With that structure it is not possible to develop a program in a server and compile it it in different operating systems connected to that server .

To overcome this difficulty even it is necessary to be able to define directory aliases , for example ,

-Alias \fpc\ = /home/actual_name/fpc/

Thank you very much .

Mehmet Erol Sanliturk

Reply by email

Mattias Gaertner
to zeljko: Lazarus uses same logic isn't it ? I already have such projects where I must use "in"…
Show quoted text 9 lines
On Tuesday 07 April 2009 15:11, Mattias G?rtner wrote: > > AFAIK under Delphi the 'in' modifier has two purposes: > - mark the unit as part of the project > - use a unit from a directory which can not be added to the unit > search path, because there is a duplicate. Lazarus uses same logic isn't it ?

It does not.
What belongs to the project is stored in the .lpi.

The codetools support the 'in' modifier and so does the lazarus IDE a bit.
But the IDE does not update the 'in' file names and it does not have any special consistency checks for them. So use them only if you know what you are doing.

The converter for delphi projects supports them (fix the file cases, adds them to the lpi).

I already have such projects where I must use "in" like in delphi.

Please give a complete example. Maybe you are doing something wrong.

Mattias

Reply by email

zeljko
to Mattias Gaertner
Mattias Gaertner wrote 19 lines
On Tue, 7 Apr 2009 15:32:28 +0200 zeljko wrote: > On Tuesday 07 April 2009 15:11, Mattias G?rtner wrote: > > AFAIK under Delphi the 'in' modifier has two purposes: > > - mark the unit as part of the project > > - use a unit from a directory which can not be added to the unit > > search path, because there is a duplicate. > > Lazarus uses same logic isn't it ? It does not. What belongs to the project is stored in the .lpi. The codetools support the 'in' modifier and so does the lazarus IDE a bit. But the IDE does not update the 'in' file names and it does not have any special consistency checks for them. So use them only if you know what you are doing.

I must use them :)

Show quoted text 7 lines
The converter for delphi projects supports them (fix the file cases, adds them to the lpi). > I already have such projects where > I must use "in" like in delphi. Please give a complete example. Maybe you are doing something wrong.

I have two dirs with projects, both have main.pas, but project2 uses some units from project1 dir.
So:
1.I must include project1 dir into project2, but sometimes , when building project2 lazarus (eg. when have some error in code), raised main.pas from project1 , but it shouldn't, it must open project2/main.pas. In kylix this is normal (because of "in"), so each unit is properly recompiled.

I've seen that it's little bit messy and tricky with fpc, so my settings for eg. project2 are:
1.project1 units , which are used in project2 ARE included inside .lpr with "in" like myunitfromproj1 in '../project1/myunitfromproj1.pas' etc.. 2.project1 dir is removed from my units path.
3.-FU is setted up to project2 dir.
4.Laz application output path is at third place ... eg. myBuilds/project2

Now it does not make any mess. Maybe I'm wrong ... but it works for me.

z.

Reply by email

Mattias Gaertner
to zeljko
Show quoted text 52 lines
On Tuesday 07 April 2009 16:59, Mattias Gaertner wrote: > On Tue, 7 Apr 2009 15:32:28 +0200 > > zeljko wrote: > > On Tuesday 07 April 2009 15:11, Mattias G?rtner wrote: > > > AFAIK under Delphi the 'in' modifier has two purposes: > > > - mark the unit as part of the project > > > - use a unit from a directory which can not be added to the unit > > > search path, because there is a duplicate. > > > > Lazarus uses same logic isn't it ? > > It does not. > What belongs to the project is stored in the .lpi. > > The codetools support the 'in' modifier and so does the lazarus IDE > a bit. > But the IDE does not update the 'in' file names and it does not have > any special consistency checks for them. So use them only if > you know what you are doing. I must use them :) > The converter for delphi projects supports them (fix the > file cases, adds them to the lpi). > > > I already have such projects where > > I must use "in" like in delphi. > > Please give a complete example. Maybe you are doing something wrong. I have two dirs with projects, both have main.pas, but project2 uses some units from project1 dir. So: 1.I must include project1 dir into project2, but sometimes , when building project2 lazarus (eg. when have some error in code), raised main.pas from project1 , but it shouldn't, it must open project2/main.pas. In kylix this is normal (because of "in"), so each unit is properly recompiled. I've seen that it's little bit messy and tricky with fpc, so my settings for eg. project2 are: 1.project1 units , which are used in project2 ARE included inside .lpr with "in" like myunitfromproj1 in '../project1/myunitfromproj1.pas' etc.. 2.project1 dir is removed from my units path. 3.-FU is setted up to project2 dir. 4.Laz application output path is at third place ... eg. myBuilds/project2 Now it does not make any mess. Maybe I'm wrong ... but it works for me.

I compiles. But it dos not work well in the IDE, because it does not know what to do with '../project1/myunitfromproj1.pas'. For example it does not know where to search the units used by myunitfromproj1.pas.

Normally shared units are put into a separate directory and then you either create a package for it or you add it to the unit path.

Mattias

Reply by email

Tom Miller
to Hans-Peter Diettrich: From a discussion I want to present this idea: FPC (and Delphi) could extend the Uses…

This isn't name spacing, but aliases.

Hans-Peter Diettrich wrote 21 lines
From a discussion I want to present this idea: FPC (and Delphi) could extend the Uses syntax to USES <unitname> [IN <filename>] [AS <identifier>] The optional AS part would allow to create an alias (shortcut...) for units of possibly conflicting (same) name. IMO a simple implementation of the most important benefits of namespaces, that does not require the introduction of orthogonal namespaces in addition to units. While this suggestion is not related to Lazarus, I still would appreciate comments from the community. DoDi _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email