Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^6: [OT:] Is this Curriculum right?

by karlgoethebier (Abbot)
on Nov 26, 2021 at 20:25 UTC ( [id://11139152]=note: print w/replies, xml ) Need Help??


in reply to Re^5: [OT:] Is this Curriculum right?
in thread [OT:] Is this Curriculum right?

«…never felt the urge to write my own linked list class…»

I talked about this issue with the boy’s teacher and it was like talking to a horse as we say in German. Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^7: [OT:] Is this Curriculum right?
by eyepopslikeamosquito (Archbishop) on Nov 26, 2021 at 23:51 UTC

    > it was like talking to a horse as we say in German
    Thanks for the lesson in German idioms! What I love about Perl monks is you can't predict what new things you'll learn each time you log in. :)

    I think I agree with your sentiment ... unless I've totally misunderstood due to my lack of fluency in German :). Sadly, I can't think of a single thing I learnt at Melbourne University that was of pratical use in the workplace, it was all way too theoretical ... while a lot of the stuff I learnt at good old RMIT night school was of immediate practical use on the job next morning ... though I see working class RMIT has now become a "University". Oh well. :)

    For every one Alexander Stepanov, writing complex and powerful low level libraries, or Larry Wall, designing post-modern programming languages, there are thousands of journeyman programmers being paid to get their job done by using these languages, libraries and frameworks. And, frankly, you wouldn't want to let most of them near such intricate code. Though I'd love to have a well paid job designing languages or low level libraries, there aren't many positions available.

    Though a brief lesson on data structure concepts (arrays/vectors, strings, maps, hashes, trees, and yes, linked lists) is basic and essential, a more practical education would spend more time on using them, rather than implementing them.

    Please let me know if I've misunderstood the point you were trying to make.

Re^7: [OT:] Is this Curriculum right?
by Marshall (Canon) on Nov 27, 2021 at 00:16 UTC
    Let's see what happens with the code that I sent you.
    BTW, here in the US we had a talking horse on a popular TV show called, "Mr. Ed" and he was a pretty smart horse.
    If your boy's instructor cannot understand my code, then as you perhaps would say, "I see black", Ich sehe schwarz.
        Great to hear this!

        I don't code in PHP, but this looks like it has the basics of a linked list and demonstrates understanding of the concept. It is a bit bizzare because inserts are positon based. Normally when tranversing a linked list, you are searching for something like a hash key in the case of a Perl bucket's list (search through entries that hash to the same hash value's index, looking for a match, or not of a particular key). Counting through the list to go to say the 5th thing is weird. That traversal of the list just to count them is inefficient.

        As far as Perl goes, there is no need for something like this because you would just use a Perl array. The Perl array can contain simple scalars or references to objects or whatever. One tricky bit is inserting or deleting something in the middle of the array, but Perl handles all the details via splice(). And of course also implements: push, pop, shift, unshift. So Perl array implements the functions of the SplDoublyLinkedList class and handles all the messy memory allocation and reference stuff for you.

        A C implementation of what this PHP code does (essentially an indexed array of pointers) would probably not be done via a linked list, but but rather a simple linear array of pointer to objects. For the head, instead of a single pointer to pointer to array, you would need a struct to describe: start of memory array allocation, end of memory array allocation, pointer to first sequential item within allocated memory and pointer to last sequential item within allocated array memory. Basically a block of allocated memory for the pointer array and a sequential block within that block that is actually "used" at the moment.

        To shift an element off of the top, you just adjust the pointer of the first item within allocated memory. To delete something from the bottom, you just adjust the pointer of the last item. Adding something to the top or bottom is also easy as long as there is enough "slack space" (unused "entries" within the allocated block of memory).

        Adding/deleting something in the middle is more complicated. To delete the 2nd item, you have to move the pointers to the 3rd-nth items "up" in the array. However moving blocks of memory is something that the processor can do very efficiently. The normal C function that does this is very fast and at maximum optimization levels or via an ASM subroutine, this is actually a single machine instruction! Growing the array would require memory allocation of new memory and copying the existing stuff to that new bigger array.

        Anyway, there is usually no need to implement a linked list like this PHP example in Perl because the Perl array basically does that. There probably is some outlier case, but normally that is not the situation.

      «…I see black…»

      MeToo. I’ll report what happened. Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found