Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Style, *again*

by Abigail-II (Bishop)
on Apr 08, 2003 at 21:25 UTC ( #249082=note: print w/ replies, xml ) Need Help??


in reply to Style, *again*

It would be nice if you also indicated why you use those rules. Some of your rules are fairly obvious, but from others, I'd be interesting to hear why you picked them.

In general, I don't find the list of rules themselves very interesting. What is interesting is knowing why someone picked the rules.

Abigail


Comment on Re: Style, *again*
Re: Re: Style, *again*
by Juerd (Abbot) on Apr 08, 2003 at 22:29 UTC

    In general, I don't find the list of rules themselves very interesting. What is interesting is knowing why someone picked the rules.

    Short answer: because anything else is evil and not the one true style. :)

    But here goes: (I'm lazy, so I'm formatting this as code.)

      * Always check return values where they are important

      To avoid bugs. Die before something worse happens. (that sounds funny :)

      But every experienced programmer knows (usually from personal experience) that there really can be a "Fate Worse Than Death"; I shouldn't be surprised if "FWTD" ends up as one of our common acronyms.

      * No here-documents, but multi-line q/qq. Even repeated prints are better :)
      The here-doc end marker cannot be indented, and I don't want something to be outdented in the middle of something that should be indented. Adding the indent spaces to the end marker means code stops working if it changes, which is VERY bad.

      That's actually not true about the here-doc end marker not being able to be indented. pgs. 23-26 (ch. 1.11) of the Perl Cookbook give a few examples of how to do that. Below is an example with 4 space indents in front of each of the lines.

      (my $text = <<' EOT') =~ s/^\s+//gm; This is a test of the multi-line, indented HERE document. EOT print qq($text);

      This code strips out the leading spaces in the text so that you don't have extra spaces there. It still has the drawback that if you change the spacing it will break unless you adjust the <<'    EOT' declaration as well, but at least it lines up better in the code.

      On another note, great list and thanks for sharing it.


      «Rich36»

        my $text = <<'    EOT'

        Which part of "Adding the indent spaces to the end marker means code stops working if it changes, which is VERY bad." do you not understand? I'm not sure you even misunderstand it, because you repeat it: "It still has the drawback that if ...".

        Suppose you add 8 spaces to the end marker because it is indented by two levels. But you decide to loop over this code. You add a while (EXPR) { and a }, and being the smart programmer that you are, you indent the block immediately using the easy feature your favourite editor has for doing so. Oops, you just broke the code by changing indentation! Unless you add another 4 spaces to the end marker, your code no longer works.

        I prefer series of concatenations or repeated print statements to error prone sugar.

        As for removing whitespace from the beginning: I usually output HTML and do not care.

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

      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

        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).
        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-12-27 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls