Over abbreviated 10

© Giant Ginkgo

Matthew Weier O’Phinney announced Zend’s naming scheme for the Zend Framework from the point where PHP 5.3 namespaces are used. The issue is, that the PHP parser does not allow class Abstract, neither interface Interface as both “abstract” and “interface” are reserved keywords. So Zend suggests prefixing interfaces with “I” and abstract classes with “A”. Hungarian notation for classes and interfaces.

One of the bullet points in the list of “what makes a name a good name?” is and will be forever “as short as possible, as verbose as needed”, other points are “you must understand the name without studying specific rules before”. The last is why hungarian notation sucks so tremendously. The IFoo/ABar violates two of those criteria: first it is not as verbose as it could be with just a few keystrokes more: AbstractBar would work fine and is much clearer. At second it introduces a special notation you have to grasp before. While AbstractBar would be as descripive as possible, ABar is cryptic for those who are not lucky enough to practice Python programming.

If we are at it, the scheme makes it impossible to have grammatically correct names: IFoo would be read as InterfaceFoo which really should be FooInterface. And no, the fix is not FooI.

Filed on 30-06-2008, 17:05 under , , & ten comments & one trackback


Trackback specific URI for this entry

  1. Trackback from WEBLOG (Tobias Schlitt - a passion for php)
    posted on June 30th 2008, 07:50:27 pm iRefuseToUse aNamingScheme

    I find the recent discussion about good naming schemes quite funny. Namespaces are potentially coming in PHP 5.3 (does anyone believe?) and people start discussion about how they can even shorten their names from Abstract to aSomething and from Interface


  1. Matthew Weier O'Phinney returns:
    published on June 30th 2008, 06:40:46 pm *

    Part of the reason I put the blog post out there was to gather input from the larger PHP community; I think that we need to come up with standards that will serve a large cross-section of projects.

    While I understand that it looks like Hungarian notation, the question I pose to you is: do you feel that other languages have approached this incorrectly? Part of the reason for the leading ‘I’ prefix is for brevity; when used as part of a standard, it is an easy to recognize sigil. Would you rather type FooInterface or IFoo? Yes, the former uses natural language, but leads to RSIs.

    That said, thanks for opening the discussion further; I’ll be taking entries like yours into consideration as we finalize our plans for Zend Framework.


  2. Derick answers:
    published on June 30th 2008, 08:19:55 pm *

    I’d definitely pick FooInterface over IFoo. It’s much clearer and can’t be mistaking for lFoo.


  3. Pelle returns:
    published on June 30th 2008, 08:50:09 pm *

    I would also pick FooInterface over IFoo. Much clearer.


  4. Lars Strojny responses:
    published on June 30th 2008, 09:13:40 pm *

    It’s RSI anyway, isn’t it. Zend::View::AView is as redundant as Zend::View::AbstractView. The only difference is clarity and clarity is important.

    In our in-house extension of the Zend Framework we use the namespaces in 5.3. We also stumbled upon the naming problem. We solved it by a) not requiring interfaces to be have "Interface" in the name. So a generic interface for decorators might be named Decorator, not DecoratorInterface. The other constraint was, that we wanted to have the base packages clean of files. So everything in "Prefix/*" must be a package, not a class. This means we are forced to repeat names like Prefix::View::View. I admit this might cause some redundancy but it is pretty clear.


  5. Richard@Home answers:
    published on July 2nd 2008, 12:50:15 pm *

    The RSI argument is a poor one. Most developers use (or should be using) a competent IDE which should have code completion.

    Cryptic Code = Bad Code

    The problem with hungarian notation was perfectly demonstrated with the evolution of Visual Basic. Initially the recommendation was to preface integers with ‘i’ (eg. iCount). Then as more datatypes were added to mix they recommended ‘int’ (e.g intCount) to differentiate between an integer and something else beginning with ‘i’. It wont be long before they’ll be recommending integerCount and then tinyIntegerCount…

    What will you do in a few years when PHP introduces something else beginning with ‘I’?


  6. Richard Lord responses:
    published on June 30th 2008, 09:57:06 pm *

    I’d prefer Foo. If it implements Foo it’s a Foo. If it implements FooInterface is it a Foo or a FooInterface? Similarly if it implements IFoo is it a Foo or an IFoo?


  7. Jay Pipes means:
    published on July 1st 2008, 06:10:42 pm *

    Hi! I actually prefer to name interfaces based on the contract which they enforce. For instance, if a class can install itself (e.g. implements an install() method), I would call the interface IsInstallable.

    This tends to force me generalize interfaces for multiple classes and focus the interface contract on what the class says it will do, instead of trying to tie an interface to a specific class, like FooInterface (that’s more what abstract base classes are for IMHO).

    So, I end up with interfaces like:


    This then helps to define the API that exists between objects, and since instanceof checks for interfaces, it makes it easy to see if a class implements a specific behaviour…

    Just my 2 cents.




  8. Lars Strojny supposes:
    published on July 2nd 2008, 10:57:32 am *

    Hi Jay,
    I’m not sure if the metaphor "acts as" is that helpful. If a class implements a certain interface, it is in fact a "Foo", not just acts as a "Foo". "Acts as" sounds like duck typing, where a the implementor of "Foo" is not really "Foo" but just acts like being a "Foo". I also like "Countable", etc. but I’m not sure if the prefix "Is" is really needed.


  9. Evert responses:
    published on July 3rd 2008, 04:46:57 pm *

    Can’t say I mind the IFoo ABar syntax.. Especially the interface form is used across a lot of languages.


Add a Comment & let me know what you think