Welcome Guest, Not a member yet? Register   Sign In
name conventions in CodeIgniter are not mainstream?
#1

[eluser]ajsie[/eluser]
i had a look at the user guide's style guide and realized that they are not following the mainstream.

often you use camelcase to name your variables, classnames and methodnames. CodeIgniter says you should use underscore.

often you type a function like this:

function foo($bar) {
// ...
}

they say you should do it like this:

function foo($bar)
{
// ...
}

i wonder if these are best practices since they go against others, eg. java/javascript conventions, which are quite mainstream.

share your cents!
#2

[eluser]skunkbad[/eluser]
[quote author="ajsie" date="1271047436"]i had a look at the user guide's style guide and realized that they are not following the mainstream.

often you use camelcase to name your variables, classnames and methodnames. CodeIgniter says you should use underscore.

often you type a function like this:

function foo($bar) {
// ...
}

they say you should do it like this:

function foo($bar)
{
// ...
}

i wonder if these are best practices since they go against others, eg. java/javascript conventions, which are quite mainstream.

share your cents![/quote]

I guess it depends what you call mainstream. Since CI is my mainstream, it's the other ways that aren't mainstream to me.
#3

[eluser]InsiteFX[/eluser]
Nothing states that you have to follow CodeIgniter's way.
It's just a recommendation of a way to do it.

But personally I like their way of doing it's well structure
and very easy to read. May be that's why CodeIgniter has one
of the best forum's and documentation around.

Plus some very intelligent programmer's in these forum's.

But everyone to their own opinion. If you prefer CamelCase then
use it. It's really up to you how you would like to write code.

InsiteFX
#4

[eluser]ajsie[/eluser]
yes i definetely agree that they got good coding style.

just one thing i noticed. they recommend you to type like this:

function name()
{
// code
}

but in the library classes they type the class like:

class name {
// code
}

why would they not follow their own rules and stay consistent?
#5

[eluser]InsiteFX[/eluser]
Some of the libraries are before the coding standards were put into place.

InsiteFX
#6

[eluser]janogarcia[/eluser]
http://ellislab.com/codeigniter/user-gui..._indenting
Quote:With the exception of Class declarations, braces are always placed on a line by themselves, and indented at the same level as the control statement that "owns" them.

Opening braces in the same line as the class declaration is what their coding style recommends, so they are in fact following their coding style guide.
#7

[eluser]ajsie[/eluser]
[quote author="janogarcia" date="1271080373"]http://ellislab.com/codeigniter/user-gui..._indenting
Quote:With the exception of Class declarations, braces are always placed on a line by themselves, and indented at the same level as the control statement that "owns" them.

Opening braces in the same line as the class declaration is what their coding style recommends, so they are in fact following their coding style guide.[/quote]

ahh ... didnt see that! but then the question is...why an exception for classes? hmm...
#8

[eluser]Phil Sturgeon[/eluser]
[quote author="ajsie" date="1271047436"]i wonder if these are best practices since they go against others, eg. java/javascript conventions, which are quite mainstream.

share your cents![/quote]

There is no "JavaScript convention", just general coding indent styles. EllisLab have made a great standard by taking some of the Zend style and using Allman indent style to make a simple, readable standard.

This can of course be totally ignored at your pleasure, Derek Allard wont send the robots after you just for that.
#9

[eluser]thomas.ernest[/eluser]
Hi there,

Just to let you know that I'm used to develop with PHP_CodeSniffer [phpcs] to check the coding convention of my php code.

However, it doesn't support Code Igniter style guide [ci-style] natively. So, I've developed something. It doesn't check all standard requirements, but already more than nothing.

[phpcs] http://pear.php.net/package/PHP_CodeSniffer/
[ci-style] http://ellislab.com/codeigniter/user-gui...guide.html
[ci4php-cs] https://github.com/thomas-ernest/CodeIgn...odeSniffer




Theme © iAndrew 2016 - Forum software by © MyBB