I'm thinking of doing some c. I haven't *really* looked at c code in ages. But i was just debugging a c script, and it looks nice to me. i could kinda use not doing $ sometimes..

How does perl compare to c, some basic thoughts. compiled vs. interpreted/compiled, etc. what are some strengths and weaknesses one would point out in how these languages compare? What are a couple of examples you would, and would not choose one language over another. If say, you were to make a script that opens a log file and formats it in some specific funky way, and saves it in parts somwhere else, you may use perl- right? What if you need to auto generate ascii art on the fly? maybe a pre-compiled c program would be better for performance, right? wrong?

Replies are listed 'Best First'.
Re: (OT) perl cmp c
by zentara (Cardinal) on Mar 16, 2006 at 13:04 UTC
    I think about it often, although I'm not much of a C programmer, I understand the basics. To me, Perl is an easy-to-use front-end to C. The most common big problems I encounter when doing a C program,are:

    declaring the variable type, which are not intuitive, and worrying about overflows, and casting.

    buffer overflows

    lack of a linked list structure type (i.e. Perl's hash )

    Perl modules are much easier to use than figuring out how to incorporate a C lib into your app. Static vs. Dynamic linking, etc.

    Perl handles all of these for you, at the expense of speed. So as others have said, if you need speed, or are moving alot of data, C is better. But almost anything you can write in C, can be done in Perl, and it can be written faster. So write in Perl, and if you need speed, convert it to C.


    I'm not really a human, but I play one on earth. flash japh
Re: (OT) perl cmp c
by Moriarty (Abbot) on Mar 16, 2006 at 00:30 UTC

    I have never seen C being described as "looking nice" before, however, having been programming in C a lot longer than I've programmed in Perl (13 yrs v 4 yrs) I can see advantages in both.

    C is good if you have a lot of data to be moved around (eg graphics) and your need the speed of a compiled language. Perl is good for extracting/analysing information in text files or for quick programming jobs where running time isn't critical.

    It really is a matter of choosing the right tool for the job (IMHO).

    M

Re: (OT) perl cmp c
by Fletch (Bishop) on Mar 16, 2006 at 02:27 UTC
    i could kinda use not doing $ sometimes..

    *cough* :)

      yo yo, yea.. i looked into ruby..thing is, it seems that both python and ruby are geared towards OOP- especially ruby. That's what the creator said.

      The fact that indenting is part of the language is .. very interesting.. and also.. *very* different.

      Also, I thoguht the creator said perl smacks to him as a toy language. That kind of turned me off. But here is an article that is interesting where Matz talks about languages, ruby, etc. I love what he says about no language being perfect for everyone. Very solid thinking.

Re: (OT) perl cmp c
by spiritway (Vicar) on Mar 17, 2006 at 04:55 UTC

    I think your question depends largely on what you need to do with your program. C is great for times when you need to be close to the bare metal, but it's difficult to use and can get you into a world of trouble fairly easily. Pointers can be fun and powerful, but they really give you a whole lot of rope with which to hang yourself. You should see my poor neck ;-)

    To my understanding, C would be faster to run for most uses. It compiles to machine code, as opposed to Perl compiling to byte code. This won't matter if you're waiting for a keypress, but in graphics and heavy math, the difference may be crucial.

    The thing is, it takes much longer to develop working code in C. Imagine what is involved in creating, filling, and sorting a hash. A competent Perl programmer could knock it out in a few minutes. A Perl wizard could probably write a one-liner. A good C programmer would probably need an hour or more to accomplish the same thing.

    In general, I'd use Perl for just about everything, because it is so easy to use (and fun). And because if I get stuck, I can always come here to Perl Monks and get an answer within minutes (usually). If I were trying to do something with heavy graphics use, hairy math (matrices, for example), any sort of time-consuming stuff, and if there were going to be large iterations of things, I'd probably bite the bullet and write at least those parts in C. So far, I haven't found anything that has required me to do this. Perl has worked just fine for everything I've needed, even digesting megabytes of text and spewing it out all neatly organized. I'm glad C is available, "just in case", but I hope I'll never need it.

Re: (OT) perl cmp c
by samtregar (Abbot) on Mar 16, 2006 at 18:51 UTC
    There's no reason to chose one or the other when they go together so well: Inline::C.

    -sam

Re: (OT) perl cmp c
by Anonymous Monk on Mar 16, 2006 at 04:16 UTC
    How does perl compare to c, some basic thoughts.
    Take a look at the Shootout.
Re: (OT) perl cmp c
by Jenda (Abbot) on Mar 20, 2006 at 16:29 UTC

    I could kinda use being allowed to do $ in other languages, especially if I could do $ even in string literals.

    I'm probably not the right person, but ... I dislike C, I dislike it a lot. And the thing I dislike most are the aroundfix types. <lotsa modifiers> <strange characters> <variable name> <a number or maybe not in square brackets> or even <lotsa modifiers> <strange characters> <function or variable name> "(" <lotsa modifiers> <strange characters> <param name> <square brackets or not>, ... ")" ? Function returing a pointer to int versus a pointer to a function returning int, anyone?

    Besides, while programming, do you think "and now I'm gonna need an integer, let's call it counter" => int counter; or rather "and now I'm gonna need a counter, it could be an int" => var counter : int;

    Plus its dated, simplistic "type system" that you have to circumvent all the time to get anything done .. no thanks, C's not for me, thank you very much.