[Grace-core] Placeholders-initialization of circular data structures

Marco Servetto marco.servetto at gmail.com
Sun Nov 18 20:23:16 PST 2012


> Also, the component-assembly example that you give is very important
> in practical software development. It has led to "dependency
> injection" frameworks being developed.
Indeed, avoiding "dependency injection" frameworks is one of my main goals.

> On a design note, one thing to consider is whether you really want
> placeholders to be able to flow to positions that aren't marked
> specially in any way.
This is the mail feature of place holders, otherwise you can already
use a "provideder" a la google juice,
so that you can have a ProvideBrain field, pass the empty ProvideBrain
object, and later on complete the initialization.
This would require the designer of human organs to know about
circularity in advance, breaking all the criteria of a separate
developing.

> Since Grace is implemented on other VMs,
> rather than having its own custom VM, this requirement could lead to a
> slowdown even for code that isn't using placeholders. It might work
> better to mark potentially lazy variables as such to make the
> implementation much easier.
A good implementation that does not slow down is possible, and is
possible over a JVM.
(supposing a type system recognizing place holder types)
--example implementation:
  use a dummy instance with all nulls in the fields as a place holder
(or an anonimus subclass with all methods overridden with throw new
PlaceHolderException()?).
  for every constructor call that take a placeholder, put the result
object in a map.
  when the placeholder replacement is required, just explore all the
object in such map and fix their fields.


More information about the Grace-core mailing list