Welcome Guest, Not a member yet? Register   Sign In
Messy Statements?
#1

[eluser]ChazUK[/eluser]
Hi, I was just wondering if anyone else thought the style guide outlines messy statements.

Code:
if($i === 1)
{
    echo '$i is 1';
}
else
{
    echo '$i isn\'t 1';
}

compared to

Code:
if($i === 1) {
    echo '$i is 1';
} else {
    echo '$i isn\'t 1';
}

I just think it makes the code a bit neater, but I'm sticking to the style guide so that others can read my code in classic CI style.
#2

[eluser]Ben Edmunds[/eluser]
Hey, that style is hard for me to get used to as well since it reminds me of how my code looked two years ago.

I usually just use that style when making libraries...
#3

[eluser]ChazUK[/eluser]
Also, I find it a lot easier to do this if you're only doing one operation (?) after a statement.

Code:
if(count($array) > 0)
    foreach($array as $value)
        echo $value . '<br />';
#4

[eluser]theprodigy[/eluser]
Personally, I prefer the "expanded" syntax:

Code:
if($that=='whatever')
{
//do something
}
else
{
//don't do something
}

over

Code:
if($that=='whatever'){
//do something
}else{
//don't do something
}

I find the expanded syntax easier to read. I know right off the bat when and where things begin an end. It's the same for the single operation syntax. I prefer always putting curly braces around that chunk of code for several reasons. 1. Easy to see where it begins and ends right off the bat. 2. Easier to added another operation later, should you need to.
#5

[eluser]Colin Williams[/eluser]
I prefer the EllisLab style.

Quote:Also, I find it a lot easier to do this if you’re only doing one operation (?) after a statement.

Programmers can't hate to type. Having a standard that says, "here's another way to do it," is hardly a standard at all.




Theme © iAndrew 2016 - Forum software by © MyBB