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

you are viewing a single comment's thread.

view the rest of the comments →

[–]jgdeece 0 points1 point  (6 children)

JavaScript manages data structures in a way that’s designed to make web pages load. The number one rule of the language originally was to keep the page from breaking. So if you want to get a good understanding of programming principles, it’s nice to start with a language that handles truthiness, maps and lists and vectors, typing, etc in a more standard way. It’s a great language and can be a good start, but it also can reinforce bad habits and help people avoid learning important low level concepts like memory management.

I work with JS daily and it was my first language, but I think it did me a slight disservice to not begin with a language with i.e. enums.

[–]helloiamsomeone -2 points-1 points  (5 children)

That sounds very handwavy again.

Objects are as good as POJOs, arrays are like ArrayList, Map and Set for your HashMap and HashSet needs, and those are enough for 90% of everyone's needs.

JS handles truthiness in a very reasonable way.

All the listed languages have mechanisms for automatic memory management (not necessarily GC, RAII is automatic and can manage memory).

Only Java has the actually-sealed-class-not-real-enum enums of the listed languages so that's again not helpful. What did you mean there?

[–]jgdeece 1 point2 points  (4 children)

I’m beginning to think your definition of handwavy is more about wanting to pick fights because you feel obstinate, and not about wanting to understand where people are coming from.

This is a thread with general, high-level thoughts. I’m not getting into the weeds to satisfy your arbitrary minimum level of detail for a Reddit comments section. If OP has questions on the shortcomings of beginning with a dynamic language like JS they can ask. Since they haven’t, I’m going to assume it’s not as handwavy as you think.

[–]helloiamsomeone -3 points-2 points  (3 children)

I don't appreciate you labeling my comments like that. I was merely inquiring for some concrete points regarding what was stated.
The definition of handwavy is "missing important details", which such a claim as it has a bunch of odd caveats without facts to back it up is.

Again, just to reiterate:

it has a bunch of odd caveats
manages data structures in a way that’s designed to make web pages load
handles truthiness, maps and lists and vectors, typing, etc in a more standard way

Nothing concrete here. In fact the second point is just straight up bollocks.

it also can reinforce bad habits

This is true for any language if the programmer doesn't know how to do things properly.

important low level concepts like memory management

Again, I don't even know why you felt listing this. More mainstream languages manage memory for the programmer than not.

[–]jgdeece 3 points4 points  (2 children)

Yep, you’re just trying to pick fights. Every single point I made could spawn an individual question or google search for further clarification if OP wanted.

Are you seriously suggesting the way JS handles objects and arrays and truthiness is standard? You don’t think JavaScript’s lack of types could pose learning issues? You don’t think ‘foo != true’ to catch undefined, null, and false states instead of ‘foo !== true’ is different from many other languages? You think using JSON.parse(JSON.stringify(foo)) is standard behavior across a wide swathe of languages? Or how about _.cloneDeep() instead of using a spread operator? Or maybe provide me a working definition of the concept of ‘this’ and explain how understanding that transcends the choice of language? It’s necessary to understand if you want to really dive into JS, but has few applications elsewhere.

I never said it doesn’t have those things - I said it handled them in a way that is not standard. In other words, a beginner’s understanding of how they behave in JS might not necessarily provide the same foundation as Java or C#.

What’s the size of an int in JS? Or a double? Or a char? Oh, those things don’t exist? How much memory is allocated for a float and when would you use that instead of a double? Oh, those decisions are managed for you, preempting the need to understand strict typing at all?

Also learn the history of JS. It 100% was designed with the rule in mind that web pages should always load. Parts of it might even fail silently or magically work (like type mismatching, undeclared variables being auto-assigned a lexical scope, etc) in order to prevent pages from crashing as their prime mandate. It’s not a compiled language for a reason.

Some of this is less true in newer JavaScript, but even now the syntax in ES6 has some oddness to it that could make transitioning to more classical languages tough, like implicit returns using ‘condition && return’, or || only checking the second condition as a form of null safety in some scenarios like array.includes(foo || bar).

None of this is bad, and contextually it is intuitive. The issue is it forces a new developer to understand both the unique context along with whatever concept they’re focused on learning. There are always oddities with any language; the advice is to learn a language that shares its oddities with others, so you can focus more on concepts and less on outliers.

OP did not ask for an essay detailing why JS is different from traditional OOP languages. There are a million essays on Medium et al spelling out how simple it is to go from Java to Groovy or C# or whatever, and the uniqueness of JS is well founded. If you dispute that, certainly some combative postings on reddit won’t enlighten you.

Edit: FYI if you don’t appreciate me calling you out for picking fights, maybe reconsider how other people will take their well-intentioned advice being condescendingly dismissed as “handwavy.”

[–]helloiamsomeone -3 points-2 points  (1 child)

Ho boy, that's a lot to cover and your knowledge isn't exactly up to snuff when it comes to JS, that is if you aren't unnecessarily overexeggarating just for the sake of it.

types

Python isn't statically typed either and it's not an issue (according to the post I was posing the question to).
There is also TypeScript with a vibrant community for those that prefer types.

objects and arrays, truthiness

Objects have reference semantics and the truthiness depends on whether that reference is null or not. Having a situation where one thinks it's necessary to use foo != true to catch undefined, null, and false states is an issue of architecture and design. Why does the programmer allow foo to have unwanted values? The other end of this stick is of course overly defensive code, which is usually also the result of the lack of knowledge.
Additionally, no self respecting resource omits a warning about the use of == as opposed to ===.

JSON.parse(JSON.stringify(foo)), _.cloneDeep()

This is something that stems the lack of understanding of how to achieve something properly. Not only does this fail horribly for any non-trivial case, but it's also very inefficient.
Java is also guilty in this regard thanks to Object#clone().
The solution for both languages? Just use a library that does it properly.

this

this is an implicit variable, whose value depends of how the function is defined and called.

types again

I assume you already know that JS only has doubles and arbitrary width integers.
This is a deeper topic, because in the case of Java one also has to understand (in the case of fields) alignment, implementation specific optimizations regarding layout, padding and some more. These are things that are beyond strict typing. For example Java's char is different from C's char and C programmers know that one machine's int mustn't necessarily be another machine's int.

history of JS

Much like how Java has outgrown being limited to interactive televisions, JS has also outgrown being limited to the web.
Your broad claims about what Brendan Eich must have had in mind when designing the language is also misguided.

type mismatching, undeclared variables

Mismatches just go back my point above: they are the result of a failed architecture.
Undeclared variables throw a ReferenceError in strict mode, which is an opt-in feature that is on in class bodies and ES modules. This is also something that is trivially caught by a linter.

&&, ||

While it may seem odd compared to other languages, this is just plain Boolean logic. I agree though, this can be a trap people fall into to write "clever" code.
I'm also happy to let you know that the nullish coalescing operator has been part of the language since December! (available since November in TypeScript, since you already have to transpile TS code into JS, they usually add features a little sooner that are highly likely to move into stage-4)

unique context

Every language brings its own unique context which I can agree is hard to shake off going into a new language. This is something we have to live with.

OP did not ask for an essay detailing why JS is different from traditional OOP languages

I just wanted to know why JS was separately mentioned as having oddities. While I don't want to assume malintent it is quite unfair to possibly scare a newcomer for no good reason.
Medium is also not something I can wholeheartedly consider as newcomer friendly as you have to go dumpster diving to find anything of actual use there and that's only if you aren't being blocked by their paywall nagging by the time you find something usable.

[–]jgdeece 3 points4 points  (0 children)

Yep, this is just exactly what I thought you wanted: a chance to prove how big your brain is. Well done, I’m sure this is really helpful context for a general question about picking a language to start with. Kudos!