[TYPO3-50-general] File name conventions for classes and interfaces

Robert Lemke robert at typo3.org
Tue Dec 12 10:13:52 CET 2006


Hi Ingo,

thank you for joining the discussion.

Am 12.12.2006 um 02:58 schrieb Ingo Renner:

> IMO you can't do this when sticking to OOA/D principals because you  
> need
>
> * some interface (I actually do prefer the I-prefix)
> * then you might want to have a very general implementation "Greeter"
> * HelloWorldGreeter would extend Greeter and so on
>
> so to have the very general Greeter class you can't use its name  
> for the
> interface and thus have to come up with a different name.
>
> Another advantage of the I-prefix would also be that you automatically
> have all the interfaces together when ordering the files by  
> alphabet...

But you also have that feature if you call the files "class.*" and  
"interface.*"
like we currently do.

> And again, it is a well established and common practice in f.e.  
> Java and
> C#, and Visual Basic

Okay, although I generally agree that sticking to standards can help,  
it's
not the main objective - the most important point is that naming is  
verbose,
self explaining and easy to remember. But maybe your suggestion is  
just that -
intuitive.

Let's add some references when we say something like "it's common  
practice"
or "a standard", because that helps leading a substantiated discussion.

Sun for example does not use the I-prefix in their code conventions  
[1]. The
Jackarta project [2] as well as most of the Apache projects just  
follow the
Sun convention. The Eclipse project makes an exception and does use the
prefix [3]. On various other Java projects I googled for I did find  
the I-prefix
in interface names.

Much Java code I have seen uses a noun for the interface and the  
suffix "Impl"
for the class implementing the interface. I think that's a bad idea.

Microsoft uses Pascal case interface names with the I-prefix for  
their .NET
framework [4]. They allow adjectives for interface names but not for  
class
names.

The GNU Coding Standard (C++) [5] suggests to use  
underscores_to_concatenate_words
instead of writingThemCamelCase. That's something I really don't  
like. It seems
like they don't have conventions for class / interface naming.

There are a lot of conventions for C++ [6] and I haven't found a word  
about naming
classes or interfaces. Linus Torvalds writes in his "Kernel Coding  
Style" [7]:

    « C is a Spartan language, and so should your naming be.  Unlike  
Modula-2
      and Pascal programmers, C programmers do not use cute names like
      ThisVariableIsATemporaryCounter.  A C programmer would call that
      variable "tmp", which is much easier to write, and not the  
least more
      difficult to understand. »

In the end it also depends on the programming language and its  
culture ... So
what conventions are used in the PHP world?

The Zend Framework uses Underscores_For_Concatenating_Words and adds  
the suffix
"Interface" for interfaces [8]. There are no rules for naming  
interfaces for
the ezComponents [9] neither does the PEAR project define conventions  
for them [10].

I would say - there's not really THE standard but you're right, many  
developers
use the I-prefix and it does help distinguishing between classes and  
interfaces
on a glance. That's a good reason for using it, so let's add it to  
our guidelines.

BTW, I found a nice interview with Eric Gamma about interfaces [11].

>> Sometimes you might even want to use interfaces just because you  
>> want to
>> be able to ask the previous question - the interface doesn't
>> neccessarily add any new methods. These interfaces are then called
>> "marker interfaces" because the mark your implementation.
>>
>> You see what I mean?
>
> I don't understand your last point.

http://en.wikipedia.org/wiki/Marker_interface_pattern

> Anyway in general I would suggest to stick with (or copy from) naming
> conventions that have been in place for years - usually for a reason.

But not always for a good reason ...

Cheers,
robert

[1] http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html#367
[2] http://jakarta.apache.org/site/faqs.html
[3] http://wiki.eclipse.org/index.php/ 
Naming_Conventions#Classes_and_Interfaces
[4] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ 
cpgenref/html/cpconinterfacenamingguidelines.asp
[5] http://www.gnu.org/prep/standards/html_node/Names.html#Names
[6] http://www.chris-lott.org/resources/cstyle/
[7] http://www.chris-lott.org/resources/cstyle/ 
LinuxKernelCodingStyle.txt
[8] http://framework.zend.com/manual/en/coding-standard.naming- 
conventions.html
[9] http://svn.ez.no/filedetails.php?repname=ezcomponents&path=% 
2Fguidelines%2Fnaming_conventions.txt&rev=162&sc=1
[10] http://pear.php.net/manual/en/standards.naming.php
[11] http://www.artima.com/lejava/articles/designprinciples.html
-- 

http://typo3.org/gimmefive




More information about the TYPO3-project-5_0-general mailing list