mdomba, on 03 October 2011 - 06:46 AM, said:
Please refrain yourself from comments like this...
The example you gave is not the same as if to use one space after if or not...
But that's exactly how code looks when a it's done. Yes, maybe simple code like get data from db and pass it to the views will look fine without spaces, but framework code isn't so simple. And I tend to do projects where simple code is not in abundance and most business logic is not trivial leading to tons of if's, foreach'es, function/method call and so on. And believe me, when you open that code even after a few weeks - you want it be perfectly easy readable.
Reading something like
if($some_var>10||$something=='somethingelse'){
is a major headache even reading your own code after a while. Reading someone's code in that style is just ridiculous - I have to reformat it all over to make sense of it.
Code readability is built on a ton of tiny things that become what we call readability. And we, humans, are all built the same way and we read the same way. You can train and make yourself to read anything - some can read hexadecimal dumps as it was plain text, but that doesn't mean that it's a readable form, don't you agree?
Separating items in code is one of those things that make reading code easier. You don't have books witch do not have spaces between some words of phrases. Here is the same thing - it is easier to process separated by space elements that a string with no spaces and trying to identify where there is what.
And for example about the braces.
I use them like this:
class MyClass
{
public function test()
{
if ($expression) {
// code
}
foreach ($item as $key => $value) {
// code
}
}
}
function ()
{
// code
}
Why? Because when I skim the code, I can identify what the block of code is by the the layout of the braces. If braces are on their own lines - that's method/function/class, in other case is a conditional block or a loop. That really helps a lot.