EllisLab text mark
Advanced Search
     
Bug: Developers are not following their own standards
Posted: 04 January 2012 05:51 PM   [ Ignore ]
Avatar
Joined: 2010-07-10
183 posts

Quote from the Codeigniter’s userguide:

Use of || is discouraged as its clarity on some output devices is low (looking like the number 11 for instance). && is preferred over AND but either are acceptable, and a space should always precede and follow !.

A recent commit on GitHub (from ericbarnes, CI developer):

elseif ( ! $this->cur_page AND $CI->uri->segment($this->uri_segment) != $base_page)

And here is an interesting comment on GitHub by philsturgeon (another CI developer) also…

Style Guide says it prefers AND over && generally.

The question:
Why you’re creating rules and standards, when you’re not following them?!?

The result:
It is bad for the community, the followers and the developers itself…

 
Posted: 04 January 2012 06:01 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3800 posts

I agree with what you are saying.

But, I also disagree with the style guide on this point and think if you are going to use && for AND you should be consistent and use || for OR.  And if you are going to use AND, you should be consistent and use OR.  But, don’t mix them…

 Signature 
 
Posted: 04 January 2012 06:04 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-10
183 posts
CroNiX - 04 January 2012 06:01 PM

I agree with what you are saying.

But, I also disagree with the style guide on this point and think if you are going to use && for AND you should be consistent and use || for OR.  And if you are going to use AND, you should be consistent and use OR.  But, don’t mix them…

You’re right!
My point was… I know it is not so important, but if they are creating rules, they have to follow them as an example. Now the core files are full of both && and AND. The devs should be an example for all the followers, right?

 
Posted: 04 January 2012 06:12 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3800 posts

Well, technically the CI coding standards say its ok to use “&&” or “AND” for AND comparisons, but only use “OR” for or and never use ||.  They just “prefer” you use “&&” for AND.  So they are following the guide as long as they never use “||” for OR.

Logical Operators

INCORRECT:
if ($foo || $bar)
if ($foo AND $bar) // okay but not recommended for common syntax highlighting applications
if (!$foo)
if (! is_array($foo))

CORRECT:
if ($foo OR $bar)
if ($foo && $bar) // recommended
if ( ! $foo)
if ( ! is_array($foo))

 Signature 
 
Posted: 04 January 2012 06:19 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-10
183 posts

@CroNiX, this is not Ok for me…

User Guide:

&& is preferred over AND

Developer:

Style Guide says it prefers AND over && generally.

I can fully understand that both are Ok, but it is a matter of consistency…

 
Posted: 04 January 2012 06:29 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3800 posts

But, a preference or recommendation is not a rule so I don’t see where the developer Eric Barnes broke with the standards since using “AND” is “okay but not recommended”.  If it wasn’t “okay” then yes, I would agree that he broke a CI coding standard.

I do agree with you that the standards in the case of logical operators is not very consistent.

 Signature 
 
Posted: 04 January 2012 06:44 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2002-06-19
122 posts

I wouldn’t call it a “bug.”  I use AND and OR.

 Signature 

Check out the new CodeIgniter Handbook from Jamie Rumbelow
CodeIgniter Handbook

 
Posted: 04 January 2012 06:51 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-03
728 posts

I think what victorche means is that Phil contradicts the Style Guide by saying “AND is preferred over &&”.

I don’t see a big problem here, AND and && are both valid and the Style Guide doesn’t explicitly exclude one of them. But I agree, that (core-)developers should propably be more careful about what rules they “create” and make sure the Style Guide doesn’t say otherwise…or if they make up new rules/change existing rules, they should just update the Style Guide as well and no one will ever know wink

 Signature 

Blog - Twitter

DBlog

MeNeedz: Auth - Cloud - Password - Search - Shoutbox - Akismet -
Twitter - Visitor tracking

 
Posted: 09 November 2012 11:06 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-04-26
1 posts

Coming bit late to this discussion… But I do see a problem with CI and ||, &&, AND and OR.

Style Guide says that it’s a matter of style.

But PHP manual says it’s a matter of precedence. || and OR are not interchangeable!

 
Posted: 09 November 2012 11:28 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
117 posts

Precedence in CodeIgniter’s style is resolved by adding parenthesis around conditions, when needed.

Also, these inconsistencies (and many more) have already been corrected in the develop branch on GitHub.