Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Perl advocacy

by tinman (Curate)
on Jun 16, 2001 at 00:42 UTC ( #88932=perlmeditation: print w/ replies, xml ) Need Help??

Recently, I was asked to write a position paper of sorts for a company that was interested in using Perl as a development language. The local universities have nothing to do with Perl, and its generally only known by a few Unix admins and webmasters...so, finding and training people would also be a factor in adopting Perl (all the universities teach Java and bits of C as standard)...

Of course, Perlmonks was a good place to start looking, and I wrote the following document...

<document>
Why Perl over Java
What is Perl

Perl is an open source cross platform scripting language.(http://www.perl.com). Originally designed and written in 1987 (http://www.perl.org/press/history.html) as a powerful replacement for Unix shell scripting languages such as sed and awk, Perl is now widely used (http://perl.oreilly.com/news/success_stories.html) in many different organizations and many different spheres of computing activity. Text processing and data analysis, as well as CGI scripting are domains which have been dominated by Perl in recent years.

Now in release 5.6.1, Perl is developed by a group of volunteers, with several commercial organizations (www.activestate.com being the main player) actively aiding and abetting. Documentation and literature for Perl is widely available on the Internet and in downloadable form. Perl itself is freely distributed in both source form and as binaries for many different operating systems (http://www.perl.com/reference/query.cgi?binaries), including Unix (Solaris, AIX, BSD variants, HP-UX), MacOS, Win32, Irix, VMS, BeOS, OS/2 etc.

What Perl and Java have in common

They're both freely available for download and use. (However, Perl is open source, Java is not.) They are both cross platform, however Perl itself is more stable on a larger number of platforms (personal experience: Java on Linux isn't very stable, although there is improvement esp. with 1.3SE. Perl on Linux is a commonly used webserver platform). Perl and Java both have garbage collection and dynamic memory allocation. Java and Perl both allow object oriented programming, although Perl can also be programmed in functional or procedural styles.

Perl and Java both have similar toolkits for most common tasks, such as database access (JDBC for Java, DBI for Perl).

Perl - Key differentiators

Regular expressions: Perl pioneered incorporating regular expressions into a language. Since Perl, other languages such as Python, PHP and even Java (from 1.4 onwards) use regexps for text matching. However, the re engine in Perl is far more sophisticated. for example: the Rx cookbook (http://aspn.activestate.com/ASPN/Cookbook/Rx)

Update 2: Blew away the regexp per Ovid's comment.. Yes, absolutely right.. It took lots of dissecting before I got it..

Speed of development Generally fewer lines of code per task than C, C++ or Java.. an often quoted metric is 3 lines of Java code per line of Perl code.

@elements = ('A'..'Z', 0..9);
builds a list which contains all characters from A to Z and all digits from 0 to 9 A complete perl script which builds the list and prints a random 15 character registration key. Comments denoted with a #
#!/usr/bin/perl -w use strict; my @elements = ('A'..'Z', 0..9); my $regkey = join '', map { $elements[ rand @elements ] } 1..15;

Update 1: Fixed the example. If you want to see the wrong way, read btrott's node :o)
Public module repositories (CPAN): Modules for almost anything that can be done with Perl database drivers, XML parsing modules (DOM, SAX), SOAP related modules, credit card authorization modules, weather modules, user interfaces (Tk) etc http://search.cpan.org/ for a list of categories

Some Perl vs Java related resources
http://perlmonks.org/index.pl?node_id=33185
http://www-106.ibm.com/developerworks/library/l-p560.html?l=16jn3
http://perlmonks.org/index.pl?node_id=68860
http://perlmonks.org/index.pl?node_id=44324
http://perlmonks.org/index.pl?node_id=72994
http://www.perl.org/phbs/
http://www.perl.org/phbs/reduce-risks.html
http://perlmonks.org/index.pl?node_id=66959
http://www.nectec.or.th/net-guide/Perl/faq/1.29.html

High traffic sites that use Perl (see http://perl.oreilly.com/news/success_stories.html)
http://www.slashdot.org
http://www.perlmonks.org
Quoting directly from this node,
"www.Etoys.com is all Perl. Deja is all Perl. http://www.Amazon.com uses Perl for nearly all their backend operations. Yahoo is mostly Perl behind the scenes. Altavista is all Perl, except for the purchased software. Sportsline.CBS.com is "80% Perl". "
</document>

I somehow am not very satisfied with the way it turned out (although I've already submitted a first draft).. Particularly, any other high traffic sites that use Perl (a perlmonks link mentioned Amazon, eToys etc, so I didn't repeat those).. any other key differentiators between Perl and Java ? (apologies, but Java is the language that they know, and they wanted a comparison)

Please note that I am not looking to start a flamewar here. I feel there aren't enough software companies that really take Perl seriously (where I come from, anyway), and I want to increase awareness, in a small way... any critiques or additions to the stuff above appreciated, and gratefully accepted...

Besides, this gathers all the Perl advocacy that I could find in one place... It'll be a useful point of reference, at the very least :o)

Comment on Perl advocacy
Select or Download Code
Re: Perl advocacy
by btrott (Parson) on Jun 16, 2001 at 00:58 UTC
    Several comments.
    • You have some examples of Perl code and you say, "it takes less lines to do this in Perl than to do this in Java". But you only give an example of the Perl code! So how am I supposed to believe you that it really takes less lines? (For the record, I *do* happen to believe you, but that's neither here nor there; you're preaching to the converted, here. :)

      And besides, saying that the program takes less lines of code isn't necessarily a reason for choosing Perl over Java. *Why* is it good that a Perl program takes less lines of code? (Maintenance, maybe?) Give them reasons, not just assertions.

    • Make sure that your programs work.

      This program doesn't do what you think it does:

      my @elements = {'A'..'Z', 0 .. 9 }; my $i = 0; my @regkey; while($i++ < 15) { push(@regkey,$elements[rand($#elements + 1)]); +} print @regkey, "\n";
      The biggest mistake is the initialization of @elements. Those should be parens, not curly braces. You have created a list of hash references. Your program prints out:
      HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80 +e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HAS +H(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a90)HASH(0x80e4a +90)HASH(0x80e4a90)
      And you really don't need that many lines to write that code (since that's one of your major points :)--
      my @elements = ('A'..'Z', 0..9); my $regkey = join '', map { $elements[ rand @elements ] } 1..15;
      And I'm *sure* that people can golf that down, but that's not really the point. The point is that my code shows some strengths of Perl, rather than looking like ported Java code (synthetic variables, for one thing).

    • Make it clearer *why* they should choose Perl. "Less lines of code" isn't necessarily a reason in itself, and if all of the local universities teach Java instead of Perl, they have a *very*, *very* good reason for choosing Java. You need to give them a counter-argument.

      Anticipate the arguments they're going to give for languages other than Perl. "Java is an industry standard"; "Java is faster"; "Students are learning Java"; etc. Give counter-arguments for these.

    • You say:
      > However, the re engine in Perl is far more sophisticated and > capable of better matches
      "Better matches"? What does that mean? Does that mean, using the same regular expression (eg. "\w+"), I can match "better" strings in Perl than in Java? :)

      I think what you mean to say is: Perl has a more powerful regular expression engine. And then you need to find examples of *how* it is more powerful.

    • One thing about Perl that is very, very good--that Java does not have--is CPAN. I really think you should mention CPAN. :)

      UPDATE: Oops, so you did mention CPAN. However, I think you should make it a stronger point. :)

(Ovid) Re: Perl advocacy
by Ovid (Cardinal) on Jun 16, 2001 at 01:14 UTC

    A couple of thoughts:

    • Drop the regex. It's practically unreadable and if any has heard of the FUD regarding Perl and linenoise, that will only encourage it.
    • Go ahead and include the Amazon and eToys links. The odds are, many people who read your document will not follow your links.
    • You mention that a company is thinking about adopting Perl as a development language. What sort of development? What are they trying to accomplish and how does Perl help them accomplish this? If they want device drivers or high-speed number crunching, Perl is not the best solution.

    Incidentally, if you must include the regex, at least have pretty formatting so it looks nice:

    $/ = ''; # paragrep mode while (<>) { while ( m{ \b # start at a word boundary (begin letters) ( # capture to $1 \S+ # one or more non-spaces ) # find chunk of non-whitespace \b # until another word boundary (end letters) ( # capture to $2 \s+ # separated by some whitespace \1 # whatever was in $1 \b # until another word boundary )+ # one or more sets of those }xig ) { print "dup word '$1' at paragraph $.\n"; } }

    Just looking at that code, even when nicely formatted, makes me wince when I think about trying to convert anyone with it. Sure, we know what <>, $/, $., $1, and \1 mean, not to mention the /x, /i and /g modifiers on the regex, but those are going to scare the heck out of someone and make 'em long for Python or something.

    If you show them some code, I think some 'baby Perl' would be a nice way to start.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Perl advocacy
by frag (Hermit) on Jun 16, 2001 at 01:31 UTC
    1. First, even if one of the perlmonks links mentioned Amazon, there are so many links here that you can't be sure that'll be noticed, so you should make that explicit. It'll probably be taken more seriously than /. or pm, which raises a question...
    2. ...is your audience going to be suits or coders? If the former, turns of phrase like "aiding and abetting" might not be a good idea if you trying to convince them of Perl's legitimacy.
    3. I know you've got links to spare, but here's an excellent link I found today, surfing the Big Kahuna's home page. It's the only link on his page under "Advocacy": It's got a lot about Perl vs. C/C++/Java, including for application development, and includes short versions of the success stories, including Amazon. It might make a good additional link; in any case, it should be worth reading for ideas.

    -- Frag.

Re: Perl advocacy
by eejack (Hermit) on Jun 16, 2001 at 01:33 UTC
    One of the points I never see mentioned is being able to segment test and develop code.

    For example you are building a simple system that takes user input from a form and puts it into a database.

    With java - you need to build it, compile it, run it, and check the database.

    With perl, you can code and test the routine that grabs the input. You can code and test the routine that builds the sql queries to put the data into the database. You can effectively code an entire system in parts, assemble and run.

    I very often will work on one piece of a script at a time, and bash all the bits together when they all work. Can't do that with Java.

    You certainly cannot build a one or two line piece of code to test regex's in Java.

    Now in your situation, short - documented and runnable bits of code make training easier, and makes converting those *on the edge* easier.

    Another neat touch would be make a java and perl version of the document, something that could put the document in a nice html format in their browser. Then show them the source code for each and (if possible) go through the steps to make a change or two. Edit-run vs edit-compile-run.

    EEjack

Re: Perl advocacy
by tachyon (Chancellor) on Jun 16, 2001 at 14:52 UTC

    I agree with almost all the comments made to date. If I was writing this doc I would emphasise:

    Perl has been around for many years (more than Java) and as a direct result all the major bugs have been ironed out.

    Perl is very cross platform, and reliably so. Java still has some *issues* to use the term coined by the company of he who may not be named.

    Open source and CPAN mean that library routines to perform most tasks are available that are not only widely used, but tested, updated, etc, etc

    Perl can do OO just like Java. It can also do procedural. More importantly it can readily be developed in sections that can be easily and independently tested and debugged. Add the CPAN libray bit again where you note that there is a lot of *free* high quality, well tested code available - if you don't have to write and debug it you save time, money and hassles.

    Give a really simple example of how Perl is shorter, this is C as I don't do Java although I am told it is similar.

    In Perl:
    
    print "Hello world\n";
    
    In C:
    
    #include <stdio.h>
       
    int main()  
     {    
          printf("Hello World!\n");  
          return 0;
     }
    

    So what if Perl code is shorter. I would emphasise easier to write, easier to test, easier to debug and easier to maintain - as a result *less cost* to implement any given solution. Bottom line $ terms is what really counts. This is why I would choose Perl over other languages for most (but not all) tasks.

    Perl is interpreted Java half compiled into bytecode. Both are fast enough to do most jobs. Who cares which is faster if both are fast enough? Having to compile Java (or anything) for testing is a pain compared to Perl's ease of running and testing.

    Target your audience. If it is suits emphasise development time, reliability, and dollars. If it is programmers emphasise laziness by utilising CPAN, ease of coding, plus whatever else you think might help.

    With the links take one link from each domain. It kinda looks as though perlmonks.com is the only perl site in existence. Not that this is not a great site but you want to emphasise the wide use of perl, so give a wide variety of links to the same info.

    Well that's my 10c worth

    cheers

    tachyon

Re: Perl advocacy
by Mission (Hermit) on Jun 17, 2001 at 00:07 UTC
    tinman, there is another item that I think is worth mentioning. I've coded in a wide variety of languages, and I can tell you that Perl was the easiest to learn. Not because of syntax, but because of the documentation, the ability to find online help, and most importantly the functionality of online communities... especially Perl Monks! I have not found another resource that has been as beneficial to my learning of the Perl language. I've never found one for C++, or Java, or JavaScript, or COBOL, etc. They just don't have the kinds of documentation, and assistance that the Perl community has going for it. That in itself is a HUGE advantage.

    Say for example this company goes with Java and has a problem with a part of a program. The only help they will find is their development team, and their paper resources that they have on hand. They surely don't have a resource online, that they would be able to post snippets of code and within minutes, be able to have different resolutions. Or be able to go to a bank of modules like CPAN to see if it has already been done.

    Again, your target audience is going to drive the way you cater your report. Heck, you could use this node itself to show the benefits of Perl. "Sure Mr. Suit. I wrote this report and posted it on Perl Monks, a Perl online community, and my fellow Perl coders from around the world helped me edit the report so I wasn't missing points!" That in itself speaks volumes.

    Please keep us informed, and make sure that you reply with a final draft of your report... I know it will be of major benefit to other people as well.

    - Mission
    "Heck I don't know how to do it either, but do you think that's going to stop me?!!"
Re: Perl advocacy
by Mr. Lee (Scribe) on Jan 12, 2005 at 19:07 UTC
    I never use Java, I never use C. On the search for another language I come to Perl, because I knew only basic. My employer is about Perl also. It is more easy to learn Perl if you know C from the start then?
    Mr. Lee

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-19 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls