5 ms·
I would like to point out that a possible reason this repo is so popular is that Javascript is more accessible to more people than any other programming languag
by sublinear 4y ago
I would like to point out that a possible reason this repo is so popular is that Javascript is more accessible to more people than any other programming language today and this shows the demand to meet these programmers halfway and help further their education. I think most js devs know Javascript is a poor choice for this, but they have to walk before they can run.
I tend to think of Javascript as the language that fulfills the promises that BASIC never did.
If every student walking into a computer science course only knew Javascript, that would still be a massive improvement over the past where half the students didn't know any programming language at all or only some vastly underpowered ones like Logo or BASIC.
- _s_a_m_ 4y agoIts purpose seems understanding and showing implementations of data structures, in this sense JavaScript is used like pseudocode. No sane person would implement something efficient outside of C++ or C.
- gumballindie 4y agoJS runs on any device regular users might want to use. If done right it’s the best language for what it was built for.
- yCombLinks 4y agoRight, it's the best language because it's available almost anywhere, not because it's well designed or a good teaching language.
- dahart 4y ago> I think most js devs know JavaScript is a poor choice for this Please elaborate, why is JavaScript a poor choice for demonstrating algorithms? Also what would be a better choice, and why?
- aketchum 4y agoAs 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
- stuartjohnson12 4y agoEverything in javascript except primatives are objects. Classes are objects, functions are objects, the runtime environment is an object. Not only is everything an object, but everything is mutable in an unlimited way.
- dahart 4y agoAnd so how does this reflect on whether JS is a good language for demonstrating algorithms? What does it matter if something is an object? How would limiting mutability make a repo of algorithm examples any better? How are these things meaningfully different from other programming languages in this context?
- user3939382 4y ago> I tend to think of Javascript as the language that fulfills the promises that BASIC never did I taught myself BASIC when I was 7 when I didn't know what a programming language was. I've been programming JS for 25 years and I still commonly can't predict what the behavior of some aspects of my code is going to be, or what the state of the application is at a given point, until I try/run it.
- kamranjon 4y ago"4" + 4 = "44" "44" - 4 = 40
- deleted 4y ago[deleted]
- a_wild_dandan 4y agoIn other words: play stupid games, win stupid prizes. ;)
- kamranjon 4y agoHaha yes, most oddities in JS are a result of the language allowing you to play stupid games - many languages would just throw an error here (heck even ruby does). I discovered this strangeness when I forgot to parseFloat on a string and things kept humming along as if nothing was wrong, until I did some addition and things grew exponentially.
- cxr 4y ago> many languages would just throw an error here Some do. Many don't. I have a feeling that most people who say this sort of thing mean "Python" and assume that that's the norm. (The "heck even ruby does" remark def. reinforces that.) Can you name any that do that aren't dynamic languages?
- kamranjon 4y ago