Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How big is yours?

by Jonathan (Curate)
on Oct 10, 2000 at 15:36 UTC ( [id://36055]=perlquestion: print w/replies, xml ) Need Help??

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

I was decoding some Geek code (what a pitiful confession) and saw the following line

I use Perl for all programs of less than a thousand lines.

My first Perl program was about 5000 lines and worked better than I'd hoped. I would happily use Perl for any programming task and have some very large database feed systems to write (approx 20,000 lines). Is my faith in Perl justified or should I dust off my 'C'?


"We are all prompted by the same motives, all deceived by the same fallacies, all animated by hope, obstructed by danger, entangled by desire, and seduced by pleasure." - Samuel Johnson

Replies are listed 'Best First'.
Re (tilly) 1: How big is yours?
by tilly (Archbishop) on Oct 10, 2000 at 15:58 UTC
    I think you are justified in having faith. Certainly browsing some success stories it looks like you are.

    But if you are going to deliver a largish system in Perl, you have to keep a couple of things in mind. First of all start-up times will slow down. Long-running database loading processes won't care, but that is something to know about. The second, and far more important one, is that Perl does virtually nothing to force good habits on you. If you bring good habits in terms of organization, testing, etc to the table then this will not be an issue, but it is a reason at a lot of places to prefer something else for larger projects. Don't get me wrong, Perl offers a lot to help set up test suites etc. But it does virtually no enforcement.

    However 20,000 lines sounds quite doable, and a database feed system sounds to me like an excellent fit for Perl.

Re: How big is yours?
by tedv (Pilgrim) on Oct 10, 2000 at 20:53 UTC
    At Motorola, I designed a simulator for a piece of cell phone architecture in perl that was about 60,000 lines (50k of which were human written). In retrospect, I could have trimmed 10k lines if there weren't so many features to implement. But the crazy thing was that the simulator had a more stable and comprehensive feature set than the actual product!

    I firmly believe that the belief that perl is only good for small applications is wrong. In reality, perl is a very flexible, powerful, easy to use language. But powerful and easy to use always means dangerous, and there are a lot of incompetant programmers out there. Perl code can and will look uglier than any other language. But it can also look more elegant than any other language.

    In other words, the responsibility is on the programmer to write clean code, just as it always was. Using Java or Python may make it more difficult to write messy code, but it also makes it difficult to write elegant code. There is no substitute for a good programmer, and Perl is one of the few languages that admits that.

    -Ted
Re: How big is yours?
by gregorovius (Friar) on Oct 10, 2000 at 19:05 UTC
    You should take a look at the Remarkable appearance of a MS Office clone written in Perl to dispel any scalability fears you may have.

    On humbler grounds my current project (a web app) is about 5,000 lines long, and I judge it much more mantainable than it would have been under C or Java due to Perl's compactness, legibility, facilities for object orientation and CPAN modules.

Re: How big is yours?
by cianoz (Friar) on Oct 10, 2000 at 15:49 UTC
    Once i wrote a perl application of about 15000 lines without relevant issues.

    the most important thing IMHO is a good analisys before you start coding (as you would do in C i suppose..)

RE: How big is yours?
by clemburg (Curate) on Oct 10, 2000 at 22:58 UTC

    With regard to those "N-thousand lines of code" statements, please bear in mind that one line in Perl is many lines in other languages. For a more quantitative point of view on this, please see any of the function-point-metric comparisons of current programming languages (e.g., this one).

    One related important point is the observation that the number of errors in a program increases linearly with the size of the program (in lines of code) (see Code Complete : A Practical Handbook of Software Construction. By McConnell, Steve M. ).

    This obviously means: less code to write for a given functionality means less errors. And less errors make for faster development, and better applications.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

      While in university I wrote a talker for my fiancee and I to get together on. It came out at around 40,000 lines of code altogether (Ok, I admit I got carried away... it was almost a complete MUD including online coding by the time I finished ;) ) After a while I got bored with chasing rogue pointers and decided to do a complete rewrite in a language I had just heard about, Perl. The new system came in at under 10,000 lines ;)

      Seriously though, the question is not really how big a perl program can be, there is no reason why you couldnt write full applications in perl (the people I work for, for example, have a working perl library exceeding 100,000 lines of code) the big question is 'is Perl really the right language?'

      Perl has a number of great things going for it, primarially things like modules that avoid the need to reinvent the wheel and it's easy syntax structure that allows the programmer to concentrate on program flow rather than havng to worry about every little detail. The result of this is most perl programs will be smaller (in terms of lines) and more rapidly written than in other languages. However, the exact same thing works in reverse when it comes to program efficency. Perl is, by definition, an inefficent language when it comes to computer resources. It has to be simply due to the fact that it is interpreted 'on the fly'.

      Therefore, while perl could be used for almost any program, there are a number of situations that preclude it.

      A shame really ;)

        The 'on the fly' remark is a little misleading. Yes, Perl is an interpreted language. However, it's compiled into bytecode and then executed, when possible. (Things like eval which make my life more convenient can be evaluated at run time.)

        The compiler's pretty good about optimizing things, as you'd expect from Real Computer Scientists, so there are things Perl can do faster than the corresponding C program. In other cases, Perl may be slower, but even taking that into account, it's faster to write, debug, and execute a Perl program that runs at half the speed of a C program that takes twice as long to write and to debug.

        The O'Reilly site has chapter 18 (or so) from the new Camel available online, and it goes into the life cycle of a Perl program including the compilation stage. Could be worth a look.

      Just remember...

      That measure of quality is a measure of the quality of the pm's. It's sort of like people comparing JAVA, without it's set of libraries, it's nothing. It's sort of like saying that one line of C is thousands of assembly lines. A line of C and a line of perl can be roughly equivalent given that the object code is out there to back it up. Perl is good because of the support of people like us, who improve upon it, with the great tools that the core language gives us.

      Just Another Perl Backpacker
Re: How big is yours?
by Tii (Monk) on Oct 10, 2000 at 19:36 UTC
    I say, "Keep the faith!"

    IMHO, the number of lines a system is estimated to be should not be the sole determining factor on which language to use.

    As cianoz mentioned, analysis is very important. You should also consider what the program does. A few years ago, I wrote a large part of a data conversion system (that formatted gigabytes of data from different database formats to a single database format) in C.
    I was required to write it in C, but I often think how much easier/shorter/more efficent it would have been if I had been allowed to write it in Perl.

    Tii

RE: How big is yours?
by Jonathan (Curate) on Oct 10, 2000 at 20:24 UTC
    Thats decided then. I'm going to Hack Perl until I drop.
    Thanks to all for such positive replies


    "We are all prompted by the same motives, all deceived by the same fallacies, all animated by hope, obstructed by danger, entangled by desire, and seduced by pleasure." - Samuel Johnson
Re: How big is yours?
by ickiller (Novice) on Oct 10, 2000 at 22:27 UTC
    I wrote a web based application using a lot of modules as a CGI (using FastCGI to overcome the startup overhead). This single CGI is a bit longer than 15000 lines. The overall project contains more than 35000 lines of perl code. It works without any troubles and is also still maintainable.

    Roli

      What is FastCGI? And why don't I know about it?
        Because mod_perl is soo much cooler!

        (... ducking ...)

        Seriously, I bet there's a lot more demand for competent mod_perl hackers out there. The mailing list is always screaming "we can't find enough people to do this XYZ-startup.com project". FastCGI is just a cool way of not firing off processes on each CGI hit, but mod_perl permits full access back to the Apache API to some some wild and wacky stuff.

        -- Randal L. Schwartz, Perl hacker

Re: How big is yours?
by amelinda (Friar) on Oct 10, 2000 at 23:15 UTC
    The statement "I use Perl for all programs of less than a thousand lines" does not, to me, say anything about using it in longer programs. It just says "For short, quick programming, I like Perl." There is no "but for long programs, I like <language>."

    Nothing about that statement indicates to me that the use of Perl for short programs in any way precludes using Perl for long programs. Therefore, use Perl in situations that call for it, be they short or long, complex or simple.

Re: How big is yours?
by cadfael (Friar) on Oct 11, 2000 at 18:35 UTC
    Hmmmm. When one computes the size of a program, does one also count the number of lines in the included modules?

    I don't write many programs over 500 lines, but most of them use CGI and DBI (not to mention SQL) and are designed to provide quick, specific data extracted from a relational database.

    Perl is extremely well qualified to take the hash returned by the db handler and format it for the World Wide Web.

    But then I'm preaching to the choir, aren't I?

    -----
    "Computeri non cogitant, ergo non sunt"

RE: How big is yours?
by Anonymous Monk on Oct 10, 2000 at 23:49 UTC
    32,000 lines according to wc. That's in an interrelated set of applications and modules, though; no one of them will be running all of that code.

    ..Theo

Re: How big is yours?
by Anonymous Monk on Oct 11, 2000 at 21:30 UTC
    I think that the stigma of 'perl is only for small things' is a result of the way in which most most people write their perl code. I'm thinking here of writing huge apps in one script, not using (self written) modules, reinventing the wheel, not coding consistently, etc. IMHO, Perl scales wonderfully to huge projects. If you actually think about the design of the project beforehand and modularize just about everything. Another point is that you can get a lot further in perl without understanding the perl internals than you can in, say, C. Just my 2c.
Re: How big is yours?
by nop (Hermit) on Oct 11, 2000 at 22:47 UTC
    Keep the faith, and use OO and objects to keep yourself from shooting yourself in the foot. Big programs need more design, more thought ahead of time, more structure. Perl can help with all of these.
Re: How big is yours?
by sergio (Sexton) on Oct 11, 2000 at 22:27 UTC
    If you learn the way of the Module and the Object your only limit in perl is the speed of your CPU and the lack of threads (stable threads!) Besides, the number of lines of code makes no sense in any language... only what the code does counts!
Taking heart
by radagast (Sexton) on Oct 11, 2000 at 20:25 UTC
    I've been working on a oddly tricky web mail type cgi script and it is quickly growing in size. However, seeing all these comments about 1000+ line programs gives me some comfort in that my programs aren't too bad but scares the bejeezus out of me at the same time knowing how complex it could get.
RE: How big is yours?
by Nitsuj (Hermit) on Oct 12, 2000 at 09:23 UTC
    Every programming language has it's niche, just remember that. I love perl to death, and it is a great language, but that's no reason to drop the others! Hack the hell out of perl, I know that I do! Just remember that you're not going to be writing a GL app in it any time soon.

    Also, we should remember that k-locks are NOT a good way to measure the size of a program! Just think of a lisp program. I've written HUGE lisp programs, that are technically only 1 line of lisp code, though I did use returns and tabs to delimit for my own sanity!

    Just Another Perl Backpacker
      Heh ;) I'm reminded of the COBOL program I did at college. It was 600 lines in the end... 597 lines of variable declaration and 3 lines of code ;)
Re: How big is yours?
by lemming (Priest) on Oct 12, 2000 at 18:51 UTC
    I would say many of the programs I write are well under the 300 line variety, but I did write a testing system in Perl that was around 5,000 lines.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-03-28 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found