Do not use "C" for prefixing custom/extension classes

Hi,

I am seeing more and more extensions for Yii that use “C” for prefixing their class names. I won’t mention any specific ones, but there are a number of them, there’s no doubt about that.

All classes in Yii are prefixed with “C” in an attempt to avoid, or at least lessen the chance for, name collisions in PHP below version 5.3 (since it doesn’t have support for namespaces). As far as I know this is not an official reservation/convention, but it is mentioned in the Guide (at http://www.yiiframework.com/doc/guide/1.1/en/basics.convention#code) as follows:

In my opinion, noone writing Yii code should use “C” as the first character in their class names, unless it’s the start of a word (i e the next letter is lowercase, in which case the C is not a prefix). The reason for this is to let Yii core classes use “C” as their prefix, both to make room for future classes and to make it easier to distinguish custom/non-Yii classes and Yii classes. It could also make the convention clearer.

When writing extensions, I suggest we use “E” as the prefix, or a prefix that is an abbreviation of the author’s name or something like that. Anything but what the Yii core uses, at least.

Yii core developers; Can we make this not just a recommendation but a formal convention? I mean that C is reserved for Yii core classes and should not be used by others, such as extensions.

Also, if anyone else than me feel this question/issue is of some importance, would it be a good idea to pin this topic to the top of the subforum, så that extension developers see it when browsing here?

Or maybe even better, make a new paragraph in the Convention section in the Guide, named "Extensions", in which some key rules for extension development are explained.

Thanks,

Pinned.

Agree. Unfortunately even some popular extensions use the “C” prefix. Shouldn’t we have a big red note about this on the page where you can submit your extension?

Yes. Maybe there should be some rules. I completely agree about not using C as a prefix. So to begin with:

  1. Don’t use C as a prefix for your extension classes. C is for core framework and Zii functionality.

  2. It should be documented. Code without documentation is relatively useless.

  3. ???

I definitely agree…

Agreed

Re-opening or continuing discussion…

I totally agree! A bit off-topic, but also related (to not to open a new thread). What piece of software you (and others) would suggest as good and tested for professional Yii Extensions’ code documentation? What is used to document core Yii, etc.?

Trejder

Core Yii is documented with text files in markdown that are converted to HTML then.

http://code.google.com/p/yii/source/browse/trunk/build

Also I wrote a simpler variant to generate YiiExt documentation:

http://code.google.com/p/yiiext/source/browse/trunk/app/commands/GenerateDocsCommand.php

Thanks, samdark! :]

Would it make sense to require all Extension classes to have the prefix "X"?

For instance - I’d like to use the “image” extension, but I already have a model class called Image.

cshehadi, it’s not a requirement but rather a good practice to do so. Nowadays a lot of extensions are using E as a prefix.

Is that a recommendation that extension classes use an E prefix?

I can’t speak for Yii officially, but the two main points for me are; 1) Dont use “C” as the prefix. 2) Do use a prefix, so that non-prefixed class names can be used for components/extending classes (for example FooBar when we extended CFooBar, this way it’s really clear that the class in question is just a wrapper for the main one).

If you don’t have any specific prefix you’d like to use (for example your initials or an abbreviation for your company name), I’d default to “E”.

I suggested "E" at the beginning, however somebody pointed out that "E" is usually used for Exceptions.

There isn’t any rule, however I’d actually use the “X” prefix for eXtensions.

  1. DO NOT open an extension just to preserve space (placeholder)… without putting a link for a download and/or incomplete documentation !

As there where still some new extension that did not follow the guidelines I just unpinned this topic and created a new one so that the main guidelines are more visible

http://www.yiiframework.com/forum/index.php?/topic/19538-guidelines-for-extensions/