Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Style, *again*

by Abigail-II (Bishop)
on Apr 10, 2003 at 11:42 UTC ( #249579=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Style, *again*
in thread Style, *again*

Thanks for the annotated list. I don't always make the same decisions, but it's interesting to see where people take an different approach, and why they do that. One question I have, you write:

Logical order in comparisons: $foo == 4, but never 4 == $foo
It's inside a bunch of rules for which you give "Normal linguistics/interpunction." as a reason. I don't think that applies for the quoted rule - I'd like to know why you would never write 4 == $foo.

Abigail


Comment on Re: Style, *again*
Select or Download Code
Re: Re: Style, *again*
by Juerd (Abbot) on Apr 10, 2003 at 16:19 UTC

    It's inside a bunch of rules for which you give "Normal linguistics/interpunction." as a reason. I don't think that applies for the quoted rule - I'd like to know why you would never write 4 == $foo.

    It's kind of normal to put the topic (subject) first. 4 is not the topic, because you already know what 4 is. $foo is what you are unsure about.

    Consider these sentences:
    "If the image on the cover is a camel, the book is probably Programming Perl."
    "If a camel is the image on the cover, the book is probably Programming Perl."
    "If foo is 4, ..."
    "If 4 is foo, ..."

    The camel is constant, the image can be anything.

    Juerd
    - http://juerd.nl/
    - spamcollector_perlmonks@juerd.nl (do not use).
    

      I see.

      I do sometimes write the constant first, because I want to reduce the amount of punctuation. If you write:

      foo $x, $y == 4

      then foo isn't called with arguments $x and $y. You'd need to write that as:

      foo ($x, $y) == 4

      Or

      4 == foo $x, $y

      And since == is a symmetric operation (assuming it's not overloaded), I don't feel strongly for the "topic first" argument. But I can see your point.

      Abigail

        And since == is a symmetric operation

        Which is the reason I often put the constant first. Turning an == into an = accidentally results in a non symmetric operation which is illegal when the left side is a constant. Which helps catch silly mistakes that the compiler doesnt notice (like in the conditional part of a ternary op.)


        ---
        demerphq

        <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
      It does make more sense when you read it out loud, but since there's no semantic difference, it sometimes helps to place immutables as the first operand since then you'll get a compiler error out of the simple typo:
      unless ($foo = 4) { ... argle blougat blopf ... }
      when it looks like this:
      unless (4 = $foo) { ... womble ... }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-07-13 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (247 votes), past polls