Welcome Guest, Not a member yet? Register   Sign In
Why CI3 requires ucfirst-case names for all classes?
#1

(This post was last modified: 03-04-2015, 02:58 PM by Maximw.)

Hello.
I can not understand this innovation. Why I can not name classes as I want, in CamelCase or in snake_case? Just autoload file for class with same name and .php extension. What's problem?
Thank you.
Reply
#2

(03-02-2015, 04:16 PM)Maximw Wrote: Hello.
I can not understand this innovation. Why I can not name classes as I want, in CamelCase or in snake_case? Just autoload file for class with same name and .php extension. What's problem?
Thank you.

I don't know the reasoning, but my guess would be for maximum compatibility across operating systems. I know that in the past I've hit problems where I was developing on a Mac (with a case-insensitive filesystem) then had things not work when pushed onto other servers running traditional flavors of linux, that did have a case-sensitive filesystem.

Other than the first letter, though, you can name it however you want.

And besides, every framework will have standard workflows they encourage or enforce. That's just part of the deal when you use someone else's codebase.
Reply
#3

(03-03-2015, 11:55 AM)kilishan Wrote: I don't know the reasoning, but my guess would be for maximum compatibility across operating systems. I know that in the past I've hit problems where I was developing on a Mac (with a case-insensitive filesystem) then had things not work when pushed onto other servers running traditional flavors of linux, that did have a case-sensitive filesystem.

Other than the first letter, though, you can name it however you want.

And besides, every framework will have standard workflows they encourage or enforce. That's just part of the deal when you use someone else's codebase.

Maximum compatibility across operating systems? Maybe, but I don't think so.
PSR-1 tells us "Class names MUST be declared in StudlyCaps". If problems with file system compatibility was real, PST-1 would have the same problems.

I don't have anything against framework standards. But they are designed to solve problems. I just want to understand reasons of choice Ucfirst standard and problems it solved.

P.S. Sorry for my ugly English.
Reply
#4

AFAIK, CI doesn't implement any of the PSR's yet.
Reply
#5

CodeIgniter does not conform to any PSR "spec" yet. That might be something adopted in an upcoming version.
In the meantime, we have our own convention, which is used by the class loader, for better or worse Undecided
Reply
#6

(03-04-2015, 08:25 PM)ciadmin Wrote: CodeIgniter does not conform to any PSR "spec" yet. That might be something adopted in an upcoming version.
In the meantime, we have our own convention, which is used by the class loader, for better or worse Undecided

Thank you for answer.
I know that CodeIgniter does not conform to any PSR. It was just for example of absence problem with filesystem.

If you know, could you tell me, please, why this convention was accepted only in CI3, but CI2 works excellently without it? Which problems does this convention solve?
Reply
#7

The CI2 convention is equally (if not moreso) arbitrary. For an example, see the user guide's page on controllers: http://www.codeigniter.com/user_guide/ge...html#hello

Quote:Let's create a simple controller so you can see it in action. Using your text editor, create a file called blog.php, and put the following code in it:

Then, further down the page:
Quote:Note: Class names must start with an uppercase letter.

So, the explanation for the ucfirst file name in CI3 is to conform to the normal association between class name and file name. In CI2, your blog.php file contained a class named Blog. In CI3, the Blog.php file contains a class named Blog.
Reply
#8

(This post was last modified: 03-05-2015, 11:07 AM by Narf.)

(03-05-2015, 08:12 AM)Maximw Wrote:
(03-04-2015, 08:25 PM)ciadmin Wrote: CodeIgniter does not conform to any PSR "spec" yet. That might be something adopted in an upcoming version.
In the meantime, we have our own convention, which is used by the class loader, for better or worse Undecided

Thank you for answer.
I know that CodeIgniter does not conform to any PSR. It was just for example of absence problem with filesystem.

If you know, could you tell me, please, why this convention was accepted only in CI3, but CI2 works excellently without it? Which problems does this convention solve?

In short: it's a way simpler convention than the one CI2 had, allows us to achieve higher performance and an easier autoloader implementation in the future.
Reply
#9

(03-05-2015, 11:06 AM)Narf Wrote:
(03-05-2015, 08:12 AM)Maximw Wrote: If you know, could you tell me, please, why this convention was accepted only in CI3, but CI2 works excellently without it? Which problems does this convention solve?

In short: it's a way simpler convention than the one CI2 had, allows us to achieve higher performance and an easier autoloader implementation in the future.

It doesn't look like the speed is improved by this change. Comparing system/core/Loader.php::model in CI2 and CI3 doesn't show any possible speed improvement.

CI2 does:

$model = strtolower($model);
require_once($mod_path.'models/'.$path.$model.'.php');
$model = ucfirst($model);
$CI->$name = new $model();

while CI3 does:

$model = ucfirst(strtolower($model));
require_once($mod_path.'models/'.$path.$model.'.php');
$CI->$name = new $model();

The ucfirst convention is unusual on Linux systems and it is annoying to type a file name with an uppercase when opening the file in vim or a terminal (that's what prompted me to reply to this thread now).

On the other hand, Windows and Mac users feel more at home because they open files with mouse clicks (so they don't care about upper/lower cases) and (if I remember right) Windows creates new files with an uppercase as the first character.

So, if you use Linux and think the ucfirst naming convention is odd and inconsistently applied in CI3, remember your OS is less than 2% of the market share.
Reply
#10

(This post was last modified: 04-29-2015, 02:36 PM by PaulD. Edit Reason: spelling mistake )

Although the Ucfirst convention is not an issue, and actually I personally like it as a reminder to ucfirst my controller names, I had a weird experience on Notepad++ and its inbuilt FTP default plugin.

I had a controller correctly named Search and the filename correctly named Search.php on creation, but when I downloaded it, it became 'search.php' and uploaded as a new file called 'search.php'. It took me ages to realise why my changes were not taking affect :-)

It seems to happen on single word filenames sporadically.

Just thought I would mention it as it amused me to find a bug in the awesome notepad++.

Paul.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB