4 ms·
As someone that writes Node as main production language, I will say I am very glad to have been taught my DSA courses in Java. I think a strongly typed language
by aketchum 4y ago
As someone that writes Node as main production language, I will say I am very glad to have been taught my DSA courses in Java. I think a strongly typed language like Java that also requires explicit memory management (if you restrict yourself to using only Arrays) is ideal because you can not ignore things that are abstracted by the language. In python or JS the standard array class is more like ArrayList and it automatically reallocates space when needed. This is hidden from you and you do not realize the additional computations that are occurring and thus you do not learn as well.
- qwertyuiop_ 4y agoJava is anything but explicit memory management. If you really want to understand and work with memory management it’s C/C++
- dahart 4y agoIf you look inside this repo, they don’t rely on the standard array class for the linked-list or the stack. Given that, what’s wrong with Javascript? My first DSA class was Scheme, btw, and it was absolutely fantastic, one of the best classes I had. Worrying about memory management is important to learn eventually as a CS major, but certainly is not necessary for an introduction to algorithms and structures. It all depends on what you want, right?
- dxbydt 4y ago> If you look inside this repo I actually looked in the repo & I believe some of it is incorrect. For instance, the signature insert(value, rawIndex) in [1] makes no pedagogical sense. Quoting from [2] - "There is no real concept of index in a linked list...Certainly none of the methods provided on the class accept indexes....Thinking of a linked list as a list can be misleading. It's more like a chain" He's then using this linked list as a base layer to implement Queue & Stack - which is correct - but doesn't ever use the insert with rawIndex functionality in either enqueue() or push() - so one wonders what the point of that index even was. Traditionally, a linked list allows you to insert before/after a node. i.e. addBefore(node,value) (see [2] ) He doesn't implement addBefore & addAfter. Instead, he provides a whole bunch of non-canonical helpers like reverse(), toArray(), deleteTail() etc - these are typical LC-Easy problems that don't belong inside the data structure. My own introduction to these things was a C course called "Data Structures in C" in the traditional CS curriculum, and yes, you would have to malloc a new node, get back a pointer with a memory address, & the process of pointing the next pointer of the current node to this new node so that the memory address of the next value was explicitly "linked" to the current value and hence linked list etc...I guess much of that terminology is lost on the new generation in the absence of pointers & memory addresses. The canonical exercise in those days was - Show that a linked list does not store objects in contiguous memory, unlike an array. So to solve this, you would traverse the list from the head node & print the actual addresses of the memory locations along the way, proving that the vals aren't stored contiguously. I wonder what that exercise would mean in JS land. That said, yeah its a good starting point & I applaud the effort. [1]https://github.com/trekhleb/javascript-algorithms/blob/master/src/data-structures/linked-list/LinkedList.js https://github.com/trekhleb/javascript-algorithms/blob/maste... [2] https://stackoverflow.com/a/7777687 https://stackoverflow.com/a/7777687
- hn_throwaway_99 4y ago> I actually looked in the repo & I believe some of it is incorrect. For instance, the signature insert(value, rawIndex) in [1] makes no pedagogical sense. Quoting from [2] - "There is no real concept of index in a linked list...Certainly none of the methods provided on the class accept indexes....Thinking of a linked list as a list can be misleading. It's more like a chain" Java's LinkedList implements List, and supports index insertion. I'm not arguing it's "right", but I am arguing it's not "incorrect". It's a design decision, there are pros and cons to it (as your second link points out, C# went a different route), but I think it's a totally valid option.
- cxr 4y agoTyped arrays and array buffers have been a thing in JS for longer than many of today's crop of programmers have even been writing code. (For longer than this repo has existed, at least.) And I don't know any language called "Node". (That isn't to say that this project is a particularly good example of how to write algorithms-focused code. It isn't.)
- aketchum 3y agocongrats on being a pedant! "I write all my production code in the javascript runtime environment called Node.js"
- deleted 3y ago[deleted]
- cxr 3y agoYou act as if I'm trying to place some unreasonable standard for verbosity upon you. In reality, it doesn't take that, and it would have sufficed to have just said "JS" where you originally wrote "Node". The JS-is-not-Node aside was not exactly the most important part of my last comment, anyway.
- nyarlathotep_ 4y ago> requires explicit memory management (if you restrict yourself to using only Arrays) Did you mean C++?