I've been using Kohana lots and their coding style is my preferred choice. That said, it's a community project and up to us to decide what
we want.
I'll respond directly to VI's comments from the point of view of someone who's been using this style for a long while.
Quote:
Originally Posted by Village Idiot
1. Indentations
The problem with different tab spacing can be solved by having tabs set to five spaces. Most IDEs can do this.
|
Please do NOT use spaces for indenting, or tabs for aligning. Tabs should be tabs and spaces should be spaces. Most IDEs can handle things perfectly fine to use the suggested style.
Quote:
Originally Posted by Village Idiot
2. String concatenation
Why no space? It makes the code cleaner looking to do so. I would recommend having a space before and after the period.
|
I've actually come to my own conclusion that using no space makes the code look cleaner, especially with longer lines of concatenated strings.
PHP Code:
$message = 'The ' . $animal . ' ate ' . $food . ' for ' . $meal . '.';
$message = 'The '.$animal.' ate '.$food.' for '.$meal.'.';
Quote:
Originally Posted by Village Idiot
3. Single line if statements
It is not a good idea to allow single line if statements at all because it is always possible a second line will be needed. A programmer could easily accidental add a line with no brackets. Then boom, you have a bug on your hand. Even if it does not take a long time to resolve, it is still a good idea to use brackets.
|
It's always possible for a programmer to delete an opening/closing bracket, to make a typing mistake or otherwise do something wrong. Using the suggested style, I can scan the code for conditions where the normal flow of execution is broken (returns, continues, etc) very quickly simply by notice where there aren't curly braces.
Quote:
Originally Posted by Village Idiot
4. Comparison operators
This is PHP, not basic. Use the C++ style operators (&& and ||) in if statements.
|
Cleanliness is next to godliness. Personally I think '&&' and '||' are ugly beasts (and all too easy to typo, right?) compared to 'and' and 'or'. When used in uppercase (as recommended) they provide a clearer separation of the conditions, IMO.
PHP Code:
if ($success || (count($results) > 5)) ...
if ($success AND (count($results) > 5)) ...
Quote:
Originally Posted by Village Idiot
5. Ternaries
Ternary operators are harder to read and edit than normal if statements and should probably be disallowed completely.
|
Why take eight lines of code when one will suffice? The aim of these standards is to make things neat and tidy. If a ternary statement is all messy then by all means separate it out into neater code. I'd also argue the point that ternary operators (unless abused) are easier to read and edit than normal if statements; one line is easier to scan (especially if it's always (SIMPLE_CONDITION) ? IF_TRUE : IF_FALSE).
Quote:
Originally Posted by Village Idiot
Concepts
...
|
From the items discussed, and the community here at TalkPHP, I think the best of the bunch of ideas already suggested would be to go with a photo gallery system. There are lots of component parts for people to work on, it'll cover a plethora of approaches to solving (application) design issues, etc..
A final note, the Kohana coding style is aimed at experienced PHP programmers and meant to keep things consistent throughout that code base. Firstly, we're probably not all at the same level (ie, contibutors might get confused over ternary operators) and secondly, we're not writing code to go into the Kohana project. Put in your own thoughts and ideas.
