Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^6: Pattern Matching Query

by Aristotle (Chancellor)
on Sep 18, 2002 at 23:22 UTC ( #199035=note: print w/replies, xml ) Need Help??


in reply to Re: Re^4: Pattern Matching Query
in thread Pattern Matching Query

You comparison was unfair. Note my initial example used formatting for neither. The second case really should have been
return the combined success
of assertion one
and assertion two
and assertion three
and assertion four
and assertion five
and assertion six

If you're using formatting to line one up, you have to use formatting to line the other up as well. I think I can stop here, as far as this particular example is concerned..

I have nothing against the concept of a guard clause per se, though your example would be much more readable if you emphasize what it is by putting the return in the spotlight and avoiding the ! linenoise:

return unless $fruit;

As far as bad memory is concerned, I don't see how my style requires a good one. To the contrary, actually, I tend to be very visually oriented. My code formatting follows that rule - I want to be able to glean the structure of a function's body without having to actually read and grok it all, and indentation carefully follows that motto. Functions should usually not be longer than about 25 lines. Some have to be of course, but those are few and far between. Most of mine tend to be around 15. That's so little you need no memory - you can take the entire function in in a single look. It's beneficial to have as little line noise as possible. Each statement should do as much as possible while being readable at a glance. Repetition is to be avoided. Contrary to intuition, spotting subtle differences in a repeated pattern is difficult - it's easy to detect their presence, but hard to actually make them out. (Have you ever seen much repetition in literature outside of poems?)

Basically I try to write Perl close to how I'd write the same thing in English.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^6: Pattern Matching Query
by PhiRatE (Monk) on Sep 19, 2002 at 03:33 UTC
    Hrm. I agree, I had not intentionally mis-formatted yours, I had simply cut&paste what I had several times :) ah cut&paste, I love thee and yet thy use doth cause me pain.

    I dislike the return - unless structure, as I said, I have a bad memory, I prefer my condition first, so that I can compare my mental state against that and continue or discard the block depending on the result. If I have to read the operation first, I then have to remember what that was when I reach the condition :)

    if (you're using formatting to line one up) { you have to use formatti +ng to line the other up as well }; {I think I can stop here} unless (another example is used).

    You're not kidding me :) you really do write your code like you write your english :) :)

    For reference, this is how I write the same thing in english:

    Regarding this particular example, if you're using formatting to line +one up you have to use formatting to line the other up as well.

    Thats highly amusing. Notice that the way I do it, I've put a guard clause in at the start of the sentence, effectively:

    if (!this particular example) { return } if (you're using formatting to line one up) { you have to use formatti +ng to line the other up as well }

    Thats kinda cool :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-09-25 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?