Slashdot Mirror


You Used Perl to Write WHAT?!

Esther Schindler writes "Developers spend a lot of time telling managers, 'Let me use the tool that's appropriate for the job' (cue the '...everything looks like a nail' meme here). But rarely do we enumerate when a language is the right one for a particular job, and when it's a very, very wrong choice. James Turner, writing for CIO.com, identifies five tasks for which perl is ideally suited, and four that... well, really, shouldn't you choose something else? This is the first article in a series that will examine what each language is good at, and for which tasks it's just plain dumb. Another article is coming RSN about JavaScript, and yet another for PHP... with more promised, should these first articles do well."

17 of 307 comments (clear)

  1. Its simple by dintech · · Score: 4, Insightful

    It's obvious that perl is best suited to some tasks over others. So is just about any language. The reason you can't use it in most cases is because it's harder to find developers to support it after you disappear than say Java or C#. That's why I won't be writing our new trade routing system in D.

  2. ob by Hognoxious · · Score: 3, Insightful

    A perl interpreter. Wasn't as hard as I thought.

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  3. Ray Tracing by DrWho520 · · Score: 5, Insightful
    3D ray tracing using Perl...what? Why?!?

    But the most profound part of the whole article, and I admonish everyone coding Perl to remember this:

    Remember that the full version of Wall's quote states, "Perl is designed to give you several ways to do anything, so consider picking the most readable one." Break up long lines into several statements, store intermediate values rather than passing them down a long chain of functions and use comments and whitespace to make the code clear.
    This applies to any language. If you can do it multiple ways, pick the readable one.
    --
    The cancel button is your friend. Do not hesitate to use it.
    1. Re:Ray Tracing by ivan256 · · Score: 4, Insightful

      If you can isolate those tight loops, there's a good chance you can do just that part in C. High-performance should be possible.


      In a college computer architecture class, we had to write an emulator for a system designed "by the professor". Basically all tight loops performing really basic operations, and a lot of synchronization. We were given sample microcode and programs to test with, and when we turned it in he ran it with different microcode and programs to guarantee accuracy. Accuracy was required to pass, but your grade was based on performance and clarity.

      They only perfect score went to an emulator written in Perl. The built-in hash tables, and some smart programming combined with the ease of parsing the microcode and program data created not only the fastest (some classmates used C, C++, lisp, or Java to write their emulators) emulator, but also the easiest to read of the group.

      It's the programmer that creates slow, unreadable code, not the language.
    2. Re:Ray Tracing by Chelloveck · · Score: 3, Insightful

      3D ray tracing using Perl...what? Why?!?

      To the contrary, I think everyone should write a ray-tracer in Perl. Or, more generally, every programmer should take his or her favorite language and use it for something it's spectacularly bad at. Like ray-tracing in Perl.

      Part of the reason is to show that yes, you can use just about any language for just about any task. But that doesn't mean you should. Using a language unsuited to a project gets you familiar with the bounds of the language, so you have a pretty good idea before you start whether or not the language is a good fit for a given task. And it can often teach you a lot about the language, because you'll have to explore the little nooks and crannies to figure out how to get it to do what you want.

      The other part of the reason is that everyone needs a little humbling. This is especially true for anyone who says, "I used to use {language_x} until I discovered {language_y} and realized that {x} is TEH SUCK!" That usually just means that {y} is more suited to what you're doing now. Go code something non-trivial that {y} is unsuited for, and see if you don't end up cursing your new favorite just as much as you curse your old favorite.

      --
      Chelloveck
      I give up on debugging. From now on, SIGSEGV is a feature.
  4. Re:Both sides... by AKAImBatman · · Score: 4, Insightful

    If you use a different tool for every job, you need to maintain all those tools and a task force that's able to use all of them.

    That's why the "right tool for the job" is sometimes the tool that meets the greatest cross-section of a company's needs rather than a jumble of tools that are ideal at a lot of little tasks.

    e.g. While it's fashionable to hate Java these days, you have to admit that it does have a rather massive cross-section of needs it can meet. Thus one of the reasons why it's so popular in large companies. Yet a smaller company might find more value in using Ruby toolkits to do all their work. Ruby may not be ideal for some of the less glamorous back-end tasks, but tools like Rails gain so much on the front end that Ruby meets a greater cross-section of needs than Java would.
  5. refund by darkvizier · · Score: 5, Insightful
    TFA:

    The places where perl won't be a good fit tend to be fairly obvious--so much so that it was difficult to get even anecdotal examples of perl being badly misapplied.
    So... you're saying there's really no point to this article. Thanks. I want my five minutes back.
  6. Re:idiots by Seumas · · Score: 4, Insightful

    The idea that perl isn't a great choice for web sites / web scripting is rather ridiculous. Unless you're looking to use JSP stuff, what is your other option? Ruby? PHP? Come on.

    Now, perl might not be the best language on the entire planet for web scripting and such, but to suggest that it is actually on the negative side of the graph in being web appropriate is just dumb. And I don't need to be a CIO to understand that.

  7. Re:is your company weak? by Sobrique · · Score: 3, Insightful
    Why? Software maintainability is a virtue too, and probably more important than a programmer using exactly the right shiny new language that's _exactly right_ for solving the problem.

    OK, so not all languages are well matched to solving all problems, but keeping it down to a managable number also serves to avoid some major grief in future.

  8. Re:is your company weak? by MBGMorden · · Score: 5, Insightful

    I kinda gotta agree with the parent here. Programming is a mindset. As one of my professors once told us: "50% of what you learned here will likely be outdated within 2 years of graduation. The other 50% will last you the rest of your lives." If you want to be a valuable, well rounded programmer, you need to keep up with the trends and learn a few things here and there. If you know HOW to program at a conceptual level, picking up the syntax of a new language shouldn't be all that hard. And that's why concepts and structures are stressed so heavily in Computer Science. The lessons you learn there should be language independent.

    --
    "People who think they know everything are very annoying to those of us who do."-Mark Twain
  9. Re:According to the article.. by plopez · · Score: 3, Insightful

    yes. comment code. don't use the fancy tricks unless you really, really have to. Ask yourself "I can be clever at this point, but do I really have to be?" In short be humble and use the simplest thing that will work. Good advice in any situation.

    --
    putting the 'B' in LGBTQ+
  10. Re:An Intelligent FrI$T Psot. by Schraegstrichpunkt · · Score: 3, Insightful

    You have to be careful, though, not to miss newly-developed cost-cutting/quality-improving technology (e.g. Pylons and Django, neither of which existed in any useful capacity more than 3 years ago) or your competitors will eat your lunch.

  11. Re:Both sides... by hardburn · · Score: 5, Insightful

    I hate the "right tool for the job" cliche. Not because it's necessarily wrong, but because it tends to be used by people who automatically assume that their tool is the right one and wish to stop any serious discussion about other possibilities.

    --
    Not a typewriter
  12. Re:is your company weak? by Aladrin · · Score: 3, Insightful

    I agree, and I do pick up languages like nothing.

    But the problem isn't 'picking up a language', it's picking up 3. If we hire a new recruit, to expect him to learn 3 new languages immediately is ridiculous. So we don't -have- a ton of different languages in use, we have a choice few that cover everything reasonably well. In fact, since I started, we have dropped 1 and almost dropped another. (They're waiting on me to have time to rewrite that last program in another language.)

    In addition to not having to have new recruits learn those 2 languages, we also don't have to maintain the software needed for those 2 languages. That saves employee time and computing power both.

    And in truth, I tried to suggest adding a new language a few months ago... And after discussion, we decided the benefits didn't outweigh the costs. I was the only one who already knew the language at all, and it wasn't -that- much better than what we had.

    If we were a huge company with thousands of employees, it might make sense to have specialists in each of the languages and also use 'the right tool for the job' ... But I somehow doubt it. I suspect it would still end up being better to use 'the right tool for the majority of the jobs'.

    --
    "If you make people think they're thinking, they'll love you; But if you really make them think, they'll hate you." - DM
  13. Re:is your company weak? by Hognoxious · · Score: 4, Insightful

    It isn't that hard to pickup a new language, unless the reason you have to pick it up is to maintain an app written by someone long gone...
    ... who didn't know how to use it properly either.
    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  14. language vs library by bzipitidoo · · Score: 4, Insightful

    I wonder if this whole discussion is off the mark. Languages are for the most part trivial. And universal. "It's the libraries, stupid" is sometimes how I feel. If it was easy to link in or call any library function from any language, then half of this discussion would immediately be seen to be irrelevant. So Perl is "the right tool for the job" because it has the ability to apply regular expressions to strings? But, you know, C can do that too thanks to this PCRE library. Hashes? C can do that too via another library. In case anyone has forgotten, Perl itself is written in C. I read that Perl 6 has vastly improved the interface to other languages, especially C libraries.

    These day, whenever I write a new program it often feels as if I'm creating yet another language. A simple, superficial, limited language, but nonetheless, a language. Program needs a configuration file? Whip up a suitable format (language) for that. Needs to save data? Barf out this big data structure into a YML file. Want some way to run the interface from a batch process, or otherwise automatically? Start turning the user interface into a language. Want to connect Perl 5 and C? Get acquainted with XS, a "language" the Perl folks felt it necessary to create for that purpose, because Perl 5 wasn't good enough alone. Want to compile a large project written in C? Get familiar with the language of Make, because while C certainly could do it, C isn't so good for that. Is ANT a "language" for building Java projects? Where's the line between language and library?

    I suppose where things lead to a new language is when someone wants to implement a new concept and the established ways aren't good enough. Or has a way to eliminate a bad programming practice, but some elements of an existing language must be dropped to do it. For instance, wouldn't be nice to have variable length parameter lists in C, as C's own printf function does? Too bad it's such a pain to do that in C. How about lazy evaluation and currying so we can have infinitely long parameter lists? Oops, guess the C call stack can do recursion, but isn't too well suited to expressing that sort of thing, time to make another language, Haskell. Do we want to pass along a pointer to a structure, or a copy of a structure? Java defaulted to pointers where C did not, but then said Java didn't use pointers. Nice not to have to type in ampersands and asterisks all the time, but still, I find the thinking misleading. Then there's garbage collection. The consensus is that garbage collection is overall a good thing, but that a good programmer can do better than the automatic garbage collector. And so on.

    --
    Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
  15. People keep saying this... by JavaRob · · Score: 4, Insightful

    ...and I tend to think they just aren't doing anything *significant* in just-learned languages.
    The problem is not learning the syntax and basic idioms. Agreed, that's pretty quick, particularly if you have a good reference.

    The problem (and the time sink) is the *ugly* side of every language. The parts of the standard libraries that sucked, and were reimplemented elsewhere (but you gotta know that...). The functionality where everyone who "lives with" the language grabs X open source library to implement -- not Y! it's a POS! -- but you don't know that yet. The language features that have secret, illogical gotchas for special cases. The bugs in the compiler or interpreter that are easy to avoid -- once you've been burned once. The code that will break cross-platform compatibility for obscure reasons. The code that will make it almost impossible to internationalize later, because you didn't learn how that support worked yet.

    Granted, the cost of these things with any reasonable mature language should not be enormous (though it depends how long you go down a wrong path...), and you can allow for it, but it's always a significant risk *especially* if you don't have someone on the team (perhaps the new team who has to maintain your old code) who's already more-or-less expert level.

    But either way, you have to allow *something* for that cost, and sometimes it's not worth it just to use the absolute best tool for the job when you have a pretty close fit available.