Nim's braindump Swords, code and a dirty mind!

9Mar/111

On naming Interfaces

Just about every programming book or OOP example I look at has the annoying habit of prefixing interface names with an I. Yes, IInterface, ICar, IWallet, IMoney, IIAmStupid. It's one of my pet peeves, I admit, but every time I come across code like this I find myself suppressing murderous tendencies.

Why oh why would you do this? "To clearly indicate that it's an interface". Why the hell do I need to know that it's an interface in the first place? If I want to use your library, I really don't give a toss whether I'm talking to an interface or a concrete class. If I do want to know (because I'm extending or initialising it) then I'm quite capable of figuring out for myself whether I'm dealing with an interface, abstract class or concrete class. The only thing this random I does is make it harder to look for suitable classes. I want to search for Car, or Wallet, or Money. Not to mention that I don't want to type that extra letter every single time I'm assigning an instance to a variable.

Seriously, how ugly is this
IFoo foo = IFooFactory.createIFoo();

The irony here is that I used "I" 32 times in this post. But for crying out loud, pick a meaningful name, not some silly prefixed monstrosity.

flattr this!

Tagged as: , Leave a comment
Comments (1) Trackbacks (0)
  1. I’d rather do it the other way round: Suffixing the concrete classes with ‘Impl’. In my opinion it’s more clean (no garbage when you’re searching for a Car class) and ‘safer’ (warning to the developer when they see that ‘Impl’ word, programming to an interface as its named).

    I’ve seen a lot of .NET devs who do that kind of prefixing. Even with local(!) variables lol


Leave a comment

(required)

No trackbacks yet.