(OT) perl cmp c
leocharre
created: 2006-03-15 18:47:18

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?

Re: (OT) perl cmp c
created: 2006-03-15 19:30:29

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
created: 2006-03-15 21:27:41
i could kinda use not doing $ sometimes..

*cough* :)

Re^2: (OT) perl cmp c
created: 2006-03-19 14:16:29

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
created: 2006-03-15 23:16:30
How does perl compare to c, some basic thoughts.
Take a look at the Shootout.
Re: (OT) perl cmp c
created: 2006-03-16 08:04:10
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
created: 2006-03-16 13:51:18
There's no reason to chose one or the other when they go together so well: Inline::C.

-sam

Re: (OT) perl cmp c
created: 2006-03-16 23:55:55

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.

perlmonks.org content © perlmonks.org and Anonymous Monk, Fletch, Jenda, leocharre, Moriarty, samtregar, spiritway, zentara

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03