Is JavaScript easy to pickup as an OOP programmer?
Posted by Fit-Try9217@reddit | learnprogramming | View on Reddit | 19 comments
Hi!
I'm a fourth year uni student tryna move away from a lot of the Java and C++ work which I've done countless of times throughout my uni projects. Mostly things such as applications that interact with a database, graphic engines, game engines from scratch etc.
I'm looking at learning full stack development to expand my skills. With full-stack, JavaScript is an inevitability...question is, is it easy to pick-up if you already know OOP concepts and all the other things that come with OOP languages? All the guides I've seen for learning JavaScript seem to be "Loops, Conditionals, Functions" etc etc. And I'm unsure if I should just dive into the actual new stuff and learn the syntax along the way?
huuaaang@reddit
I found JS to be confusing to learn coming from OOP because the prototype system is not really OOP. It's a very crude system, IMO.
I suggest jumping right to typescript and just skip vanilla JS completely.
jessepence@reddit
I totally get why you would say that, and I'm not going to pretend that JavaScript has the best approach to object orientation. However, I do feel the need to defend Prototypal Inheritance to some degree. To quote Douglas Crockford from his article "Classical Inheritance in JavaScript", "JavaScript's prototypal inheritance has more expressive power than classical inheritance". As he shows in that article (and later got baked into the language), you can build Classical Inheritance with Prototypal, but you can't do the same in the other direction. He wrote another article that does a pretty good job of explaining the thinking behind Prototypal Inheritance.
And then, here's the MDN docs if OP needs any further reading.
MoTTs_@reddit
On the contrary, it's actually extremely easy and I did it.
jessepence@reddit
Cool link! I don't have enough time to dig in right now, but I look forward to checking it out. 🙂
Kadabrium@reddit
I feel if the goal is "find a way do OOP when you don't have types" then js's solution is the one that logically arises
huuaaang@reddit
But all that flexibility is part of what makes it confusing to learn. It's not just because "it's different." What you end up with is developers who use the prototypal system differently. That's why I suggest goign right to Typescript which is more opinionated about how the prototypal system is used by default, making code bases more consistent. That and all the other benefits TS brings on top of JS. I see little reason to write plain JS these days.
jessepence@reddit
Yeah, sometimes I think that adding the
classkeyword in ES6 was a mistake because it just added another way to do the same thing and it glosses over the differences between the inheritance systems so sometimes newbies are confused about how things actually work.jessepence@reddit
Yeah, sometimes I think that adding the
classkeyword in ES6 was a mistake because it just added another way to do the same thing and it glosses over the differences between the inheritance systems so sometimes newbies are confused about how things actually work.MoTTs_@reddit
The prototype system is actually an extremely common way to implement OOP. Python, Ruby, Perl, Obj-C, Lua, Smalltalk, and more, for example, all have OOP features that work the same way as in JavaScript.
In Python, for example, a lot of JavaScript folks are surprised to find out that Python's "classical" inheritance and JavaScript's "prototypal" inheritance are actually the same thing and work in the same way. Python classes are not blueprints, Python classes are objects. They are runtime, mutable, assignable, objects. Instance objects have a runtime link to its class object, and class objects have a runtime link to any parent class objects, forming a runtime chain of objects.
When you invoke a method, then at runtime Python will look inside the instance object for the method's name, and if it's not there, then Python follows the runtime link and looks inside the class object for the method, and if it's not there, then Python follows the runtime link and looks inside any parent class objects, and on and on. Here, for example, is JavaScript and Python classes side-by-side, showcasing the same runtime mutable behavior and abilities.
The JavaScript community believed for a long time that their inheritance behavior was unique, but as it turns out the prototype style of inheritance was already around and even commonplace long before JavaScript was invented.
Frolo_NA@reddit
you don't have to interact with prototypes at all in modern JS. its had classes now for 10 years or so
huuaaang@reddit
Still, just use Typescript.
NumberInfinite2068@reddit
JavaScript is hot garbage, but really, does it matter if it's easy? Are you going to skip it if it's hard?
I don't get the "easy/hard" questions here, will it change your learning path to know if it's easy or hard? I don't think it will.
Arianethecat@reddit
If you already survived Java and C++ the syntax part of JavaScript is the easy bit. The weirdness comes from how flexible JS is and how many different ways people structure things. I’d jump into TypeScript early instead of treating vanilla JS like a rite of passage
Misaka_Undefined@reddit
No it's not easy
iOSCaleb@reddit
As opposed to what? Not learning the syntax? Not learning the new stuff, whatever that is?
Pick up a book on Javascript and work your way through it. Some parts will be easy because you've seen C-like syntax before and it's largely the same. Some parts will be annoying because there are weird quirks, like the difference between `==` and `===`. Some parts might be hard because you're used to strongly typed languages, and Javascript is not one of those. But any way you slice it, you need to learn most of it; working through a book is likely to provide the fastest, most coherent path to getting up to speed.
KaelonR@reddit
JavaScript should be easy enough to learn, but to ne clear, JS is NOT an OOP language. It's a prototypical language, and the core concept of the language is prototypes. Prototypes are a fundamentally different concept from classes.
Modern Javascript has class syntax nowadays, but that's just syntax sugar and at the end of the day you're still working with prototypes at runtime.
CptPicard@reddit
It definitely is an OOP language. It does not have static types, it has prototypal inheritance. But objects are definitely there as first class things that group data and functions.
high_throughput@reddit
Yes, it will be very familiar.
grantrules@reddit
Yeah, it's pretty easy