This page includes miscellaneous notes about the design of <harmony>.
Classes versus Interfaces
Should the specification use classes or interfaces?
There are three undesirable side effects that may be caused by the use of interfaces:
- Conceptual overload: potential, a programmer need to deal both with interfaces and the classes implementing such interfaces.
- Reduced portability: game code that subclasses vendor specific classes will be harder to port from one implementation to another.
- Broken window: where classes are forcibly used to program code, it is likely that those classes will give access to functionality that the original interfaces do not provide. Additionally, game programmers may be more tempted to cast interfaces to their actual implementers to access non standard functionality.
Enumerations cannot grow. In most cases where <harmony> requires enums, it is difficult to predict in advance what the enumerated elements will be. Examples
- body parts
- enumerated activity states (e.g. walking, running, striking, idle, …)
However enums are fast and conversions with int are transparent.
The <harmony> specification provides sample enumerations, however the actual types supported by the API are generic.
In the original draft, I provided two actor interfaces, <Actor> and <MutableActor>. The question was to find out whether this distinction should be generalized or removed.
Pros and cons of distinguishing between mutable and immutable versions of entities:
- When a system’s dynamics become complex, it is often convenient to localize all write accesses to a given part of the system - the idea is a given part of the system processes events and modifies it’s own state in response to such events, rather than external modifications affecting the state of the object directly. Notably this makes coordinated state change easier.
- Typically, simplifications and optimizations are possible when immutable states are known in advance.
- The distinction is not intuitive.
- In Objective C, it may be difficult to provide accessible properties while maintaining the above distinction. Properties, however, are convenient.
Provisionally the distinction will be removed. However, entities may be reformulated later on, using the following pattern:
- @interface Actor <ReadableActor,WritableActor>
This allows resolving simple cases without worrying about the readable/writable distinction, while allowing game programmers to purposefully restrict access should they wish to do so.