Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: "Indirect" object syntax?

by Apero (Scribe)
on Nov 24, 2015 at 01:35 UTC ( #1148464=note: print w/replies, xml ) Need Help??


in reply to Re^2: "Indirect" object syntax?
in thread "Indirect" object syntax?

My question was more about whether —from a linguistical point of view— the name "indirect object" was the most accurate.

I figured, although backing up my alternative naming convention (which I'll hardly claim as the "best", or even better than indirect) with reasoning might help another reader realize what's going on behind the scenes when making Perl English readable; that's not always a useful metric as you noted.

The discussion is interesting since many of Perl's constructs can be read in an English-like way (even promoted as options at times, as in use English. On the other hand, I frequently find lines, especially long unbroken ones, hard to read.

Some more musing (or rambling, depending on your opinion) on subject/verb ordering in Perl follows..

I could say do many things now if you are ready and set and prepared ...

do('many', 'things', 'now') if ( $ready and $set and $prepared );

... but I often prefer how the code syntax looks if I reverse the English above and instead state, "if you are ready and set and prepared, do many things now."

if ( $ready and $set and $prepared ) { do('many', 'things', 'now'); }

Indirect object method invocation is almost Yoda-like, in the way the green Jedi might say "go_to_the_lake, Sally does"

go_to_the_lake $Sally;
.. but as above, I think I prefer "Sally, go to the lake", this time both in terms of English appeal and the code implications:

$Sally->go_to_the_lake();

I didn't mean to take away from your linguistic pondering too much (although hopefully another reader can benefit from that.) In any event, thanks for the discussion!

Replies are listed 'Best First'.
Re^4: "Indirect" object syntax?
by muba (Priest) on Nov 24, 2015 at 02:20 UTC

    Ah, well then. I must've misunderstood the intention behind your post. My bad.

    do('many', 'things', 'now') if ( $ready and $set and $prepared );

    could be made even more English-like (Englishy? Englishesque?) if we ignore for a moment that do is a built-in function ;)

    do 'many', 'things', 'now' if $ready and $set and $prepared;

    And even you prefer the if-this-then-than notation over the that-if-this syntax, there are neat ways:

    $ready and $set and $prepared and do 'many', 'things', 'now'; $ready and $set and $prepared? do 'many', 'things', 'now' :() ;

    What's funny about that last one is that it's... well... rather Englishy indeed:

    (Are you) ready and set and prepared? Do many things now <shocked emoticon>;

    Coincidentally (or maybe not, as it's neatly linked to on my homenode), I've asked about the various ways to write conditionals before.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2019-11-12 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (64 votes). Check out past polls.

    Notices?