Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 05, 2013 selective import | ||||
---|---|---|---|---|
| ||||
Hi all. How to use use selective imports more effectively? I have two modules foo and bar: module foo; class Foo {} module bar; import foo: Foo; class Bar { private Foo foo_; this(Foo foo) { foo_ = foo; } } Now I add module baz that use both modules above. How to import foo and bar - everything or only 'the topmost' one, bar? module baz; import bar: Bar; import foo: Foo; or import bar: Bar, Foo; // also in bar import of foo.Foo should be public of course I don't see difference, but it doesn't mean it doesn't exist. What do you think about it? |
December 05, 2013 Re: selective import | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandr Druzhinin | On Thursday, 5 December 2013 at 11:17:18 UTC, Alexandr Druzhinin wrote:
> I don't see difference, but it doesn't mean it doesn't exist. What do you think about it?
It depends on how bar uses foo. You should do public import of symbols from foo if they are required to interact with bar public API. If foo is only used as part of internal implementation, it should be kept private and both modules imported explicitly.
|
December 05, 2013 Re: selective import | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | 05.12.2013 20:34, Dicebot пишет:
> On Thursday, 5 December 2013 at 11:17:18 UTC, Alexandr Druzhinin wrote:
>> I don't see difference, but it doesn't mean it doesn't exist. What do
>> you think about it?
>
> It depends on how bar uses foo. You should do public import of symbols
> from foo if they are required to interact with bar public API. If foo is
> only used as part of internal implementation, it should be kept private
> and both modules imported explicitly.
Third module uses both Bar and Foo. So I should either import every module individually, or import Bar only but Bar should publicly import Foo - that's the question.
|
December 05, 2013 Re: selective import | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandr Druzhinin | On Thursday, 5 December 2013 at 13:39:09 UTC, Alexandr Druzhinin wrote:
> 05.12.2013 20:34, Dicebot пишет:
>> On Thursday, 5 December 2013 at 11:17:18 UTC, Alexandr Druzhinin wrote:
>>> I don't see difference, but it doesn't mean it doesn't exist. What do
>>> you think about it?
>>
>> It depends on how bar uses foo. You should do public import of symbols
>> from foo if they are required to interact with bar public API. If foo is
>> only used as part of internal implementation, it should be kept private
>> and both modules imported explicitly.
> Third module uses both Bar and Foo. So I should either import every module individually, or import Bar only but Bar should publicly import Foo - that's the question.
It does not matter what third module uses, it is purely about relation between foo and bar. If foo symbols are not necessary part of public bar API, third module will import both. If they are, bar will import foo publicly. Pretty simple.
|
December 05, 2013 Re: selective import | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | 05.12.2013 20:43, Dicebot пишет:
>
> It does not matter what third module uses, it is purely about relation
> between foo and bar. If foo symbols are not necessary part of public bar
> API, third module will import both. If they are, bar will import foo
> publicly. Pretty simple.
I realized.
|
Copyright © 1999-2021 by the D Language Foundation