Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Code Formatting - generous spaces in expressions

by metaperl (Curate)
on Jun 16, 2011 at 14:25 UTC ( #909965=perlmeditation: print w/replies, xml ) Need Help??

I was looking through the source code for Data::Maker and noticed the author put a lot of spaces around his expressions.
sub rand_date { # Get the options hash my %options = @_; # use the Date::Calc module eval q{ use Date::Calc }; cluck($@) && return if $@; my ( $min_year, $min_month, $min_day, $max_year, $max_month, $max_ +day ); # Get today's date my ( $year, $month, $day ) = Date::Calc::Today(); if ( $options{'min'} ) { if ( $options{'min'} eq 'now' ) { ( $min_year, $min_month, $min_day ) = ( $year, $month, $da +y ); } else { ( $min_year, $min_month, $min_day ) = split ( /\-/, $options{'min'} ); } } else { ( $min_year, $min_month, $min_day ) = ( $year, $month, $day ); } if ( $options{'max'} ) { if ( $options{'max'} eq 'now' ) { ( $max_year, $max_month, $max_day ) = ( $year, $month, $da +y ); } else { ( $max_year, $max_month, $max_day ) = split ( /\-/, $options{'max'} ); } } else { ( $max_year, $max_month, $max_day ) = Date::Calc::Add_Delta_YMD( $min_year, $min_month, $min_day, +1, 0, 0 ); } my $delta_days = Date::Calc::Delta_Days( $min_year, $min_month, $min_day, $max_ye +ar, $max_month, $max_day, ); cluck('max date is later than min date') && return if $delta_days +< 0; $delta_days = int( rand( $delta_days + 1 ) ); ( $year, $month, $day ) = Date::Calc::Add_Delta_Days( $min_year, $min_month, $min_day, $delta_days ); return sprintf( "%04u-%02u-%02u", $year, $month, $day ); }
I found it very clean and easy to read. I'm an Emacs user and would like to switch to that mode of formatting my text. But I'm not sure if that's possible.

The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"

Replies are listed 'Best First'.
Re: Code Formatting - generous spaces in expressions
by toolic (Bishop) on Jun 16, 2011 at 14:41 UTC
    perltidy might have an option for that.
Re: Code Formatting - generous spaces in expressions
by biohisham (Priest) on Jun 18, 2011 at 15:54 UTC
    perltidy is great indeed esp when fixing code that was kind of written on the run, consider Perl Best Practices as a style makeover tool

    David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...
Re: Code Formatting - generous spaces in expressions
by pvaldes (Chaplain) on Aug 13, 2011 at 10:55 UTC
    You can choose between several indent styles for Perl in emacs:

    M+x perl-mode

    menu perl -> indent styles...

    Read also: and

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://909965]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-07-16 12:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found