Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: conditional self-execution

by talexb (Canon)
on Jan 28, 2008 at 11:36 UTC ( #664703=note: print w/replies, xml ) Need Help??


in reply to conditional self-execution

    A common Ruby idiom involves creating all the classes and methods necessary for a given program and for other programs that might want to use them as in a library call, then in its own little section write the code that makes use of those classes and methods, creating something that works equally well as either a library or a stand-alone script.

OK -- after reading and re-reading the first sentence of your post, I think I understand the concept.

So what's the point? It just strikes me as a clever piece of code, a solution looking for a problem. It makes more sense to me to just write a module, which is really just a library of related subroutines and variables, and call it from a script, which is just the main-line.

And I'm asking this in the nicest possible way -- I'm not trashing Ruby, just I'm really puzzled as to why one would write something like this.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: conditional self-execution
by apotheon (Deacon) on Jan 30, 2008 at 06:17 UTC

    I get the feeling that, the more you get used to the idea of having that option, the more you'll find things that could be done better if you aren't afraid to use that option when it's available.

    In my personal case, though, the primary use so far has been for unit tests.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin

Re^2: conditional self-execution
by djberg96 (Acolyte) on Jan 30, 2008 at 20:04 UTC
    First, it's not common. I personally only use it for tinkering but I don't publish that code. A few people use it as a place to put their unit tests, though that's still unusual.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2020-11-28 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?