One of the problems that are immediately faced is that as the tab size changes, the code indenting becomes inconsistent.
for example:
$car = new Vehicle('car');
$boat = new Vehicle('boat');
$motorcycle = new Vehicle('motorcycle');
It looks fine with a tabstop of 4, but with a tabstop of 8, the two tabs in the gap suddenly become:
$car = new Vehicle('car');
$boat = new Vehicle('boat');
$motorcycle = new Vehicle('motorcycle');
So what do you do? Demand that tab stops all be the same size, such as 4 spaces? Where then is the benefit of tabs being able to represent multiple numbers of spaces?
Smarter editors that use spaces when you tab seem to be more common-place these days.
Depends how lazy Im feeling and on how complex the script is ;). But I prefer A to B
Same with commenting the code, if its a basic script then very little comment, if theres a lot going on then Ill comment more than I code, I dont wanna spend a day in 2 years time trying to figure out what the hell I did.
I’ve been using 5.3 before it even was released. It is still PHP there is nothing dramatically different other then a few additions. It is not like upgrading to a new or different Operating System.
Right, but how stable is it? I’m always wary about upgrading server software in a production environment… and 1 year is not “quite a long time” in relative terms… if there’s a security hole, and you’re building PCI compliant apps, you’re screwed.
There’s a reason managed servers all come pre-installed with 5.2 still…
If there is a security hole it is probably (more then likely) in the previous version as well.
You also say that like the previous version has no (or would not have) security holes itself.
And it is as stable as PHP has ever been, take it as you will.
[ot]PHP 5.3 has been out nearly 2 years, not one. Further, PHP 5.2.x has had it’s final release put out and will not receive new updates unless they are critical security flaws.
PHP 5.4 is on the horizon - it MIGHT be out this fall, but predicting PHP releases is almost as bad as picking lottery numbers.[/ot]
Package managers are so slow to get the latest updates for PHP in. Really annoys me. Have to install apache and PHP from source to get it to work with 5.3, but at least it’s done now!
Two years is easily enough time to find out if there are any major show stoppers preventing you from upgrading. I see no reason not to really.[/ot]
class Demo {
function __construct() {
echo 'Opening brace on same line.';
}
}
In PHP I type opening brace on the same line, after a space. That’s what I learned when I read my first C++ book and it has stuck with me since then. Neat indenting makes this very clean and easy to read in my opinion. I’m currently reading the book “Clean Code: A Handbook of Agile Software Craftsmanship” which I really recommend for both intermediate and advanced coders fine-tuning their habit of writing clean code.
Recently I’ve been using Ruby though so I haven’t had to care much about braces at all.
But let’s not forget what’s most important of all for writing clean code; consistency. You, and your team, should settle for a coding style and go with it during the entire project. I’ve seen projects where different programmers use different styles and it isn’t pretty.
I favour style “A”, or rather a variation of 1TBS as mentioned earlier. Like @stormrider, I style classes and functions the same as other control structures.
However, with “A” the 2nd to last closing brace should be indented…
function name() {
function last() {
// Do something
}
}
The closing brace always matches a control statement… function, if, while, etc.
I used to code in Delphi as well, although I have never mimicked the positioning of BEGIN…END with the opening/closing braces {…} as in Allmans style - I think because the opening brace on its own always looked like a waste of space to me and by including the opening brace on the same line you could see more code without having to scroll.
I actually find style “B” where you have indented the braces as well (Whitesmiths style) a bit confusing. If I was to give the opening brace its own line I wouldn’t indent it, keeping it inline with the control structure (which is more like true 1TBS) …
function name()
{
function last()
{
//Do something
}
}