www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is anything private by default when declared in a module?

reply "Gary Willoughby" <dev nomad.so> writes:
Is anything private by default when declared in a module?

I'm declaring functions, classes, structs, enums, aliases, etc.. 
I'm assuming all these are public by default when declared in a 
module to allow them to be imported into another. Is there 
anything private by default when declared in a module?
Dec 02 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
 Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
Dec 02 2013
parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
 On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby 
 wrote:
 Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
But sadly named imports aren't private... /// module foo private import std.stdio: writeln; writeln can be used in any module which imports foo. :/
Dec 02 2013
next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
 On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
But sadly named imports aren't private... /// module foo private import std.stdio: writeln; writeln can be used in any module which imports foo. :/
WAT? That's messed up. Is there a bug for that? T -- Why waste time learning, when ignorance is instantaneous? -- Hobbes, from Calvin & Hobbes
Dec 02 2013
next sibling parent "Gary Willoughby" <dev nomad.so> writes:
On Monday, 2 December 2013 at 21:10:44 UTC, H. S. Teoh wrote:
 On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
 On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe 
 wrote:
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby 
wrote:
Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
But sadly named imports aren't private... /// module foo private import std.stdio: writeln; writeln can be used in any module which imports foo. :/
WAT? That's messed up. Is there a bug for that? T
WAT?++
Dec 02 2013
prev sibling parent reply "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 2 December 2013 at 21:10:44 UTC, H. S. Teoh wrote:
 On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
 On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe 
 wrote:
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby 
wrote:
Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
But sadly named imports aren't private... /// module foo private import std.stdio: writeln; writeln can be used in any module which imports foo. :/
WAT? That's messed up. Is there a bug for that? T
I mean yes, but I find nothing. Short example: io.d ---- private import std.stdio : writeln; ---- io_use.d ---- import io; void main() { writeln("Hello"); } ----
Dec 02 2013
parent "Namespace" <rswhite4 googlemail.com> writes:
On Monday, 2 December 2013 at 21:30:08 UTC, Namespace wrote:
 On Monday, 2 December 2013 at 21:10:44 UTC, H. S. Teoh wrote:
 On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
 On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe 
 wrote:
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby 
wrote:
Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
But sadly named imports aren't private... /// module foo private import std.stdio: writeln; writeln can be used in any module which imports foo. :/
WAT? That's messed up. Is there a bug for that? T
I mean yes, but I find nothing. Short example: io.d ---- private import std.stdio : writeln; ---- io_use.d ---- import io; void main() { writeln("Hello"); } ----
I have found it https://github.com/D-Programming-Language/dmd/pull/2256
Dec 02 2013
prev sibling next sibling parent reply "lomereiter" <lomereiter gmail.com> writes:
On Monday, 2 December 2013 at 20:53:10 UTC, Namespace wrote:
 But sadly named imports aren't private...
OMG now I get it why in 2.064 importing std.regex makes visible std.uni.isWhite all of a sudden.
Dec 02 2013
parent "eles" <eles eles.com> writes:
On Monday, 2 December 2013 at 21:28:48 UTC, lomereiter wrote:
 On Monday, 2 December 2013 at 20:53:10 UTC, Namespace wrote:
 OMG now I get it why in 2.064 importing std.regex makes visible 
 std.uni.isWhite all of a sudden.
Unicorns cannot be white, as they are already pink & invisible. At least the std ones... http://en.wikipedia.org/wiki/Invisible_Pink_Unicorn
Dec 03 2013
prev sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, December 02, 2013 13:09:06 H. S. Teoh wrote:
 On Mon, Dec 02, 2013 at 09:53:09PM +0100, Namespace wrote:
 On Monday, 2 December 2013 at 20:46:58 UTC, Adam D. Ruppe wrote:
On Monday, 2 December 2013 at 20:43:23 UTC, Gary Willoughby wrote:
Is anything private by default when declared in a module?
I believe imports only. "import foo;" is private, so you write "public import foo;" to expose outside. But other than that, I'm pretty sure everything is public unless you say otherwise.
But sadly named imports aren't private... /// module foo private import std.stdio: writeln; writeln can be used in any module which imports foo. :/
WAT? That's messed up. Is there a bug for that?
Yes. It's a longstanding bug with regards to selective imports. They create a conflicting symbol in the importing module's scope. That's why you should never use them at this point. https://d.puremagic.com/issues/show_bug.cgi?id=314 - Jonathan M Davis
Dec 02 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 3 December 2013 at 07:34:37 UTC, Jonathan M Davis 
wrote:
 They create a conflicting symbol in the importing module's 
 scope.
 That's why you should never use them at this point.
Well, that's sometimes useful, it helps get rid of conflict errors quickly, easily, and explicitly. It should just be a private name in the new scope unless the import was public. BTW private names should be outright invisible outside the module. At least private things at module scope. I get really annoyed with "public symbol foo from module bar conflicts with private symbol foo from module baz". Gee, I wonder which one I wanted to use??? But that's a separate issue.
 https://d.puremagic.com/issues/show_bug.cgi?id=314
wait, I thought Kenji fixed that? The comments don't say why it was reopened... did it just break too much Phobos code or was the fix wrong in some other way?
Dec 03 2013
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Dec 03, 2013 at 04:16:04PM +0100, Adam D. Ruppe wrote:
[...]
 BTW private names should be outright invisible outside the module.
 At least private things at module scope. I get really annoyed with
 "public symbol foo from module bar conflicts with private symbol foo
 from module baz". Gee, I wonder which one I wanted to use???
Yeah, that's pretty annoying. Once I wrote a module that exports a symbol that just so happens coincided with a private symbol in std.regex, and the compiler complained all over the place about it. Pretty annoying. Worse yet, the code *worked* when the code that referenced that symbol was in the same module, but when it was moved out during code reorg, it started to fail compiling. I was not very happy with that. (And doesn't that go against what TDPL says, too?)
 But that's a separate issue.
 
https://d.puremagic.com/issues/show_bug.cgi?id=314
wait, I thought Kenji fixed that? The comments don't say why it was reopened... did it just break too much Phobos code or was the fix wrong in some other way?
The pull linked to in the bug hasn't been merged yet. T -- Long, long ago, the ancient Chinese invented a device that lets them see through walls. It was called the "window".
Dec 03 2013