I read the presentation. It is hard to know where to begin on responding. There are a lot of true facts presented, and it all sounds very clever. But the big picture is completely wrong.
Yes, there is overhead with arrays, and yes you over allocate space. (My memory says 5/4, not by 2, but that's a minor implementation detail.) However a linked list has so much overhead that it is always going to lose. Yes, a push on an array can cause it to come unshared in forked processes. But thanks to the way that Perl uses reference counting. the simple act of iterating through a linked list will cause all of THAT to become unshared. Yes, arrays that take space don't untake them. But if it matters, it is easy to keep the array that will grow in an array ref, and then replace the array ref to save space. Yes, arrays pose locking issues. But Perl's story around multi-threading sucks so much that if you're worrying that, you're probably doing something fundamentally wrong. And so it goes. It all sounds smart, but he's thinking about it wrong. On Sat, Nov 1, 2014 at 11:03 PM, Adam Russell <[email protected]> wrote: > Well, this isn't code being written for any purpose other than to experiment > with some algorithms and data structures. The fact that it is in Perl > is just for fun. That said, I believe that there is a good use case for > linked lists when you want to strictly control memory allocation. > Last I heard, Perl arrays grew in large chunks (I forget the details) > whereas with a LL the memory allocated by perl will grow > more slowly. This is from a talk I heard back in 2009 at YAPC > (http://www.slideshare.net/lembark/perly-linked-lists) so some of these > advantages > may no longer be applicable. I'd be interested in knowing of this was the > case. > > As to your question, well, I have no strong reason (again, just playing > around here). My thinking is along the lines of that I would rather have a > "book" have "pages" > than just have "pages". Perhaps too subtle a point that isn't worth trying > to capturing. Anyway, my analogy isn't exact since my "book" is really just > a reference to the > title page. :) > > >> Date: Sat, 1 Nov 2014 22:44:50 -0700 >> Subject: Re: [Boston.pm] object composition (has-a) with built-in OO >> system >> From: [email protected] >> To: [email protected] >> CC: [email protected] > >> >> Just so that you know, it is very hard to find a use case for linked >> lists in Perl where a native array is not a better option. That said, >> why draw a distinction between a node in a linked list and a linked >> list? I would just have one class, that is a reference to a node. >> (That itself might have children.) The one exception is if you wanted >> a doubly linked linked list, and wanted to avoid having a memory leak. >> >> For inheritance, usually you just set up @ISA in some way. Either by >> explicit assignment, or with 'use parent'. (The modern replacement >> for 'use base'. Though I don't know why that needed replacing...) >> >> On Sat, Nov 1, 2014 at 10:36 PM, Adam Russell <[email protected]> wrote: >> > I was experimenting with some code, jogging my memory of linked lists. >> > >> > The approach I took was to define a package LinkedListNode and then a >> > package LinkedList. >> > My idea is that my LinkedList package is a wrapper around the head node >> > which would also define >> > some useful methods such as print_list(), remove_node(), and so forth. >> > >> > I did this by having the constructor for LinkedList create and bless() >> > the head node. >> > But then I ran into a problem having this object call LinkedListNode >> > methods. This was solved >> > by making LinkedList a subclass of LinkedListNode with the line >> > unshift @ISA, 'LinkedListNode'; >> > >> > Ok, so I am doing what seems to me to be "composition" in OO speak. That >> > was my design intention anyway. >> > The only way I've found that it works is to use a parent class >> > relationship. Does Perl have some >> > other way of doing this, using the built in OO system? >> > I've read >> > http://search.cpan.org/~rjbs/perl-5.18.4/pod/perlootut.pod#Composition >> > and it seems that the answer is "No, what I've done is the way to do >> > it." but I thought I'd ask in case >> > I'm just not getting something? >> > >> > I only want to use the Perl built in OO system. I am aware Moose (and >> > others) have facilities for this. >> > >> > My code is at http://pastebin.com/8fnxY0Xy if you'd like to take a look. >> > Any other questions or comments on this code would be appreciated as >> > well. I've been brushing up on a few things >> > and am open to comments. >> > >> > Thanks! >> > Adam >> > >> > _______________________________________________ >> > Boston-pm mailing list >> > [email protected] >> > http://mail.pm.org/mailman/listinfo/boston-pm _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

