Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?

by chromatic (Archbishop)
on Dec 13, 2007 at 19:07 UTC ( [id://656884]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?
in thread How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?

Why bother? If the C-style works for you then stick with it.

Fencepost errors, for one (or is that zero?).

  • Comment on Re^2: How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?

Replies are listed 'Best First'.
Re^3: How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?
by KurtSchwind (Chaplain) on Dec 13, 2007 at 19:33 UTC

        Fencepost errors, ...

    By definition, that pretty much violates the "works for you" part of my comment, doesn't it?

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

      That depends on who finds the bug and when. I know I can write a C-style for loop correctly, most of the time, but I don't trust myself to write it reliably all of the time, and so I try to avoid them whenever possible.

      There is really only one interpretation you can place on for my $element (@array) and very few ways it can go wrong whether you know Perl or not. On the other hand for ($i = 0; $I < $numOfElements; ++$i) {...} requires a lot of interpretation even if you know C and there are many places it can go wrong. One of the reasons Perl seems to work as expected first off more often than C (and I know this to be true from personal experience) is that you can avoid exactly this sort of issue the vast majority of the time in Perl.

      Some Perl idiom is just weird and non-obvious to the non-Perl programmer, but much of it is understandable without arcane Perl knowledge (and simply pulsates with succinct power).


      Perl is environmentally friendly - it saves trees

        I don't want to get hung up on loops as that is just one C-style construct under discussion. Also, I don't want to be in the position of having to defend C. Especially on a site called "PerlMonks".

        That said, I agree most of what you said above. Although, I think that people who natively think in C don't have any problems reading

        for ($i = 0; $i < $BLAH; ++$i) { ...}
        . For a native C thinker to make a mistake with that construct is pretty rare.

        But when you have the luxury of perl and you aren't forced to use C constructs, why not use

        for my $foo (@bar) { . . . }
        I agree completely. It's the better solution. But my point is I wouldn't wring my hands over using the C construct if you don't normally make mistakes with it.

        --
        I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found