in reply to RFC: App::SFDC

This comment is related to the WWW::SFDC package.

I don't like stuff like

my ($result, $headers) = $self->_call( 'executeAnonymous', SOAP::Data->name(string => $code), $options{debug} ? SOAP::Header->name('DebuggingHeader' => \SOAP::Dat +a->name( debugLevel => 'DEBUGONLY' ))->uri($self->uri) : (), );

because it makes it hard to see what's going on. I would prefer it to build the function arguments separately, like:

my @args = ( 'executeAnonymous' SOAP::Data->name(string => $code), ); if ($options{debug}) { # this line should also be cleaned up somehow push @args, SOAP::Header->name('DebuggingHeader' => \SOAP::Data->nam +e(debugLevel => 'DEBUGONLY'))->uri($self->uri); } my ($result, $headers) = $self->_call(@args);

Replies are listed 'Best First'.
Re^2: RFC: App::SFDC
by ali0sha (Sexton) on Jul 15, 2015 at 08:25 UTC
    Do you think it's more that just a stylistic/opinion choice? My feeling is that creating intermediate variables and modifying them is less clear because it requires keeping track of more variables over more statements and lines.

      It is basically a stylistic choice, but I think it improves the readability of the code a lot. At least to me. I picked this code example because at first glance I simply saw 'stuff', then while looking at it there were 'revelation'-like experiences. Oh! It's a function call! Oh! It's using a ternary operator to build a conditional argument set. Oh! The conditional is just there to help debugging.

      I rewrote the code to make these 3 different aspects more visible and make it easier to mentally skip parts that are probably not relevant to spotting bugs, e.g. the debug conditional.

      Generally I try to format the code in a way that minimizes the mental effort and the time required to recognize the building blocks. Hopefully this helps to reduce the 'TL;DR'-effect when reading / scanning over it and helps to spot possible bugs more easily. That's also the reason why I try to avoid the ternary operator in complicated statements. Sure it's convenient, but '?' is a lot less visibly distinct then 'if ('. In your case I was even able to drop the 'else' branch, because it didn't have any purpose besides satisfying the syntax.

        I have to agree that Monk::Thomas' rewrite is quite a bit easier to understand.