Re: Do everything in Java…

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 10 15:41:15 PST 2014


On 10 Dec 2014 18:30, "H. S. Teoh via Digitalmars-d"
<digitalmars-d at puremagic.com> wrote:
>
> On Wed, Dec 10, 2014 at 06:15:48PM +0000, Paulo Pinto via Digitalmars-d wrote:
> > On Wednesday, 10 December 2014 at 16:56:24 UTC, Iain Buclaw via
> > Digitalmars-d wrote:
> [...]
> > >In D, this should be akin to:
> > >
> > >// Package header
> > >module functions;
> > >void Swap(T)(out T x, out T y);
> > >
> > >// Package body
> > >module functions;
> > >void Swap(T)(out T x, out T y)
> > >{
> > >  // Implementation
> > >}
> > >
> > >// Importing it
> > >import functions : Swap;
> > >void main()
> > >{
> > >  int x = 1;
> > >  int y = 2;
> > >  Swap(x, y);
> > >}
> > >
> > >Iain
> >
> > But the current object model doesn't support it, right?
> >
> > At least my understanding is that you need to have the full body
> > visible.
> [...]
>
> Yeah, the compiler cannot instantiate the template without access to the
> full body. It *could*, though, if we were to store template body IR in
> object files, perhaps under specially-dedicated object file sections. It
> wouldn't prevent reverse-engineering (which is moot anyway when
> templates are involved), but it *would* work as an "opaque" library
> interface file.
>

So long as it's instantiated somewhere in the provided by the library
object shipped with the module interface, then all symbols will
resolve at link-time.

I can't imagine Ada being much different at the object level. To even
quote from a book of Ada that covers information hiding in a section
(changing the function names to be relevant for this discussion).

"""
In the above example, the full definition of Swap can be indeed
deferred until the package body.  The reason, of course, is that
nearly all current machines have a uniform addressing structure, so
that an access value always looks the same regardless of what it is
designating.

To summarise, the logical interface corresponds to the visible part;
the physical interface corresponds to the complete package
specification, that is, to both the visible part and the private part.

As long as a package specification is not changed, the package body
that implements it can be defined and redefined without affecting
other units that use this specification as an interface to the
package.  Hence it is possible to compile a package body separately
from its package specification.
"""

Now if you swap 'package specification' for 'function/template
signature', you've got yourself more or less describing how D
modules/packages work.

Iain.


More information about the Digitalmars-d mailing list