Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

perlstyle - Unclear wording

by tinita (Parson)
on Nov 18, 2005 at 13:38 UTC ( [id://509770]=perlquestion: print w/replies, xml ) Need Help??

tinita has asked for the wisdom of the Perl Monks concerning the following question:

hi monks,

there is a sentence in perlstyle.pod which seems unclear to me:
* Space after last parenthesis matching on current line.

any ideas what this could mean? a discussion in the chatterbox didn't get to a solution, the agreement was that it's unclear.
it could mean

# use if (bla) { # instead if (bla){
but this is just my interpretation.

Replies are listed 'Best First'.
Re: perlstyle - Unclear wording
by radiantmatrix (Parson) on Nov 18, 2005 at 14:34 UTC

    Funny, I've always interpreted that particular advice in the context of nested parens. The last paren that has a match on the current line should get a space, but I think it only applies with nested parens. I.e.:

    #do this: if (($a+b) eq ($c-$d) ) { } #instead of: if (($a+b) eq ($c-d)) { } #but I do: if ( ($a+b) eq ($c-$d) ) { }

    It never even occured to me that it could mean something different.

    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: perlstyle - Unclear wording
by jonix (Friar) on Nov 18, 2005 at 15:36 UTC
    While the respective style guide is part of Programming Perl (3rd Edition, july 2000) in a way - some wordings are different, not as brief and more concise - the ambiguous advice in question does not seem to be part of it. The relevant chapter is 24 'Common Practices', 'Programming with Style' IMHO.
    I am wondering whether it was omitted on purpose, or was it added to the pod later on?

    Regards,
    jonix
Re: perlstyle - Unclear wording
by Aristotle (Chancellor) on Nov 18, 2005 at 13:59 UTC

    I wouldn’t say that is unclear, I’d say it makes no sense. “Unclear” would mean there are multiple possible interpretations – in this case, though, I can’t find even one. How does a parenthesis “match on current line”?

    Makeshifts last the longest.

      How does a parenthesis “match on current line”?
      Like-a-so:
      ( ($a eq "foo") && ($b eq "bar") )
      In each case, the close parens "matches" it's open parens (the converse is also true). So, if it "matches on current line", the open and close are on the same line.

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        Doesn’t that make it a strangely particular style rule, though? It doesn’t make sense for someone like me who spaces all parens anyway, as in:

        ( ( $a || $b ) && ( $c || $d ) )

        And it looks weirdly out of place in code of someone who doesn’t, as in:

        (($a || $b) && ($c || $d) )

        Makeshifts last the longest.

Re: perlstyle - Unclear wording
by eric256 (Parson) on Nov 18, 2005 at 13:51 UTC

    What is the other option? I can't think of anything else that matches that statment so it seems clear.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;

      Sumsumming the other ideas that were floated on the CB

      There are many situations that seem to apply but don't make sense:

      if ( ($foo == 1) and ($bar == 1) ){ # ^ space after last matching parens

      Also, in plain statements, it doesn't make much sense:

      (caller) [0] # ^ space after last matching parens?
        Yes, it would be clearer if it said something like "Space between two right parens when the first matches a left paren on the current line and the second matches a left paren on a previous line."

        I agree that those cases don't make much sense. But with long and complex condition statement, I occassionally break it in some way to help myself understand it, for example:

        if (($a1 == $a2) && ($a3 == $a4) && (($a5 == $a6) || ($a7 == $a8)) ) { }

        This way of breaking makes it clear (at least to me) that those lines are at the same level.

        Ahh. For what its worth. When it said matching I though the expresion part of an if block. Although looking at those, the wording isn't very clear.


        ___________
        Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://509770]
Approved by Limbic~Region
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found