in reply to Re^3: Perl vs C
in thread Perl vs C

I would have said that functionally, a linked list is more like a hash than an array, so the argument seems prone to falling off a cliff and accelerating exponentially as it enjoys the gravity.

An irony might be that I would bet that perl hashes are implimented via C pointer arrays (just a guess).

Another guess: 6X is bang on, bytes of code wise (but how long you took with each line may be another thing?...the only real "efficiency" may be comprehensibility, which should have to be wildly Subject-Oriented)

Replies are listed 'Best First'.
Re^5: Perl vs C
by GrandFather (Saint) on Mar 15, 2009 at 07:13 UTC

    Actually a linked list is orthogonal to both C arrays and Perl hashes, but is somewhat similar to Perl arrays. Given that Perl arrays are partially implemented using linked lists, that shouldn't be too much of a surprise. Although, at the end of the day, anything written in C (and Perl is written in C) uses combinations of C arrays and pointers in any case - that's pretty much all there is in C.

    It is easy to argue, because of the greater complexity arising from the greater size, that it takes longer per unit (lines, bytes, whatever) as the size increases. One could also argue that as the functional density increases per unit of size so does programming time (that's the comprehensibility thing). The implication is that somewhere there is a crossover point and a further implication that as functional density increases so does scalability. The interesting conclusion is that Perl is faster to code and scales better than C. And, because opportunity for bugs tends to be size related, Perl code likely has fewer bugs than the equivalent C code.

    Update struck bogus comment.


    True laziness is hard work
      Given that Perl arrays are partially implemented using linked lists, that shouldn't be too much of a surprise.
      That is new to me. I never got that impression from the perlguts manual page, nor from the illustrated version. Care to explain where linked lists come into play?
Re^5: Perl vs C
by tilly (Archbishop) on Mar 15, 2009 at 16:21 UTC
    You can argue until the cows come home what the appropriate Perl analogy for a linked list is. But there is no question about whether they are often used in the two use cases I presented, and about whether Perl arrays are appropriate as a replacement for that use case.

    I don't know what you meant by saying that Perl hashes are implemented via C pointer arrays. They certainly are not just internally an array. But as is normal for implementing a hash table, Perl hashes are implemented using both a C-style array for the lookup of the hash bucket from the hash value, and linked lists for the contents of each hash bucket. For the details you can look in perlguts, and for the really gory details read hv.h and hv.c in the Perl source code.

    To answer your rhetorical question about how long it takes to write Perl, multiple studies across multiple language, backed up by anecdotal experience among Perl programmers that I know, says that X lines of Perl takes roughly as long to develop as X lines of other mainstream programming languages. Furthermore comprehensibility is more an effect of the programmer rather than the language. Though if you wish to write incomprehensible code, as Larry Wall says, In accordance with UNIX philosophy, Perl gives you enough rope to hang yourself.