This page is no longer updated - please visit http://ghostwire.com Thank you!
 

« PHPObject »
An Opensource Alternative to Flash Remoting
Current Release
Readme
Notes
Journal
Archives

Journal
Monday April 28, 2003

Embracing curly braces

I read somewhere that curly braces are a good thing, even in cases where they are unnecessary. For example,

if (myVar == "hello world")
    return true;
has the same effect as
if (myVar == "hello world") {
    return true;
}
If you ask me, I would say the first way is neater (of course if you start inserting more than one line of code under that condition, you need to insert the braces) and is my preferred way. But which is better? Too many curly braces sometimes confuses me. For now, nevertheless, I have decided to follow "good practice" and change my code to embrace the curly braces...

Posted by sunny at April 28, 2003 11:12 AM

 

Comments

I have always used curly braces as in the second example. When I come across code written like the first example, I find it near-impossible to understand. imo having the scope clearly defined is neater as well as more robust.

Posted by: plusplus at May 1, 2003 10:59 PM

Good on ya! Clean and proper code always reads nicer for those who have to work with it, even the computer. Okay... so the computer doesn't care... but one day they might! Watch out!

Posted by: sugarjunky at May 9, 2003 04:18 AM

Curly braces are good, though I'm not a fan of the opening one being at the end of the code line, personally I prefer:

function foo()
{
...
if(1==2)
{
...
}
}

I find it easier to glance at the code to see the 'level' of the contained code. Indenting is also a good thing, though best with Tabs, not spaces :)

Posted by: Zingo at May 12, 2003 04:51 AM

 

Post a comment









Remember personal info?







Zones



Forums