Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Code style question -- code review

by GrandFather (Saint)
on May 21, 2021 at 03:18 UTC ( #11132825=note: print w/replies, xml ) Need Help??


in reply to Re: Code style question -- code review
in thread Code style question

"I prefere the and put at the end of the line and all and aligned: the same for or and for thernary like ? and : because somenting at the end of line is easier to spot."

I emphatically disagree! The easiest stuff to see is at the start of the line. I frequently break complicated expressions over lines so that it is easier to understand them. For example, the following test from a C++ project I'm working on right now could be laid out several ways:

if (currMaj < bestMajVer || (currMaj == bestMajVer && currMin <= bestM +inVer)) // Current image is no better than the best so far if (currMaj < bestMajVer || (currMaj == bestMajVer && currMin <= bestMinVer) ) // Current image is no better than the best so far if ( currMaj < bestMajVer || (currMaj == bestMajVer && currMin <= bestMinVer) ) // Current image is no better than the best so far

To my eye the last version is much easier to understand than the previous two.

One of Perl's features that I really like is the provision of statement modifiers because, for short statements at least, I can get compact expressive code with the important bits in the right order:
<do this interesting thing> <while/for/if> <something vaguely interesting>.

For the same reason the default increment operator should be pre-increment (++$thing) instead of the cargo culted post-increment operator ($thing--). There are places where post-increment must be used, but they are rare and the default should always be pre-increment just because the operator is easier to see and the operation is less surprising.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^3: Code style question -- code review
by Discipulus (Abbot) on May 21, 2021 at 06:55 UTC
    Hello GrandFather

    > I emphatically disagree!

    :) as I told, I suppose is a matter of taste. I tend to use something like:

    # complex clause if ( defined $thing and $thing > 3 and $thing <= 42 and 0 == $thing % 2 ) # ternary print (defined $thing and $thing > 0) ? $thing : 'not';

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-10-21 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?