HomePage RecentChanges Curly Braces

The issue with braces...

OK I have a simple rule. Can I comment out a block of code?

Rules?

These rules are good:

Ext common style issue

ExtJS recommends this common form:

#!JavaScript
items: [{
    columnWidth: 0.13,
    layout: 'form',
    items: [{
        fieldLabel: 'Date',
        id: 'date'
    }]
},{ 
    columnWidth: 0.52,
    layout: 'form'
}]  

My solution:

#!JavaScript
items: [
    {   
        columnWidth: 0.13,
        layout: 'form',
        items: [
            {
                fieldLabel: 'Date',
                id: 'date'
            }
        ]
    },  
    {
        columnWidth: 0.52,
        layout: 'form'
    }
]

Easier to read.

Perl... or most languages

Bad:

#!Perl
sub xyz
{
 ...
}

if (x < 3)
{
  one;
} else {
  two;
}

Good

Bad:

#!Perl
sub xyz {
 ...
}

if (x < 3) {
  one;
} 
else {
  two;
}

You can now comment out just the "else" block". In the first example you can't.

Parameters

I also do these with parameters to a function. When it comes down to it, what is the difference to that and a block. The common practice is to leave the first parameter inline, then spaces to line up the rest. Using spaces to line up these days is very 1980s... use Tabs.

#!Perl
myFuncCall(
  Param1,
  Param2,
  Param3
);
myComplexCall(
  q{
    SELECT
      *
    FROM
      a_table
    WHERE
      q = ?
  },
  undef,
  $q
);

Some rules

Software error:

Can't locate object method "endform" via package "CGI" at /data/scott.dd.com.au/wiki/modules/search.pl line 15.

For help, please send mail to the webmaster (webmaster@dd.com.au), giving this error message and the time and date of the error.