[Lazarus] Packages and units with the same name

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
Hi,

Imagine that we have two packages and each one has a global.pas unit like this:

BasePack
   /pkg
      basepack.lpk
   /src
      global.pas

SmartPack
   /pkg
      smartpack.lpk
  /src
      global.pas


Both packages have the same configuration:
Other unit files (-Fu) = ../src

But if SmartPack uses BasePack the compiler says that we have two
versions of global.pas

My question is:
How can I put some units in a package but in a way that these units
would be invisible in others packages?

I thought that only units included in package would be visible outside
(other programs/packages) but I realized that doesn't matter if were
included or not, the visibility is defined only by path (-Fu).

Best regards,
Marcos Douglas
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
On Fri, 13 Oct 2017 15:42:27 -0300
"Marcos Douglas B. Santos via Lazarus" <[hidden email]>
wrote:

>[...]
> I thought that only units included in package would be visible outside
> (other programs/packages) but I realized that doesn't matter if were
> included or not, the visibility is defined only by path (-Fu).

Correct. Unit names must be unique in a program.


Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
On Fri, Oct 13, 2017 at 4:16 PM, Mattias Gaertner via Lazarus
<[hidden email]> wrote:

> On Fri, 13 Oct 2017 15:42:27 -0300
> "Marcos Douglas B. Santos via Lazarus" <[hidden email]>
> wrote:
>
>>[...]
>> I thought that only units included in package would be visible outside
>> (other programs/packages) but I realized that doesn't matter if were
>> included or not, the visibility is defined only by path (-Fu).
>
> Correct. Unit names must be unique in a program.

Right. But when we use 3rd packages, we don't control which names they
will use to name their units.
Moreover, I believe each package should work only in a bounded
context. Its developers should not named their files considering that
these names could be used in a bigger context. Don't you agree?

IMHO, would be better if packages may have just some "exported units".
What do you think?

Best regards,
Marcos Douglas
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
On Fri, 13 Oct 2017 16:32:37 -0300
"Marcos Douglas B. Santos via Lazarus" <[hidden email]>
wrote:

>[...]Its developers should not named their files considering that
> these names could be used in a bigger context. Don't you agree?

IMO reusable code should be named properly for a bigger context.

 
> IMHO, would be better if packages may have just some "exported units".
> What do you think?

If you mean Lazarus packages: FPC has only one type of unit, so
Lazarus can't mark units private.
Of course you can write a library. Then all unit names are hidden. But
then you loose a lot of comfort.
You might want to help FPC with namespaces.

Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 13.10.2017 21:32, Marcos Douglas B. Santos via Lazarus wrote:

> On Fri, Oct 13, 2017 at 4:16 PM, Mattias Gaertner via Lazarus
> <[hidden email]> wrote:
>> On Fri, 13 Oct 2017 15:42:27 -0300
>> "Marcos Douglas B. Santos via Lazarus" <[hidden email]>
>> wrote:
>>
>>> [...]
>>> I thought that only units included in package would be visible outside
>>> (other programs/packages) but I realized that doesn't matter if were
>>> included or not, the visibility is defined only by path (-Fu).
>>
>> Correct. Unit names must be unique in a program.
>
> Right. But when we use 3rd packages, we don't control which names they
> will use to name their units.
> Moreover, I believe each package should work only in a bounded
> context. Its developers should not named their files considering that
> these names could be used in a bigger context. Don't you agree?
>
> IMHO, would be better if packages may have just some "exported units".
> What do you think?

It doesn't matter. Any symbols in a unit are mangled only locally to the
unit and there *can not* be two or more symbols with the same name in
one program. What you ask for is simply not possible.

Regards,
Sven
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
On Fri, Oct 13, 2017 at 6:40 PM, Sven Barth via Lazarus
<[hidden email]> wrote:
> On 13.10.2017 21:32, Marcos Douglas B. Santos via Lazarus wrote:
>> [...]
>>
>> IMHO, would be better if packages may have just some "exported units".
>> What do you think?
>
> It doesn't matter. Any symbols in a unit are mangled only locally to the
> unit and there *can not* be two or more symbols with the same name in
> one program. What you ask for is simply not possible.

Is it not possible *today* or never?
I don't know how the compiler works, but try to understand me:
I would like to modularize a big program in small packages — because
it's better than to use dll/so.
Each one these packages will work in a bounded context. Each one may
have a "Facade" to the main program, exposing its "interface" (classes
and interfaces, most).
So, the main program shouldn't know nothing about "private units" that
belongs only for the package.
That is encapsulation too.

Best regards,
Marcos Douglas
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
> Is it not possible *today* or never?

Never, not without changing the way compiler manages units. FPC units are
organized in folders for easier management at filesystem level, but
filesystem is not the namespace, there can never be /first/path/to/a.pas and
/second/path/to/a.pas used in a single program, because only that a
identifies the unit, not the path to it. This is the same as you can't have
two files with the same name under the same path. Indeed you can't control
unit names written by 3rd party and collision might happen, so most package
developers add prefix in their unit names (e.g. IdGlobals) or use the new
dotted unit names (e.g. my.globals.types, your.globals.consts).

> So, the main program shouldn't know nothing about "private units" that
> belongs only for the package. That is encapsulation too.

Pascal unit is THE namespace, while most other languages uses filesystem as
namespace. Namespace don't have visibility, only its contents have.



--
Sent from: http://free-pascal-lazarus.989080.n3.nabble.com/
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list

Am 14.10.2017 00:03 schrieb "Marcos Douglas B. Santos via Lazarus" <[hidden email]>:
>
> On Fri, Oct 13, 2017 at 6:40 PM, Sven Barth via Lazarus
> <[hidden email]> wrote:
> > On 13.10.2017 21:32, Marcos Douglas B. Santos via Lazarus wrote:
> >> [...]
> >>
> >> IMHO, would be better if packages may have just some "exported units".
> >> What do you think?
> >
> > It doesn't matter. Any symbols in a unit are mangled only locally to the
> > unit and there *can not* be two or more symbols with the same name in
> > one program. What you ask for is simply not possible.
>
> Is it not possible *today* or never?
> I don't know how the compiler works, but try to understand me:
> I would like to modularize a big program in small packages — because
> it's better than to use dll/so.
> Each one these packages will work in a bounded context. Each one may
> have a "Facade" to the main program, exposing its "interface" (classes
> and interfaces, most).
> So, the main program shouldn't know nothing about "private units" that
> belongs only for the package.
> That is encapsulation too.

I can very reasonably say that this will never be possible. It's simply how things work on the binary level. And as I said that's also true for dynamic packages (which are a different beast than Lazarus' packages): even if a unit becomes part of a package it won't be touched as it can be used as part of the package as well as directly in the application binary without any changes.
Unit names *must* be unique inside a program (with or without packages). So better use prefixes or dotted unit names to reduce the chance for conflicts.

Regards
Sven


--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Sat, Oct 14, 2017 at 1:18 AM, leledumbo via Lazarus
<[hidden email]> wrote:

>> Is it not possible *today* or never?
>
> Never, not without changing the way compiler manages units. FPC units are
> organized in folders for easier management at filesystem level, but
> filesystem is not the namespace, there can never be /first/path/to/a.pas and
> /second/path/to/a.pas used in a single program, because only that a
> identifies the unit, not the path to it. This is the same as you can't have
> two files with the same name under the same path. Indeed you can't control
> unit names written by 3rd party and collision might happen, so most package
> developers add prefix in their unit names (e.g. IdGlobals) or use the new
> dotted unit names (e.g. my.globals.types, your.globals.consts).
>
>> So, the main program shouldn't know nothing about "private units" that
>> belongs only for the package. That is encapsulation too.
>
> Pascal unit is THE namespace, while most other languages uses filesystem as
> namespace. Namespace don't have visibility, only its contents have.

I know how it works in a single program, but I thought that using
packages could be different... but not.
Thanks, anyway.

Best regards,
Marcos Douglas
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Sat, Oct 14, 2017 at 4:33 AM, Sven Barth via Lazarus
<[hidden email]> wrote:

> Am 14.10.2017 00:03 schrieb "Marcos Douglas B. Santos via Lazarus"
> <[hidden email]>:
>>
>> On Fri, Oct 13, 2017 at 6:40 PM, Sven Barth via Lazarus
>> <[hidden email]> wrote:
>> > On 13.10.2017 21:32, Marcos Douglas B. Santos via Lazarus wrote:
>> >> [...]
>> >>
>> >> IMHO, would be better if packages may have just some "exported units".
>> >> What do you think?
>> >
>> > It doesn't matter. Any symbols in a unit are mangled only locally to the
>> > unit and there *can not* be two or more symbols with the same name in
>> > one program. What you ask for is simply not possible.
>>
>> Is it not possible *today* or never?
>> I don't know how the compiler works, but try to understand me:
>> I would like to modularize a big program in small packages — because
>> it's better than to use dll/so.
>> Each one these packages will work in a bounded context. Each one may
>> have a "Facade" to the main program, exposing its "interface" (classes
>> and interfaces, most).
>> So, the main program shouldn't know nothing about "private units" that
>> belongs only for the package.
>> That is encapsulation too.
>
> I can very reasonably say that this will never be possible. It's simply how
> things work on the binary level. And as I said that's also true for dynamic
> packages (which are a different beast than Lazarus' packages): even if a
> unit becomes part of a package it won't be touched as it can be used as part
> of the package as well as directly in the application binary without any
> changes.
> Unit names *must* be unique inside a program (with or without packages). So
> better use prefixes or dotted unit names to reduce the chance for conflicts.

My next question would be about dynamic packages... but you've already
answered me.
Thanks for all information.

Best regards,
Marcos Douglas
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
> I know how it works in a single program, but I thought that using
> packages could be different... but not.

Packages is Lazarus concept, the compiler has no idea about it at all. What
Lazarus does with it is generate a unit with the same name as the .lpk
containing all units belonging to the package in its uses clause (with
additional Register procedure and initialization section containing
RegisterPackage call, purely for linking with the IDE), then feed the
compiler with it. The end result is no different than compiling the units
manually. In the end, when used by a program, it's the same combinations of
.o and .ppu pair that the compiler sees.



--
Sent from: http://free-pascal-lazarus.989080.n3.nabble.com/
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Packages and units with the same name

Free Pascal - Lazarus mailing list
On Sun, Oct 15, 2017 at 12:36 PM, leledumbo via Lazarus
<[hidden email]> wrote:

>> I know how it works in a single program, but I thought that using
>> packages could be different... but not.
>
> Packages is Lazarus concept, the compiler has no idea about it at all. What
> Lazarus does with it is generate a unit with the same name as the .lpk
> containing all units belonging to the package in its uses clause (with
> additional Register procedure and initialization section containing
> RegisterPackage call, purely for linking with the IDE), then feed the
> compiler with it. The end result is no different than compiling the units
> manually. In the end, when used by a program, it's the same combinations of
> .o and .ppu pair that the compiler sees.

I see. Thanks.

Regards,
Marcos Douglas
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus