Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: Regarding style

by AgentM (Curate)
on Oct 24, 2000 at 23:21 UTC ( [id://38179]=note: print w/replies, xml ) Need Help??


in reply to Regarding style

Actually, the ampersand is less of a shortcut and more "a feature of perl 4". Its requirement in some situations is easily gotten around by predeclaring your subs. I'm not advocating or attacking its use, just commenting on what eventually became of it (according to the perldocs).

I don't think anyone uses m// anymore. i imagine that some people don't even know what it is! Languages evolve and perl is a language. Since m// is arguably the most used regex function, I don't disagree that it's use is optional.

The "diamond operator" is used to save five keystrokes. Whether this is good or evil is irrelevant. use whichever is more obvious in context to you. A well-weathered JAPH will link them in his head instantaneously. No problem.

I think there are many more such "shortcuts", such as cutting down on parentheses in functions. Also, I jokingly consider all of the awk-inherited variables to be very nice shortcuts that I enjoy alot. Thanx awk!

Also, another great shortcut can be found under this link.

AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

Replies are listed 'Best First'.
RE (tilly) 2: Regarding style
by tilly (Archbishop) on Oct 25, 2000 at 03:20 UTC
    I have to disagree on a couple of those.

    First of all the diamond operator does not just save 5 keystrokes. Instead it allows you to build filter programs that have a standard (and well-defined) behaviour without your having to build logic to open, test the open, read, close, test the close, get the next filename, etc. When you need it, it is very nice to have. Of course people who use it to avoid writing STDIN are being silly.

    But I use the diamond, and not for obfuscation.

    As for m operator, I use it as well. Why? Well if I want to match a pattern with forward slashes in it, it is often very nice to use m and a different delimiter. So I don't use it often, but unless I am nobody...

      Continuing on the diamond theme, I usually flag "dangerous" anything during code reviews that look like:
      print "Some prompt? "; $input = <>;
      Why? Because that program works fine when you run it without command-line arguments. But what happens when some other part of the program needs a command arg for a toggle or something? Oops!

      And saying "well, sometimes I want to get stuff from files instead of STDIN" doesn't fly, because then you get the extra prompts!

      For me, the only proper combination is:

      • print "..."; $input = <STDIN>;, or
      • $input = <>;

      In other words, if you're interacting, use the explicit filehandle. Otherwise, suck from diamond.

      -- Randal L. Schwartz, Perl hacker

      Don't consider what i say a personal attack- in the end it is a stylistic matter. If you ant to build a filter system using the diamond operator, go right ahead- but again, it's simply a matter of taste, not code quality or obfuscation. Honestly, the only reason I mentioned m is because I haven't seen it in code for quite a while and you will never encounter a situation where it is required.
      AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
RE: RE: Regarding style
by footpad (Abbot) on Oct 25, 2000 at 00:20 UTC
    AgentM,
    I don't think anyone uses m// anymore. i imagine that some people don't even know what it is! Languages evolve and perl is a language. Since m// is arguably the most used regex function, I don't disagree that it's use is optional.

    Let me ask you this...would you downvote code if it used an m instead of leaving it out?

        Sorry if that sounded like a strange question; I'm still trying to get the PM mindset about things. Certain discussions in other threads made wonder is all.

        Thanks...

Log In?
Username:
Password:

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

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

    No recent polls found