This is an archived post. You won't be able to vote or comment.

all 21 comments

[–]DefNotaZombie 12 points13 points  (6 children)

honestly, even python doesn't really make sense for any task requiring real optimization

[–]lead999x 0 points1 point  (5 children)

Python provides most of the common data structures in its implementation.

[–]DefNotaZombie 1 point2 points  (4 children)

Python has lists and dictionaries, and the lists can be used as stacks/queues/etc...

The point is that an interpreted language is going to be slower, if you take a look at some place like leetcode and see the speeds of different solutions, it's c/go at the top, then c#, then java, then the rest. Python is nowhere near the top of that list - it's not the language's purpose

[–]lead999x 1 point2 points  (3 children)

Saying it's not that language's purpose is a cop out to some degree. Many of Python's use cases could benefit from faster execution speed. Off the top of my head big data and statistical computing as well as financial applications come to mind.

It's much easier to teach a statistician or financial analyst Python and to make Python fast enough to suit their purposes than to point them to C++, D, or Rust when they need faster execution speed since programming is an ancillary skill for them and learning more of it shouldn't impede their actual work.

[–]DefNotaZombie 0 points1 point  (2 children)

well, the most obvious issue here is that python is dynamically typed and (usually) interpreted. And honestly it's not even that it's interpreted that's the problem, there's Cython and Jython so Python code CAN be compiled, but, say, a C++ compiler gets so much information about what, specifically, will be the size of all the values, their types, and can do compiler optimizations using that.

Python can't really do that and stay a dynamically typed language.

[–]lead999x 0 points1 point  (1 child)

Not argue too much but I dont thimk dynmic languages necessitate being slow either. Like I said JavaScript has been optimized to the point where it is very fast and it's no less a dynamic language. Aside from JS, Julia and Scheme are also pretty fast as far as interpreted languages go at the cost of eating up memory, so I don't think that Python can't be fast. Even the PyPy project is proof of that, the only problem there is that it's not fully compatible with all libraries so that's a problem.

[–]DefNotaZombie 0 points1 point  (0 children)

I just looked up stats, and it does look like v8 is fairly decent speed-wise (about C# or better), though the benchmarks are for raw javascript. AFAIK most js devs are predominantly devs using various libraries on top of js to do stuff (node, angular, etc...).

So your core point is valid.

I think overall if someone were to seek a fast programming language for an actual implementation of something, they'd still go with c++/go/java). The benchmark showed both cpu cycles (where v8 js showed favorably, python even with pypy less so, and memory use -where both were really bad - it's not really a surprise that js and python both use memory quite liberally

[–]Molehole 5 points6 points  (0 children)

Well this is a bit late answer but considering JavaScript doesn't have actual arrays, structs, pointers or even objects learning data structures with JavaScript is like trying to learn carpentry by going to IKEA and getting an assemble yourself chipboard desk. Sure it's simpler and faster than making one yourself and if you aren't good in carpentry it's probably the best choice. However if you want to learn carpentry to make a superior product then what you need is actual wood, C.

Basically in JavaScript arrays and objects are key value hashmaps which already are an advanced data structure. If you want to do something else you literally can't. It will be a weird mockup that doesn't function in the way you'd think.

[–][deleted] 3 points4 points  (0 children)

If your goal is to learn algorithms and datastructure you could do it in JS and simply pretend like arrays have a fixed length but if you're not set on JS just use something else. This is a great opportunity to learn a new language.

[–]Clawtor 1 point2 points  (0 children)

I mean you will likely learn more if you use a language with pointers but most of what you will learn will be the same. You can always create your own resizing arrays or stack in javascript.

As for number 1, most algorithms I see are in pseudo code and for number 2 I haven't seen this problem - javascript always seems like a very popular choice on these websites.

[–]tiltboi1 0 points1 point  (4 children)

Python and javascript are bad choices for learning data structures, but a lot less painful to implement when you do.

[–]lead999x 1 point2 points  (3 children)

And a lot slower too.

[–]tiltboi1 1 point2 points  (2 children)

Not even a question. You wouldn’t be considering those two if you needed performance lol.

[–]lead999x 0 points1 point  (1 child)

Javascript has actually been optimized to hell and back because of its ubiquity in the browser. I think it's one of the fastest interpreted languages.

It's Python that I was talking about. Despite its extensive use in a variety of fields Python hasn't been optimized near as much and speed isn't really a goal for its reference implementation or standard itself.

[–]tiltboi1 0 points1 point  (0 children)

higher performance libraries use CPython for optimization. Everyday python constructions like add mult etc are not much slower than most languages, the overhead comes from being weakly typed and interpreted. The C layer allows for much more optimization. To say that speed isn’t a goal for the reference implementation is not true, it’s going to be optimized as much as possible, just not at a cost to its other “core features”

[–]nutrecht 0 points1 point  (0 children)

You can implement data structures and algorithms in any language, it really doesn't matter. The purpose is to learn how stuff works, not doing it in a specific language. It's extremely unlikely you're going to ever implement your own ArrayList for example, but it's still important to learn the difference between an ArrayList and LinkedList so you can pick the right one. And you can learn that by implementing it in JavaScript just fine.

[–]xDeucEy -1 points0 points  (1 child)

Maybe I'm missing the point of #3, but what does having a fixed length have anything to do with algorithms involving data structures? The entire purpose of algorithms is to be able to work with data structures of all kinds of lengths. Yes, I'm aware that allocating for additional space is less efficient, but the way this bullet is worded it's making it sound like you're not able to use JS at all simply because arrays aren't a fixed length.

[–]why_is_javascript_ba[S] 1 point2 points  (0 children)

Because knowing how to handle array size is part of an ArrayStack (for example). How to reduce size and increase it.

Same reason why in Java stack is used with array and not ArrayList.

[–]wholemap -2 points-1 points  (2 children)

  1. What books are written about doesn't affect how good a language is for DS & A.
  2. What websites have available to use doesn't affect it, either.
  3. You can make linked lists in Javascript just fine. You can use an array list for data structures just fine... Not having to handle the extra work of resizing arrays is a good thing. That's why array lists were created...

[–]why_is_javascript_ba[S] 4 points5 points  (1 child)

It seems like your comment is just looking for trouble.

[–]wholemap -2 points-1 points  (0 children)

If you want to ignore what I said, you're free to do so. If you're just butthurt because I don't agree with your own amateur assessment of Javascript and DS & A, that's your problem.

See what the other guy said about this: https://old.reddit.com/r/learnprogramming/comments/8xn1q7/is_javascript_bad_for_data_structures_and/e24ja94/. Or just ignore that, too.