[computer-go] Choice of interface naming style

Mark Boon tesujisoftware at gmail.com
Fri Aug 11 14:26:11 PDT 2006


As often when trying to make something public and I go over my old  
code, there are some gnawing questions concerning style. I think I am  
already using interfaces a lot. But I've never quite converted fully  
to the "always program to interfaces" paradigm. But if I'm going to  
make an extensible framework I think it's probably best to use  
interfaces with separate implementations as much as possible, as that  
will provide maximum flexibility.

The knee-jerk response to the question whether to use an interface or  
not is usually 'not' due to the overhead involved in virtual calls.  
Since I wasn't quite sure what the cost in performance would actually  
be I did a quick experiment and found that it's a bit over 10%. Not  
as bad as I feared, but still not nice. And this was just a small  
(but I think representative) code sample. Replacing an interface by a  
class (provided you have only one implementation of course) is not  
really a lot of work, so if the cost starts to get prohibitive I can  
always revert to using classes in a few selective cases.

Now to my dilemma. What would be a  good naming-convention? I've seen  
aticles that advocate using a normal name for the interfaces and  
suffix the implementations with 'Impl'. I use this convention  
occasionally. But there are a few things about it I dislike. First of  
all I don't like the ugly 'Impl' and I don't like to use  
abbreviations other than for temporary variables to avoid unexpected  
ambiguities. But 'Impementation' as a suffix is rather unwieldy. A  
more serious problem is when you have more than one implementation,  
naming soon becomes ugly or difficult to remain consistent.

Another possibility is to prefix all interfaces with an 'I'. So you  
get IChain and IGoMove etc. I think this is a Microsoft convention.  
It also goes against my rule of not using abbreviations, but since  
it's a prefix it won't easily be ambiguous. And it gets ugly when the  
interface already starts with an 'I', so you get IIntStack for  
example. But it's easy to remain consistent, so I now tend towards  
this one.

I wondered what other conventions are generally used, maybe there's  
one more to my liking.

Mark



More information about the computer-go mailing list