Coding Standards

:mellow: I see coding standar is not so important because you could format it by the IDE easily when you are reading codes and let people to write codes in ways make them comfortable.

;D

Should I say that IDE auto-formatting usually breaks on constructs having more than 2-3 formatting elements.

Besides, you checkout the framework from SVN and what - format the whole project? o.O

A project should be written to meet one set of coding standards, if you work on a project you follow that projects coding standards, even if you don’t like it. Personally:

Tabs vs Spaces

Tabs for indentation and spaces for aligning, the two are separate. I prefer tabs as everyone can have it flow how they want it. The trouble with treating spaces as tabs is that if one person commits two spaces and another three it falls down. Personally my tab stop is 3!

Yoda Style

I’m all for this, given a little time you start doing it without thinking and it’s safer. Once you’re programmed to do it you find it doesn’t take longer to read the code but there is a little re-training involved. Saying you’ll never make that assignment mistake is a little naive also ;p

Single Line Conditions

In favour of these, they make it absolutely clear that line’s scope. It may seem overkill but again it’s a little bit safer. Especially if there’s lots of lines together sometimes that indent is not entirely obvious and you skip over it. On that note, I always put the opening brace on it’s own line too.

Finally

The core Yii! team set the coding standards and as it stands they are the ones that are going to be coding using it. However if they do decide to grow the team then the decisions of coding standards that are easy to pick up and use should be considered and surely people using Yii! day in day out are a good source on opinions on this matter.

I agree, it is up to the core team to agree on coding standards.

This is despite the fact that I would do things differently.

It would however be great if they could publish them.

So you’re willing to write your expressions backwards, making the code less legible, prevent yourself from making typos.

I don’t get it.

If you’re worried about making this mistake, the if ($dummy = true) statement can be easily detected and highlighted by an IDE. This problem should not be solved by garbling your code, but by using proper tooling.

If you are as l33t as you appear to be, why are you letting your tools take the responsibility of making sure that your code is correct?

My advice would be to trust experienced programmers.

Oh, and another thing you’ve got wrong: Samdark is actually against Yoda conditions as is apparent from the quote you posted.

As a C++ programmer as well as a PHP programmer, I embrace all coding conventions which helps to ensure that my code is correct.

But that’s probably just me. ;)

Yep, I’m not a star wars fan :)

YES, YES, YES!!!

Same happens in NuSphere PHPEd.

PLEASE, PLEASE, PLEASE - add brackets to a single line and stop doing this:




if(is_file($viewFile.$extension))

	return Yii::app()->findLocalizedFile($viewFile.$extension);

else if($extension!=='.php' && is_file($viewFile.'.php'))

	return Yii::app()->findLocalizedFile($viewFile.'.php');

else

	return false;



because it is really hard to guess breakpoints in debug mode.

Instead, it should go:




if(is_file($viewFile.$extension)){

	return Yii::app()->findLocalizedFile($viewFile.$extension);

}else if($extension!=='.php' && is_file($viewFile.'.php')){

	return Yii::app()->findLocalizedFile($viewFile.'.php');

}else{

	return false;

}



I recommend following the Pear coding standards.

Lubos

for me the frameworks code base is a black box

but the community around yii should agree to a coding standard for extensions

Agree on black box

I think class methods that are declared as protected or private must begin with a single underscore.

That was a convention for languages which didn’t really support visibility declaration… you used _ to remember that a method/property was “private”

You should suggest to fix their bug

There’s nothing to fix, since there’s no bug.

Server parses executed script and sends to IDE debugger listener information about executed line. Debugger listener check if such a line has a breakpoint set by developer - if yes, it pauses script execution and waits.

The problem is that it is hard to guess which line will be a valid breakpoint line parsed by server. If you put e.g. two PHP commands into a single line or if you dont use brackets (but single line instead) then you have a chance 50% that you will set breakpoint at line that will be skipped. Then you must try more breakpoints to “find” the right breakpoint line. It’s a bit of frustration sometime. That’s why I recommend PEAR syntax - it encourages debugging-problem-free code standards.

It’s hard to explain - if you try you would see…

Yeah, indeed I don’t really understand the issue… it seems a non-issue to me

Imagine this code:




01: if ($condition)

02:  foo();

03: else

04:  bar();



If you set a breakpoint on line 2 or 4, the debugger won’t break. Instead, you had to set the breakpoint at the first line of foo() or bar().

With the following code, there are no such problems:




01: if ($condition) {

02:  foo();

03: } else {

04:  bar();

05: }



You just set the breakpoint and it stops execution. Might be a problem of the debugger, or some sort of PHP opcode generation/ optimization. Don’t really know. Maybe it will get fixed some day. But till then, braces help debugging.

If it is like that, then it looks to me like a debugger issue. And in my opinion that code is much more readable without useless baces.

Regarding braces for single line if statements here is a nice discussion - http://stackoverflow.com/questions/691476/are-singleline-if-statements-or-if-statements-without-braces-bad-practice

+1 to that. ;)

Completely agree. Only here is very important word.

Never, never and never use spaces instead of tabs for indention. Don’t change fw style at this part. It’s very important.

May be this is a good idea. But please don’t change brackets style from this:




if

{

    ...

}

else

{

    ...

}



to:




if {

    ...

} else {

    ...

}



It’s ugly, in addition to another 10 reasons (code folding for example). And one of them: open any fw file. Immediately we can say that this is Yii. Not f…g Zend, not b…t Symfony(even 2). It’s Yii.

May be this is a good idea too. But only in comparsions (and maybe ‘key’ => ‘value’ delimeters, expressions). What i mean:




if($x === true)



Yes, tolerantly. But:




if ($x === true)



And things going bad.