Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: C vs. Perl

by gmax (Abbot)
on Oct 22, 2003 at 16:02 UTC ( [id://301261]=note: print w/replies, xml ) Need Help??


in reply to C vs. Perl

Some criticism about your code is in order.

In Perl you would write like this

In Perl I would write a one-liner.

perl -ane '$items{$F[0]} = $F[1] ;END{print "apples cost $items{apple} +\n" if $items{apple}}' data
your code should be able to handle any number of items

But yours will only handle as may item that can fit into your system's memory. If I had really to handle "any number of items" I would use a DBMS. And still you fail to convince me that I couldn't do the same in C. With more lines of code, perhaps, but I can do it in any language I have used so far.

#here you can also get the name from the user and print the #price.

But let's assume that there is no "apples" in your input. You would print an empty price. You should check first.

The bottom line is, you don't compare two main languages using such a trivial example and offering no alternatives, especially if your "positive" example is questionable as well.

I have coded in C for many years, and when I switched to Perl it wasn't because C wasn't up to my expectations. It's simply that Perl is easier and faster to code.

If you want to consider a more critical comparison of a specific implementation of a well established algorithm, have a look at Perl's pearls

 _  _ _  _  
(_|| | |(_|><
 _|   

Replies are listed 'Best First'.
Re: Re: C vs. Perl
by hardburn (Abbot) on Oct 22, 2003 at 16:31 UTC

    But yours will only handle as may item that can fit into your system's memory. If I had really to handle "any number of items" I would use a DBMS.

    If you want to be pendanic, then you'll still be limited in a DBMS by your hard drive space. Now, where did I leave that piece of infinate paper tape?

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

Re: Re: C vs. Perl
by sauoq (Abbot) on Oct 22, 2003 at 21:18 UTC

    Some criticism about your reply is in order.

    And still you fail to convince me that I couldn't do the same in C.

    He wasn't trying to. Read his first line again: "I was wondering how C makes certain things harder to write and perl (and similar languages) makes it easy to write."

    Apparently, you agree with his premise because you said, "It's simply that Perl is easier and faster to code."

    He's just wondering "why"...

    The reason is that Perl was designed so that code for a problem would map more easily to the programmer's way of thinking about it and C was designed so that code for a problem would map more easily to the machine's way of executing it.

    BTW, as for your one liner, how likely do you think it is that you would actually have to do that on the command line? It's far more likely that that task would be part of a larger program... in which case using -a probably wouldn't help at all.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-18 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found