The I in Interface
I'm sometimes asked why the interfaces in Flint don't start with a letter I. The simple reason is that I think this practice, while common among Actionscript developers, is so seriously flawed that it's better not to do it, even if it is common among other developers and may cause some initial confusion for some.
The argument for
The only argument I've heard in favour of this practice is that it enables a developer to know whether a type is a class or an interface just by looking at the name, but I'm not convinced.
It's more confusing
Looking through the core Actionscript classes, I do a double-take at classes like ID3Info - (What's a D3Info? Oh, it's a class not an interface.)
Or, consider what might happen if you were creating an application that interacts with mobile phones. You are very likely to have a type called IPhone. But is that a standard phone interface that all phone classes should implement? Or is it a class for the iPhone implementation?
Same name, different type
And it's not just confusion over whether something is an interface or not. What makes a class an EventDispatcher? Is it any type that extends EventDispatcher, or is it any type that implements IEventDispatcher. The I is just a prefix indicating that a type is an interface, so we have two EventDispatcher types. Without the I prefix this wouldn't be possible.
But we copied it from Java, didn't we?
Actionscript developers have adopted the I prefix because Adobe did so. But why did Adobe adopt this idea? Common thinking is that they adopted the idea from the Java community, which sounds plausible. Many of the ideas in Actionscript originated in other languages.
However, using an I prefix on interfaces isn't a standard in Java. In fact, it's just the opposite. Look at any of the Java core api, or any other code developed by Sun, and you'll not see an I prefix on the interfaces. And it's not just Sun, many other large Java development companies don't use the I prefix (Google, for example). Far from being a Java standard, the I prefix is an aberration adopted in some corners of the Java world, possibly by ex-Microsoft developers.
Why ex-Microsoft developers? Because Microsoft used to use Hungarian Notation in all their code (Charles Simonyi, who invented Hungarian Notation, became chief architect at Microsoft). The reason Hungarian Notation works is because it requires every name to have a prefix. So iPhone is the Phone interface (i prefix for interface) and cIPhone is the IPhone class (c prefix for class).
Problems occur when only some names have prefixes, as with the I prefix for interfaces and no prefix for classes. Unfortunately, this is the pattern that Adobe have adopted for Actionscript (and that Microsoft have adopted for C#, but even C# isn't perfect).
This is why I don't use the I prefix on interfaces in any of my code, including Flint.
Share this post or a comment online -
Also in the collection Actionscript
- Finite State Machines for AI in Actionscript
- Singletons - we're better off without them
- Simple example of acceleration
- List Loader for Actionscript 2
- Singleton Factory
- Events in Actionscript 2
- Different types of weak references
- Events in Actionscript 3
- Creating weak references in Actionscript 3
- Polling the keyboard in Actionscript 3
- Radial Perlin Noise
- The parentheses operator
- Object Pool class
- Four ways to link a list (a performance test on linked list architectures)