In a nutshell: In the Lua integration we do things the user asked us
for... and if they ask us for sitelinks of a property or statements of a
$foo, then we have to gracefully handle that.
In the future we might want to do that (at least partly) on the Lua
level by having different metatables for different entity types (which
would make our Lua Apis a little harder to use)... but that's a b/c
breaking change that I don't want to make a blocker to statements on
properties.
Cheers,
Marius
On Mon, 2014-11-10 at 04:16 +0100, Jeroen De Dauw wrote:
Hey Hoo and Katie,
A few days ago, on IRC I mentioned that I could not see any immediate
problems with doing something like
if ( instanceof StatementListProvider ) { do stuff with statements }
I started wondering why this is not bad, since I've definitely seen
some code that got seriously bad by doing this. And I've come to the
conclusion that this is fine:
function storeStatementsOfEntities( EntityDocument[] ) {
if ( instanceof StatementListProvider ) { store statements }
}
While this is not:
function storeAllPartsOfEntities( EntityDocument[] ) {
if ( instanceof StatementListProvider ) { store statements }
if ( instanceof FingerprintProvider ) { store fingerprint }
// ...
}
In other words, if the context is specifically about one thing that an
entity can have, then it is fine. If on the other hand, you need some
general handling for whole entities, such as for diffing them,
serializing them, etc, then a different approach is needed. The pseudo
code above should make it clear why this is the case. (The second code
suffers from a big Open Closed Principle violation. You'd need to
modify this if an extension adds a new type of entity containing a new
type of field, which you cannot do, since the dependency would go in
the wrong direction. So you become unable to define new types of
entities via an extension mechanism.)
IIRC the lua handling code does something with whole entities, and
thus falls into the second category. If that is the case, then you
probably need to do something like what I outlined here:
https://lists.wikimedia.org/pipermail/wikidata-tech/2014-August/000546.html
Cheers
--
Jeroen De Dauw -
http://www.bn2vs.com
Software craftsmanship advocate
Evil software architect at Wikimedia Germany
~=[,,_,,]:3