Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Is Perl worth it? How does perl deal with programmer folly?

by jotti (Scribe)
on Apr 23, 2002 at 12:19 UTC ( #161266=perlquestion: print w/replies, xml ) Need Help??
jotti has asked for the wisdom of the Perl Monks concerning the following question:

Ok, that was only a provocative question, I know it's worth it.

Anyhow, I'm a newbie. I've done some bigger CGI projects using C++ (Borland) on an IIS. I decided to go Perl, because the exes that I made used to choke the server. Infinite loops in my code, 16 bit vs. 32 bit problems etc. I want to know if using Perl minimises the risks. How does a www server handle with Perl scripts that might run into infinite loops or other unpredictable situations. What are typical pitfalls?.

Johan Halmén

Edit kudra, 2002-04-24 Added to title

  • Comment on Is Perl worth it? How does perl deal with programmer folly?

Replies are listed 'Best First'.
Re: Is Perl worth it?
by Biker (Priest) on Apr 23, 2002 at 13:27 UTC

    I'd like to comment on Perl as a programmming language.

    Perl is a programming language with many built in commands, many different ways of doing things and aiming at many different problem areas. This is mostly considered a Good Thing in the Perl community.

    As such, Perl provides you a lot. OTOH, and IMHO, Perl also require quite a lot from the programmer. Agreed, it is very easy to write a small script to solve a small and well defined problem. But when you start to write something big and/or complex, there are numerous ways of getting confused.

    Perl gives freedom to the developer. Freedom has a price and the cost is responsibility. Perl puts you in the front seat. You drive. So chose your road visely. Perl will not stop you from going off the cliff. Or into the rock wall.
    Good Perl is better or as good as good code in most (any?) other language. Bad Perl code is a disaster.

    If you're experiencing problems with infinite loops in your daily work I see two potential solutions:

    1. Invest your own time, interest and involvement in a language like Perl. Study a lot. Take time to learn. You will be rewarded for serious efforts.
    2. Chose a more limited language. A language that will guide you while typing. Visual Basic comes to mind with it's syntax parsing IDE.

    Now, these are only opinions. But they come from having programmed in many different languages. And from having passed the 'newbie' level in Perl, still without being able to call myself an expert in Perl. Experienced maybe, but not an expert.
    Everything went worng, just as foreseen.

Re: Is Perl worth it?
by broquaint (Abbot) on Apr 23, 2002 at 12:35 UTC
    Perl is a rather lenient language when it comes to the mixing of types (recently explored here). So unless your dealing with really big/small numbers, then there shouldn't be much of a problem.

    As for the likes of infinite loops perl doesn't deal with them any differently to any other code, so they will run infinitely (and potentially consuming a lot of CPU). A web server however may time out such long running processes after a specified period of time, but this depends on which web server you're running and it's configuration.

    Any other 'unpredictable situations' should really be dealt with by the programmer, as it's not the interpreter's job to watch out for programmer short-sitedness. Perl does come with mechanisms for dealing with exceptional behaviour in programs with functions like die() and eval(). There's also the CGI::Carp module which, can handle unexpected program termination in CGI programs with style.

    Ultimately though, if you're writing programs with cpu-hogging infinite loops and any other such follies, then the problem lies not in the language but in your skills as a programmer I'm afraid. So your best choice would be to brush up on programming technique and practice (a lot of which can be found within this site, Super Search is your friend).


Re: Is Perl worth it?
by cjf (Parson) on Apr 23, 2002 at 12:53 UTC

    As already pointed out, Perl, or any other language I currently know of, will not totally prevent all stupid mistakes. However, it is extremely well suited for CGI scripts and, to answer your question, can help you minimize many risks.

    For details take a look at Why Use Perl? and in particular, tilly's reply.

Re: Is Perl worth it?
by BUU (Prior) on Apr 23, 2002 at 12:25 UTC
    It doesnt matter if your program is in perl, or c++, or c, or asm. Infinite loops = bad. No language will save you from your own mistakes. Some might be a little more accepting of mistakes, but you still need to code properly
      infinite loops == bad


        do {} while 'infinite loops' ne 'good'


      Infinite loops = bad

      Use many daemons? I like chicken.
        shush you. i think if he was writing deaemons he would have some idea what he was doing..
Re: Is Perl worth it?
by bcrowell (Acolyte) on Apr 23, 2002 at 16:30 UTC
    Suppose you compare the same application written in C and in Perl. What's the first thing you're going to notice? The C program is about 10 times longer. The number of bugs in a program probably scales as the number of lines of code raised to some power between 1 and 2, so this is a big advantage of Perl. A lot of the string manipulations that a Perl programmer would do with a one-line regex, a C programmer would have to do with a page full of loops and pointers. All that code potentially harbors dangling pointer bugs, infinite loops, etc. Of course if you have access to really good libraries that you can call from C, then maybe you wouldn't have to reinvent the wheel so much. But experience does show this factor-of-10 difference in code size, so either the libraries don't exist, or people don't use them, or they're buggy, or they're nonportable, or they cost money, or ...

    I think a lot of the previous replies to your question were unhelpful: "Infinite loops are bad. Improve your skills." Well, if those possessing true code fu can always write bug-free C code, then why is it that people are still finding buffer-overflow bugs in 20-year-old BSD Unix code? An infinite loop is only one of the classes of bugs that you referred to.

    Also, when you code in C and call someone else's toolbox, you are vulnerable to their bugs. If their code chokes on the parameters you passed and dumps core, then you're going to have a long, hard day ahead of you with a machine-level debugger. This kind of thing is much less of a problem with Perl calling Perl, since, e.g., there's no such thing as a dangling pointer crash.

    Perl will not cure all your problems, but it may reduce them. I also enjoy the process of coding in Perl a lot more than I enjoyed C coding, because I can focus on creativity and problem-solving.

Re: Is Perl worth it?
by thunders (Priest) on Apr 23, 2002 at 14:01 UTC

    yes perl is worth it. CGI is just one of many environments in which perl proves it is worth it. Perl is platform independent, however I'm not sure if there is a 16-bit build of perl anymore, probably.

    Regardless you do not have 16 vs 32 problems if you are coding in pure perl, which you probably would be. You do not declare datatypes like long, int, double, etc. Nor do you have to worry about pointers.

    infinite loops are almost always a case of poor design, not a bug or shortcoming of the language. These will harm your projects performace, so test, test, test. Do not deploy untested code on a production server. Set up a remote server on a localhost. Apache is a great free choice for this. failing that you may test on the command line or in certain IDE's.

Re: Is Perl worth it?
by dev2000 (Sexton) on Apr 23, 2002 at 12:51 UTC
    I'm pretty new also and I've certainly made mistakes like this before, but in my experience it seems as if once the connection is broken (you click stop on your browser) the loop breaks (sooner or later). Is this right?
      CGI programs are executed by the webserver software on a web host system somewhere far away from users clicking things in their browsers. Nobody would want some random user out there in www-space killing processes on their nice server via keypresses in Netscape. :-)

      Clearing up b0rk3n CGI processes (i.e. those containing unintended infinite loops etc) is a familiar task to many a system administrator.

Re: Is Perl worth it?
by perrin (Chancellor) on Apr 23, 2002 at 19:12 UTC
    On a unix-based system, you would use a module like BSD::Resource to limit the amount of CPU a script can use and prevent runaways from killing your server. There's probably an equivalent for Win32, but I'm not sure what it is.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://161266]
Approved by rinceWind
Front-paged by suaveant
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-05-28 07:16 GMT
Find Nodes?
    Voting Booth?