Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Why Use Perl?

by Gremlin (Acolyte)
on Mar 25, 2001 at 09:37 UTC ( [id://66959]=perlquestion: print w/replies, xml ) Need Help??

Gremlin has asked for the wisdom of the Perl Monks concerning the following question:

I need as many opinions as i can get so please offer your suggestions or improvements to mine!

I am a final year student of Electrical and Computer Engineerng at the University of the West Indies in Trinidad. My final year project is a web based one and i coded the CGI scripts in perl.

My presentation is coming up very soon and i am anticipating a major question when that time comes around.

"Why did you program in perl? why not c?"

the webservers are IIS on NT4 but these gave me too much stress so i used a different machine with Apache and Active Perl (problems disappeared woo hooo!)

ok so i know why i used perl:
1. i generally dont like to program in c since perl can so it with much less coding (hell these are simple enough applications why go through the stress).

2. there is always more than one way to do it in perl.
3. There is a huge online community that offers great support and ready advice and assistance (thanks perlmonks!!)
4. hence, it is almost certain that someone else has done it before (or something close to it) so why re-invent the wheel??
5. there is a wealth of resources for perl (i cant say the same for c - but you may know better)

But more importantly
no one in the university has used perl for projects before so it goes well that this is a new area of development.

I need more concrete reasons why i should use perl over c for cgi applications or better wording for my reasons.
I want to hit them on the head (not literally) and let them know that perl is the way to go now... its time to explore it.

I would appreciate your responses / comments / suggestions

Regards
Gremlin

Replies are listed 'Best First'.
Re (tilly) 1: Why Use Perl?
by tilly (Archbishop) on Mar 25, 2001 at 23:04 UTC
    If you are comparing to C in a web environment be absolutely sure to nail some collection of the following points:
    1. CGI is an environment where security matters. In software today the single largest source of security holes is still the lowly buffer overflow. If you use Perl this is completely eliminated. This is before the wins you can get from things like taint checking.
    2. The single most common bug in C is off by one fencepost errors. If you consistently loop over lists in Perl using foreach you virtually eliminate this error. (The number one security hole and the number one bug both gone!) Perl also frees you from the effort and the common mistakes in memory allocation.
    3. CPAN is the single largest repository of freely available code for any language. While quality varies, there is a very long list (CGI, DBI, Template::Toolkit...) of extremely good software to build on.
    4. Perl has an exceptional amount of built-in functionality for direct string manipulation. Considering that web programming is largely concerned with string manipulation, this is a big win.
    5. Perl has a large and friendly community. For instance you can find plenty of good examples, get questions answered online, find discussions of best practices, and many other resources that help programmers improve.
    6. Perl is portable. Sure, C is portable in theory. But in practice sizeable C projects tend to take work to port between platforms. By contrast people in the Perl world frequently just throw their code on a networked file-server and just expect that it will run unchanged on different machines running different operating systems.
    7. Perl is portable, again. The standard libraries on CPAN often make the same internal API available when interfacing with multiple external resources. For instance with DBI it is trivial to write a program which will not only run unchanged against the most popular half-dozen relational databses out there, but it will even allow you to store the information in a collection of CSV files. Which database you connect to and work against can come down to a configuration variable.
    8. Perl can be faster. Straight CGI programs tend to be slow because of the overhead of starting programs, opening database connections, etc. However it is not hard to develop a site in Perl using CGI and then move the execution into the webserver, for instance by using mod_perl on Apache. This eliminates startup times, allows you to cache connections, etc. Doing the same in C would involve writing a custom webserver?
    9. Perl can be faster, again. With native data types like hashes Perl makes it easy to come up with algorithmically efficient answers to problems.
    10. Perl can be faster, again. Perl's RE engine has some breathtaking optimizations. For instance if you wanted to check for whether the string "this is amazing" appeared in another string, in Perl you would write: if ($string =~ /this is amazing/) { # etc You could write that in C, it would be more work, but you can. However the naive C implementation will not succeed in searching the string faster than you can walk the string. Perl's naive implementation both can and does. Matching that in C is possible (if Perl does it it has to be, after all Perl is written in C) but takes a lot of work to do.
    11. Perl is faster, again. As noted by several people, Perl is a master of the school of being maintainable by virtue of being short and sweet both in terms of lines of code and (more importantly) conceptually. Shortness correlates directly to speed and ease of writing, ease of testing, and ease of debugging.
    Now before you stand up and cheer, you will face several complaints that you should be ready for.
    1. Perl is untyped! A type system may be regarded as a test of an official spec for an API. The extent to which things you would want to be tested in the spec cannot be said and checked in the type system is the extent to which the type system failed to do you any good. For instance in C the type system is unable to document important limitations like the maximum length of string that will fit in a buffer. Perl's dynamic data types generally keep these from being errors in the first place. Also you can point out that in practice many typed languages, aren't. For background on this I recommend the following amusing Java example and Dominus has a wonderful article on Typing that is very informative.
    2. Perl is line noise! Perl's syntax is actually fairly easy to get the hang of. While it is possible to write very obtuse Perl code, as perlstyle says, Perl is designed to give you several ways to do anything, so consider choosing the most readable one. With a little attention, Perl is quite good on the readability front without requiring verboseness.
    3. Who uses Perl? Perl tends to be a great stealth tool. While officially virtually nobody uses it, in reality Perl books sell very well, and they sell to working programmers. Perl may not be "respectable", but it is effective. There are some who are willing to admit to their success stories, but there are also a lot of cases like the unnamed but large (very large I assure you) Wall St company that hired Damian Conway in mid-Febuary to teach several internal seminars but who wrote into their contract that he would not say who they were! (I heard the story minus the name from the horse's mouth, and the story with the name from several other people.)
    4. Perl is not scalable! Real life success rates in software don't say good things about the scalability of any software language. Perl scales a lot farther than most people realize. Of course if you write a single straight script, you will fall over. But if you use strict, private namespaces with package, etc people routinely manage to write and maintain systems in the tens of thousands of lines without problems. More importantly given the expressiveness of Perl, many of those would be in the hundreds of thousands of lines in another language. Given the quadratic development inefficiencies as you add bodies, the difference between 30,000 lines and 150,000 for the same task is not insignificant.
    5. Perl programmers are hard to find. With Perl good programmers can be more productive. The history of software engineering does not have encouraging successes for the popular model of throwing many bodies at problems. Perl aims to make existing bodies more effective instead.
    6. Perl uses too many magic variables You don't have to use them. I didn't.
    7. Perl isn't multi-threaded At Threads vs Forking (Java vs Perl) you will find a discussion of my opinions on that. Suffice it to say that IMNSHO anyone who is unable to give an impromptu lecture on problems with threading (for instance a talk about why reversing multi-threading onto code that is not thread-safe is intrinsically hard) has no business trying to deal with it.
    Does that help? :-)
Re: Why Use Perl?
by tinman (Curate) on Mar 25, 2001 at 10:58 UTC

    I used Perl for my final year project too.. One of the reasons that you mentioned, that no one else had done Perl, was part of the reason, but only a very small part

    I'd done work with Java, C, C++ and a few other languages before.. the difference that I discovered is that these languages are a lot more detail oriented than Perl is.. the classic onliner that is possible with Perl underscores this point.. I think I can concentrate on the job at hand, and not worry too much about writing reams of code to get to that point...

    I know its a biased example, but a friend was doing a similar project in Java.. all his code was 42 kb.. mine was just 11 kb ;o)

    Its also worth noting that average time to develop something in Perl is generally shorter than equivalent in C.. I know this is subjective, a good C programmer is going to be pretty quick to do something, but generally, time to develop almost anything is shorter in Perl..

    and when compared to the monstrosity that is Swing, Tk rules in UI speed and memory usage , nuff said :o)

    So, in short, speed of development, lots of reusable code, unlimited flexibility (I love regexps ;o), and the sheer coolness of doing something no one had done before (in my university, at least) were my reasons for using Perl..

    A few more points to add, I was happy to get away from malloc, calloc and the tedium of tracking memory allocations.. I appreciated being able to switch near seamlessly between Linux and Windows, which were my development OS..but these were mentioned before too
    HTH

Re: Why Use Perl?
by Masem (Monsignor) on Mar 25, 2001 at 09:51 UTC
    • Because perl is interpreted, as opposed to compiled, the development time is cut down as the compliation step is non-existent. (Do note, of course, that perl can be compiled to native executables to speed things up once scripts are debugged completely).
    • The perl code will remain portable across platforms if that so happens to the case. You'd have to recompile C scripts and account for any vendor differences with C.
    • Perl's much less prone to 'buffer overflow errors' compared to C, given that you don't have direct access to memory. You still need to run with strict, -w, and -T, but a lot of security headaches can be removed in this aspect.

    Update: as pointed out to me, perlcc'ing a perl script does not gain any benefits during runtime compared to intepreting that script, so the second comment on the first point is null & void. However, the fact that avoiding the compilation step to just test and debug code is a definite benefit.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      As discussed in chatter, the benefits of compilation using perlcc are that you can claim it is compiled and waste disk space. There are no performance benefits (indeed loading time generally increases), it wastes memory, and introduces new bugs...

      So why do it?

      I wouldn't know because I don't. :-)

Re: Why Use Perl?
by merlyn (Sage) on Mar 25, 2001 at 19:43 UTC
    For the most part, you'll code about 3 lines of Perl for every 10 lines of C, C++ or Java. And studies have shown that debugging and maintenance cost is proportional to lines of code.

    The cost of programmers being what it is, Perl is cheaper to use overall. (Plus, it's more fun!)

    -- Randal L. Schwartz, Perl hacker

Re: Why Use Perl?
by batmonk (Scribe) on Mar 25, 2001 at 11:15 UTC

    Because C is not open source, Perl is. (Yes, there are open source C compilers, but which really has the largest sell-thru?) Show me the C equivelant of CPI.pm and DBI and I'll consider the language, provided you can also point me to something that teaches me how to think in pointers.

    Perl is for the average person, for the individual who just wants to get something done without having to relean every fscking wheel that everyone else has had to learn.

    That said, Perl is not the only solution and only a fool would think that it can do everything. Use the best tool for the job.

      Which C compiler has the largest sell-through?

      I really don't know.

      From the official advertising I would guess at Visual C++. But in the circles that I move in, the leader is definitely gcc. In fact even people on Windows that I know tend to install Cygwin and then use gcc.

      OTOH I don't exactly know an unbiased group of people...

        I apologize for not being to provide you with numbers, for I cannot locate the article I had in mind when I originally responded. VC far and above outsells even the closest competitor.

        dws was kind enough to /msg me privately with similar thoughts, however, I ask you the same question I did him: how many Fortune 1000 companies do you know of that've standardized on gcc, as compared to the number that've standardized on VC?

        As stupid as that sounds, (free vs. howevermuch Microsoft wants to charge you today), the point remains that MS is the best selling C++ compiler on the market. I'm not any more fond of that than you are, however, look at the numbers.

        I think the one point you're not taking into account is that the people you hang out with know what they're doing. Many of the rest of us deal with PHB's, Mordac, and the rest of the Dilbertian personalities on a regular basis.

        And, if you'll forgive me, this is something that many of you (collectively, not individually) fail to take into account. Open source may be the best thing since sliced bread, Unix may be a superior OS, and M$ make suck as hard as you wish to say in public. But, until you'll able to accept the fact that Windows is a reality and that openly accepting Windows developers is one of your best opportunities for expanding the useage of Perl, then you'll continue to be marginalized like Ralph Nader, who by refusing to endorse the candidate closest to him ensured the election of the one farthest from his view point.

        If you truly want what is best for Perl, the community, and the people that want to use it, you will accept those with Windows blood in their veins and minimize your harping on their choice of careers or lack of "true faith," for denying them will only drive them to ASP, PHP or other technologies.

        Dont' get me wrong; gcc is great, but...VC has more books on the shelves.

Re: Why Use Perl?
by tune (Curate) on Mar 25, 2001 at 10:41 UTC
    I use perl because i like to live a convenient lifestyle :)))
    Sometimes I try to solve a problem in C, but 5 minutes, and I am completely pissed off! Just crying back myself to perl...
    To be honest C is very fast, and essential for mission critical purposes. But you have to learn how to persuade your boss on using perl :-) Mine used to leave the decision on me! :-)

    -- tune

Re: Why Use Perl?
by damian1301 (Curate) on Mar 25, 2001 at 09:55 UTC
    "Why did you program in perl? why not c?"

    What do you mean "did", I program it everyday!

    Seriously though, before I started programming in Perl, I tried BASIC. It was really difficult for me and I didn't understand what a variable declaration was. Then I came to Perl. It was much easier and better explained. The books and documentation were really helpful for me. Perl is just really well explained and easier than any other language I know of.

    Almost a Perl hacker.
    Dave AKA damian

    I encourage you to email me
Re: Why Use Perl?
by diskcrash (Hermit) on Mar 25, 2001 at 13:04 UTC

    Greetings Great Gremlin-

    I turned to Perl for very pragmatic reasons: NT and Solaris compatibility, rich network tools - FTP and sendmail right out of the box, zero cost - no internal budget problem, a lively support community and good documentation.

    Upon arrival in Perland - there were more treasures; no memory leaks, good performance, faaaast change cycle, clear syntax, and no &%^*&% proprietary tools needed.

    Diskcrash

Re: Why Use Perl?
by dmckee (Scribe) on Mar 25, 2001 at 19:41 UTC
    Of course, when CGI programming is involved - there's CGI.pm, which is useful for quickly creating 'valid' CGI scripts, as well as the problem that many administrators dislike running custom executable code (ie: compiled) as it's impossible to ensure (without recompilation) that the source code is actually the executable code...

    Although admittedly it's very easy to create perl which looks more like line-noise than when it's compiled ;-)

    Dave

    Eight years involved with the nuclear industry have taught me that when nothing can possible go wrong and every avenue has been covered, then is the time to buy a house on the next continent. Terry Pratchett

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found