October 18, 2012
Hey guys!

I think I understand the reasoning behind the idea that classes in the same module are automatically "friends", but why isn't there any way to have this sort of relationship between classes outside of a module? I feel like there are times when it doesn't always make sense to have two(or more) classes in the same module, but you would still need to make them interact like "friends."

Is there any kind of work around for this functionality?

And in case you were curious, my main problem with this is that I think it is a lot cleaner when writing code and easier to manage my projects when I can split things up into different files. I'm currently working on a wrapper for a C++ api and started wishing I could do this a few days ago.
October 18, 2012
On Thursday, October 18, 2012 10:09:46 Jeremy DeHaan wrote:
> Is there any kind of work around for this functionality?

The package access modifier.

- Jonathan M Davis
October 18, 2012
On Thursday, 18 October 2012 at 08:12:42 UTC, Jonathan M Davis wrote:
> On Thursday, October 18, 2012 10:09:46 Jeremy DeHaan wrote:
>> Is there any kind of work around for this functionality?
>
> The package access modifier.
>
> - Jonathan M Davis

You, good sir, are now my new best friend.
October 18, 2012
On Thu, Oct 18, 2012 at 11:12 AM, Jeremy DeHaan <dehaan.jeremiah@gmail.com> wrote:
> On Thursday, 18 October 2012 at 08:12:42 UTC, Jonathan M Davis wrote:
>>
>> On Thursday, October 18, 2012 10:09:46 Jeremy DeHaan wrote:
>>>
>>> Is there any kind of work around for this functionality?
>>
>>
>> The package access modifier.
>>
>> - Jonathan M Davis
>
>
> You, good sir, are now my new best friend.

Does it work? I thought it was not implemented.
October 18, 2012
On 2012-10-18 19:57, Philippe Sigaud wrote:

> Does it work? I thought it was not implemented.

Define "work". They're not virtual, which this would imply:

"All non-static non-private non-template member functions are virtual."

http://dlang.org/function.html#virtual-functions

-- 
/Jacob Carlborg
October 18, 2012
I mean, the 'package' access modifier.
October 18, 2012
On Thursday, October 18, 2012 20:42:08 Jacob Carlborg wrote:
> On 2012-10-18 19:57, Philippe Sigaud wrote:
> > Does it work? I thought it was not implemented.
> 
> Define "work". They're not virtual, which this would imply:
> 
> "All non-static non-private non-template member functions are virtual."
> 
> http://dlang.org/function.html#virtual-functions

That's a spec bug. Walter and Andrei have both confirmed that package functions are not intended to be virtual and that that won't be changing.

- Jonathan M Davis
October 18, 2012
> Does it work? I thought it was not implemented.

Hmm. I don't know what it's current state is. There _is_ a long-standing bug on it in bugzilla ( http://d.puremagic.com/issues/show_bug.cgi?id=143 ) which is still open. I had forgotten about it. But the bug is that package doesn't restrict when it's supposed to as opposed to restricting when it's not supposed to, so it'll work in that you can use it correctly and have your code work, but it won't catch incorrect usage, and your code which uses it incorrectly will break once it's fixed.

- Jonathan M Davis
October 19, 2012
On Thursday, 18 October 2012 at 20:44:42 UTC, Jonathan M Davis wrote:
>> Does it work? I thought it was not implemented.
>
> Hmm. I don't know what it's current state is. There _is_ a long-standing bug
> on it in bugzilla ( http://d.puremagic.com/issues/show_bug.cgi?id=143 ) which
> is still open. I had forgotten about it. But the bug is that package doesn't
> restrict when it's supposed to as opposed to restricting when it's not
> supposed to, so it'll work in that you can use it correctly and have your code
> work, but it won't catch incorrect usage, and your code which uses it
> incorrectly will break once it's fixed.
>
> - Jonathan M Davis

It seems to be working for me. Things within the same package can access those members and things outside can't. The compiler complained when I tried.
October 19, 2012
On 2012-10-18 20:51, Philippe Sigaud wrote:
> I mean, the 'package' access modifier.

So did I.

class Foo
{
    package void foo () {}
}

Would, according to the spec, imply a virtual method. But as Jonathan said, this is a bug in the spec.

-- 
/Jacob Carlborg
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home