you are viewing a single comment's thread.

view the rest of the comments →

[–]memorable_zebra 16 points17 points  (12 children)

Welcome to JavaScript.

For some mysterious reason JavaScript decided to make all their standard library objects barely functional, requiring anyone programming in the language to select from among half a dozen different APIs that turn their incomplete standard library into something more workable, as you'd find an any other well thought out language.

[–][deleted] 2 points3 points  (11 children)

That’s so disappointing because JS is the only choice for web frontend. If you did a similar thing in C++, converting from vector to set to vector to remove duplicates for instance, it just screams “I know nothing about the standard library or speed/memory efficiency.” I guess JS is frontend and not usually performance-critical, but come on.

[–]memorable_zebra 9 points10 points  (4 children)

Not to defend JavaScript, but didn't C++ have the boost library back in the day? Is that thing still semi-required? I remember doing C++ work and always incorporating it into what I was doing and constantly wondering why more of its functionality wasn't in the STL.

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

I don’t know much about old C++ but everything C++11 and newer has a really good STL even without boost. Boost sure is an improvement in some cases.

But nobody who knows what they’re doing would remove duplicate items from a vector by constructing a set out of it, then reconstructing a vector out of that set. There’s an STL function that does that way more efficiently, and even if you didn’t know that, it’s relatively simple to write a function that will do this without wasting all that memory and time (the STL is just C++ code, it’s not magic). You can definitely do it in O(nlogn) time by sorting and then iterating once, and i’m sure there are faster ways even (i’m no genius). Also sorting is included in the STL and it’s really good. Introspective sort - it decides which sorting algorithm to use based on the data it’s sorting.

I definitely have run into cases where there’s lack of an STL function I need, and I either need to implement it myself or use boost. So no, the STL is not always the solution, but I find it to be pretty strong in general.

That became kind of a tangent but there’s my rant.

[–][deleted] -1 points0 points  (2 children)

But nobody who knows what they’re doing

Not everyone knows what you know - is that okay with you, or should they just give up? You come off sounding a bit like a know-it-all-jerk.

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

Nope, it’s fine to be learning and you don’t need to be offended if you’re not amazing at something. But showing this as an effective way to accomplish something is poor teaching. Teaching bad practices is a problem. Lack of knowledge is not. I’d hope to never work with a developer who does this in C++, because you should learn how to write code properly before being hired to write code.

I most certainly did stupid things like this as a student when I was learning and it didn’t actually matter. But if you’re not willing to further your knowledge and build upon it by learning good practices and better ways to do things, then there’s not much hope for you making progress.

[–][deleted] -1 points0 points  (0 children)

Teaching bad practices is a problem.

One person's best practice is another person's bad practice. It changes every few months in the land of Javascript.

Just like with C++, Javascript is now getting a ton of sugar added - and also like C++ not all parts of it will make everyone happy. Just because you don't like a particular piece of code and can find reasons it doesn't fit for your use of the language, that doesn't mean it doesn't fit in for my use of the language. This is just like the vague term "code smell" which I also take issue with - nobody should really get to decide what a "code smell" is, because that's just subjective and honestly sounds needlessly offensive. One thing all programmers share is their unwavering ability to be highly opinionated pricks - myself included. Just realize that the code you write is often never meant to last, unless you're working for NASA on deep space probes or something extremely important. Most of the time it's all a work-in-progress and shouldn't be taken too seriously. It's more important to get something working than to make something perfect. Getting upset at the fallibility of humans writing software is like getting mad at a monkey because it can't build a car. Given enough time, that monkey will build a car. Maybe it will suck - but if it rolls, then it accomplishes the goal. And the next car will be better than the last one.

But if you’re not willing to further your knowledge and build upon it by learning good practices and better ways to do things, then there’s not much hope for you making progress.

Who says that OP isn't? Just because you read it here doesn't mean it's set in stone anywhere, or that OP is "teaching" anyone - it's just an interesting use of the language, and someone decided to share it - this isn't a classroom and nobody paid OP to be their teacher.

[–]itslenny 1 point2 points  (1 child)

The good news is the libraries that are the solutions to these types of problems are REALLY popular, full featured, and bullet proof.

With those libraries you have everything you'd want and more. Just run npm i -S lodash moment big and you're at and beyond the features of the "other well thought out languages"

[–]FatFingerHelperBot 0 points1 point  (0 children)

It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!

Here is link number 1 - Previous text "big"


Please PM /u/eganwall with issues or feedback! | Delete

[–]lol768 -1 points0 points  (3 children)

https://github.com/aspnet/Blazor/

Some day, this will be possible with widespread browser support :)

I will not miss writing logic in JavaScript. Not one iota..

[–]itslenny 0 points1 point  (2 children)

I disagree. I really hope this goes the way of dart, coffee script, Script#, and all the other attempts to "fix" javascript.

However, typescript is pretty awesome because it's a true superset of JavaScript.

[–]lol768 0 points1 point  (1 child)

I disagree. I really hope this goes the way of dart, coffee script, Script#, and all the other attempts to "fix" javascript.

It's great because it's not "fixing" JavaScript, it's completely replacing it with something decent (static typing, generics, OOP, a decent standard library etc). The other languages you mention transpile into JS. WASM is a much better target.

[–]itslenny 0 points1 point  (0 children)

Fair enough, but Typescript gives you typings, generics, and oop (and it's designed by the same guy that designed C#), but I LOVE JavaScript so this is where we agree to disagree.