[sf-perl] perltidy frustration

Michael Friedman frimicc at gmail.com
Mon Feb 11 15:16:55 PST 2013


Kevin,

I'm 100% with you. My last office used PBP style. Alas, I'm not in control of the style at my new office and have to conform to their idiosyncratic existing system. I've tried to convince them to change, but to no avail. Maybe when I've been here a bit longer I'll have more pull, but I just started a couple of months ago.

The main impediment to the PBP kind of stacking you point out is the 120 character line length. Shortening it makes the code wrap much better, to my eyes, but I'm not allowed to change that setting. Maybe I'll bring up that issue again...

Thanks,
-- Mike

On Feb 11, 2013, at 3:11 PM, Kevin Frost <biztos at mac.com> wrote:

> For your second example, are you worried about it merging lines on that $req->div call?
> 
> I find this pretty readable, from the latest perltidy on 5.12.3 with PBP options:
> 
>    return $req->div(
>        {   id    => $id,
>            class => "mod_stack $class size_$size",
>        },
>        $req->div(
>            { class => 'mod_stack_layer' },
>            $req->div(
>                { class => 'mod_stack_layer' },
>                $req->div( { class => 'mod_stack_content' }, $content ),
>            ),
>        ),
>    );
> 
> So that last div() method call is not quite as bunched up.
> 
> As for your .perltidyrc, I have after many years come to the conclusion that, while I am sure I am capable of writing The World's Best Perltidyrc, so are a bunch of other people and we'd never really agree.  Thus best to use the Perl Best Practices defaults, because they are well-known and well-documented and you can spend the energy coding instead of arguing about style.  Yes, this means using some policies you may disagree with, but it's for the greater good!
> 
> You may of course disagree with that statement, but if you have control over the policies or perhaps are just laboring under some legacy prima donna's code style standards I really encourage you to give it some serious thought.
> 
> cheers
> 
> -- frosty
> 
> On Feb 11, 2013, at 7:31 PM, Michael Friedman wrote:
> 
>> I'm trying to get my new office (Polyvore.com -- we're hiring, BTW) to adopt perltidy for their existing, but complicated, code style standards. I've managed to get it relatively close, but I'm running into a wall with two particular cases. Since a number of SFPM members seem to be masters of perltidy, I wondered if anyone might have an idea of what I can try to get these to work. (My .perltidyrc is at the bottom of this email.)
>> 
>> Thanks for any advice!
>> -- Mike Friedman
>> 
>> First case: How do I get perltidy to line up equal signs with other equal-like things, like ||=, //=, and so on? The lining-up-of-equals doesn't seem to be controllable by any of the flags I could find. The BEFORE code is turned into the AFTER code by perltidy with my options.
>> 
>> BEFORE:
>> $params->{_default_sort} = '-count';                                                                                         
>> $params->{_sort_map}     = TAG_SORT;
>> $params->{_limit}      ||= Cons::MAX_CLEAN_TAGS;
>> $sql                     = _limit_order($sql, $params);
>> 
>> AFTER:
>> $params->{_default_sort} = '-count';                                                                                             
>> $params->{_sort_map}     = TAG_SORT;
>> $params->{_limit} ||= Cons::MAX_CLEAN_TAGS;
>> $sql = _limit_order($sql, $params);
>> 
>> 
>> 
>> Second case: The BEFORE code is turned into the AFTER code. The statement about 'mod_stack_layer' is arguably more readable before than after, but I can't get perltidy to not merge the lines as it does. For other reasons I'm not allowed to shorten the line length < 120 characters or to make all lists vertical. I know I could put in a format-skipping marker (#<<<  do not let perltidy touch this), but this construction occurs often enough to make that painful.
>> 
>> Any ideas on how I can get this to stay broken the old way? 
>> 
>> BEFORE:
>> sub render_stack {
>>   my ($resp, $item, $options) = @_;
>>   my $req = $resp->request();
>> 
>>   my $size = $options->{size} || 's';
>>   my $class = $options->{class} || '';
>>   my $renderer = $options->{renderer} || \&render_item;
>> 
>>   my $content = &$renderer($resp, $item, { size => $size });
>> 
>>   my $id = $options->{id} || Request::dom_unique_id();
>> 
>>   return $req->div({
>>           id => $id,
>>           class => "mod_stack $class size_$size",
>>       },
>>       $req->div({ class => 'mod_stack_layer' },
>>           $req->div({ class => 'mod_stack_layer' },
>>               $req->div({ class => 'mod_stack_content' }, $content),
>>           ),
>>       ),
>>   );
>> }
>> 
>> AFTER:
>> sub render_stack {
>>   my ($resp, $item, $options) = @_;
>>   my $req = $resp->request(); 
>> 
>>   my $size     = $options->{size}     || 's';
>>   my $class    = $options->{class}    || '';
>>   my $renderer = $options->{renderer} || \&render_item;
>> 
>>   my $content = &$renderer($resp, $item, { size => $size });
>> 
>>   my $id = $options->{id} || Request::dom_unique_id();                                                                        
>> 
>>   return $req->div({
>>           id    => $id,
>>           class => "mod_stack $class size_$size",
>>       },  
>>       $req->div(
>>           { class => 'mod_stack_layer' },
>>           $req->div({ class => 'mod_stack_layer' }, $req->div({ class => 'mod_stack_content' }, $content),),
>>       ),  
>>   );  
>> }   
>> 
>> 
>> 
>> 
>> 
>> .perltidyrc:
>> -l=120      # Max line width of 120 cols                                                                                        
>> -i=4        # Indent is 4 spaces
>> -ci=2       # Continuation indent is also 4
>> #-st        # Output to STDOUT
>> -se         # Errors to STDERR
>> -vt=2       # Max vertical tightness for opening blocks
>> -cti=0      # No extra indentation for closing brackets
>> -ce         # Use "cuddled" else
>> -bar        # Open brace always on right
>> -pt=2       # Max parens tightness
>> -bt=1       # Medium brace tightness
>> -bvt=0      # Min non-code-block brace tightness
>> -sbt=2      # Max square bracket tightness 
>> -bbt=1      # Medium block brace tightness
>> -sot        # Stack opening tokens
>> -sct        # Stack closing tokens
>> -nsfs       # No space before semicolons
>> -nolq       # Don't outdent long quoted strings
>> -nbbc       # No blank line before comment line
>> -msc=1      # Minimum space to trailing comment
>> -wbb="% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
>>           # Break before all operators, not just the defaults
>> 
>> _______________________________________________
>> SanFrancisco-pm mailing list
>> SanFrancisco-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
> 



More information about the SanFrancisco-pm mailing list