« field prefixes | Main | XML versus APIs »

A break from the Norm

More on interfaces. I like this passage:


If you read my post and Cameron's carefully, you noticed that we are not trying to resurrect the Hungarian notation completely, but we are simply pondering ways to adapt it to Java.

Russell Beattie:

If you follow the IFoo convention, and you want to change a class into an Interface, you have to change all the places it is instantiated and all the places it is used (in method arguments and declarations).


This is not really a problem if you use a good, modern IDE.

This argument doesn't stand up when you start thinking about published APIs. I don't think an IDE, however good, can refactor a client's code. Especially the ones I don't know are using my code.


Cedric: Since we are harping about conventions, here is another one that is finally gaining some momentum in the Java community, despite being pushed forth by Microsoft in the first place: all interfaces should begin with "I" (e.g. "IWorkspace").
The standard argument against such a practice is, again, that it breaks encapsulation: "I am dealing with a type, I don't care if it's an interface or a concrete type."
Well, you should, because they are not equivalent. For example, you cannot "new" an interface, and it's the kind of information I would like to have right off the bat, not when I do my first attempt at compiling and realize that now, I need to find a way to find a concrete implementation of the said interface.

Mmm, hardly. The fact that you can't construct against an interface doesn't imply you should mark its name with an 'I'. Indeed it's irrelevant - what possible help marking an interface with an 'I' is escapes me - what can that information tell me the context of the code cannot? To be honest I'm not interested in whether something is an interface, I'm interested in its interface- which as Parnas said years ago, is the combination of signature and behaviour.

Sorry, I don't get the rationales.

Similar arguments apply against the merits of Hungarian notation (indeed using 'I' is just that). Cedric points out that good IDEs can help us keep var iable names in sync with assigned types. First, this only makes sense in statically compiled (languages, but since this discussion is going around Java weblogs, we can let that go). Second, , I don't want to depend on an IDE for such an arbitrary reason, or to help me write noisy code. Third while I buy the argument put forward that we can adapt to any convention, that's not an argument to say we should to adapt arbitrary ones. I'm inclined to say let the Hungarian notation die - the best convention is the one you don't need.

Charles Miller says it best:

I prefer to have code that is easy to read in the general case, and tools that will tell me the supporting information if and when I need it. Hungarian notation is an artifact of a time when the tools weren't good enough to give us this information in any way but by throwing it all in our face at once. Now we have colour-coding, tool-tips and one-keypress navigation available to us, Hungarian notation is a horrendously clumsy anachronism. The information should be available, but not obscuring the code. Which is why I don't use Hungarian notation, but I do use a good, modern IDE.

But I didn't agree with this:

Whatever James Gosling might say about IDEs, I have little sympathy for people who think that a text-editor alone qualifies as a complete programming environment.
Things like code-completion, fast class-navigation and Javadoc access, context-aware searches (find implementors, find callers) and inline error detection not luxuries any more. They are essential to efficient programming. And if someone is deliberately choosing to program in an environment that doesn't have them, that someone is either so good they don't need additional notation, or (more likely) wasting time and money.

What's odd abut this is that many productive programmers I've worked with do not use, or depend on IDEs very much. I don't believe I'm alone in that experience. That's not to say we shouldn't use IDES, would be more productive with them, or should be dismissive of IDEs in general. But they are pretty far from neccessary. My experience is that there is no one IDE that is ideal- in Java-land, IDEA and Eclipse are close, but nowhere near sufficient. And at some point you'll always need to drop out to a command line to get something done.

December 4, 2002 09:36 PM


Trackback Pings

TrackBack URL for this entry: