Basically, I had a Github mail conversation with Mike Cann about the
possibility of an entity serialization implementation in Swft,
somewhat inspired by PushButton engine's XML-serialization package,
but without the numerous inline property referencing (and inline node
properties) found in PushButton's serialization implementation.
The specs can be found here:
http://wiki.github.com/Glidias/CityFly/xml-serialization-and-fcss-specifications
In short, I came up with a system to allow spawning of entities via
XML configurations (and varying stylings through CSS property
settings, and the ability to add components to entities). However,
based on my experiences with this and what MikeCann said, it's obvious
that XML/CSS configurations will have a disadvantage when it comes to
type-safety, particularly during refactoring.
How I'd reply to such known aspects:
Yup, what you said clear pointed out a fact that it's easy to end up
having misspellings when writing class names in an external file.
Even though test-checks can be made at runtime to check the validity
of the XML and it's ability to spawn entities correctly, it's done at
runtime rather than compile time.
Generally though, when it comes to any dependency, it must always be
checked at runtime, that's why SwiftSuspenders will throw errors to
inform the user of missing dependencies. However, in the context of
Swft, we also need to know which entity is currently being tested. The
EntityMap doesn't really provide this functionality (and it shouldn't,
because it assumes all dependencies are met). Doing this in
EntityXMLSpawn isn't really required either, because one can use the
following method with try/catch as shown below to test that all of
your concrete entity classes can be created within Swft:
bc. public static function
testEntities(entityMap:IEntityMap, ...args):void {
for each (var classe:Class in args) {
var chkEntityClassName:String = getQualifiedClassName(classe);
try {
entityMap.createEntity( classe );
}
catch(err:Error) {
throw new Error("Entity creation failed for:
"+chkEntityClassName + "\n");
}
}
}
// And somewhere in your app, list out all your entity classes
testAllEntities(
entityMap,
ClassA,
ClassB,
ClassC
);
After all, eventually you'll need to list out all your coded classes
anyway in order for them to be compiled. So, doing testing in
EntityXMLSpawn (with it's initXML configuration) isn't really
required, through you can play around with varied stylings/component-
additions without having to recompile under a xml-based node id.
Generally, that's the purpose of EntityXMLSpawn, varying stylings/
settings without having to re-compile (which is actually the premise
behind F*CSS/Flash Camouflage) actually, which actually defers a lot
from what most RobotLegs people tend to prefer (which is compiled
configurations).
However, it's very true that with *any* given XML/CSS property
configuration, one of the issues often faced is that in the event you
refactor your classes ( change of variable/classnames names and
such...), your CSS properties would have to change to match those
values (Of course, F*CSS applicator provides hooks which you can
extend to throw runtime warnings/errors for unmatched CSS properties,
but again this only done at runtime), So, in the sense, hardcoding
operations/settings through extended classes or factory methods would
obviously provide type-safety at compile time. After all, why lose the
benefits of a compile-time language?
Additionally, in order to spawn an entity, you need to reference this
by some arbitrary id in your code. If you had a concrete factory
method for this, you get type-safety and clearly defined parameters,
albeit you have to spend time coding that process, it allows you to
clearly document the process of objection creation within the scope of
a factory method as well. When you have an external XML configuration
which is used for your "spawn" node implementation, it is assumed the
node id is already there. The coder would have to write
"spawn('someIDWhichIhopeDoesExists') within the code, and hope
everything runs fine "magically". If you change the XML configuration
ids, than your code would have to change as well. If you re-factor
your code, than the XML/CSS would have to change to match that. In
short, the benefits of custom coded compile-time classes/factory-
methods are too good to ignore. To some, the only reasonable basis for
XML configurations is to be done at the end of the app-development
cycle, where you just one a list of end-user settings to be used in
varied circumstances (saved games, user options, etc.), which are
simply tailor-made to the finalised game.