SQL call formatting style

Myk Melez myk at mozilla.org
Wed Apr 2 21:43:39 UTC 2003


Gervase Markham wrote:

> David Miller wrote:
>
>> On 3/29/03 10:39 PM +0000, Gervase Markham wrote:
>> If I had to pick a preference, I'd go for the q{} stuff, personally. 
>
>
> OK :-)
>
> Revised proposal:
>
>   my ($comma, $separated, $list, $of, $vars, $on, $one, $line) =
>     $dbh->some_longwinded_methodname(q{SELECT some SQL variables
>                                        ON multiple lines
>                                        IF necessary
>                                        WITH placeholders ?, ?, ?},
>                                      undef,
>                                      $placeholder, $variables, $here);
>
> How's that look? The SQL block could be outdented if you need the 
> room, and the placeholders could run onto a second line if necessary. 
> I think this combines compactness with readability; it's also pretty 
> like most of the calls currently in the code.

That's ok, except we should allow the following when the name is really 
long:

    $dbh->some_longwinded_methodname(
        q{SELECT some SQL variables ON multiple lines IF necessary
          WITH placeholders ?, ?, ?},
        undef,
        $placeholder, $variables, $here
    );

And placeholders should be able to be aligned vertically (perhaps this 
should be the default in fact):

    $dbh->some_longwinded_methodname(q{SELECT some SQL variables
                                       ON multiple lines
                                       IF necessary
                                       WITH placeholders ?, ?, ?},
                                     undef,
                                     $placeholder,
                                     $variables,
                                     $here);

And indenting the SQL a few extra spaces would help readability:

    $dbh->some_longwinded_methodname(
        q{  SELECT some SQL variables ON multiple lines IF necessary
            WITH placeholders ?, ?, ?},
        undef,
        $placeholder, $variables, $here
    );

    $dbh->some_longwinded_methodname(q{  SELECT some SQL variables
                                         ON multiple lines
                                         IF necessary
                                         WITH placeholders ?, ?, ?},
                                     undef,
                                     $placeholder,
                                     $variables,
                                     $here);

And this should be a recommendation, not a rule.

-myk





More information about the developers mailing list