Why CI3 requires ucfirst-case names for all classes? |
(03-02-2015, 04:16 PM)Maximw Wrote: Hello. 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. (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. 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.
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 (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. 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?
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. (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 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. (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? 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.
04-29-2015, 02:35 PM
(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. |
Welcome Guest, Not a member yet? Register Sign In |