Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a number of conventions in Java and C# that we have grown comfortable with; but that are backwards. For example, the convention of putting private variables at the top of each class is quite silly from a technical point of view. The most important things about a class are it's public methods. The <em>least</em> important things, the things we <em>hide</em> behind a privacy barrier, are the instance variables. So why would we put them at the top?</p> <p>The "I" in front of interfaces is another backwards convention. When you are passed a reference to an object, you should <em>expect</em> it to be an interface. Interfaces should be the default; so there is no point in doing something extra, like using an I prefix, to announce that you are doing what everyone expects you to do. It would be better (though still wrong) if we reserved a special marker for the <em>exceptional</em> condition of passing a concrete class.</p> <p>Another problem with using I, is that (oddly) we use it to communication the <em>implementation decision</em> of using an interface. Usually we don't want implementation decisions expressed so loudly, because that makes them hard to change. Consider, for example, what might happen if you decided that IFoo really ought to be an abstract class instead of an interface. Should you change the name to Foo or CFoo, or ACFoo?</p> <p>I can hear the wheels turning in your head. You are thinking: "Yeah, but interfaces have a special place in the language, and so it's reasonable to mark them with a special naming convention." That's true. But integers also have a special place in the language, and we don't mark them (any more). Besides, ask yourself this, <em>why</em> do interfaces have a special place in the language?</p> <p>The whole idea behind interfaces in Java and C# was a cop-out. The language designers <em>could</em> have just used abstract classes, but they were worried about the difficulties of implementing multiple inheritance. So they made a back-room deal with themselves. They invented an artificial construct (i.e. interfaces) that would provide <em>some</em> of the power of multiple inheritance, and they constrained normal classes to single inheritance.</p> <p>This was one of the worst decision the language designers made. They invented a new and heavyweight syntax element in order to <em>exclude</em> a useful and powerful (albeit controversial) language feature. Interfaces were not invented to enable, they were invented to <em>disable</em>. Interfaces are a hack placed in the language by designers who didn't want to solve the harder problem of MI. So when you use the I prefix, you are putting a big spotlight on one of the largest hacks in language history.</p> <p>The next time you write a function signature like this: </p> <pre><code>public void myFunction(IFoo foo) {...} </code></pre> <p>Ask yourself this: "Why do I want to know that the author of IFoo used the word 'interface'? What difference does it make to me whether he used 'interface' or 'class' or even 'struct'? <em>That's his business, not mine!</em> So why is he forcing me to know his business by putting this great big I in front of his type name? Why doesn't he zip his declarations up and keep his privates out of my face?" </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload