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