views:

225

answers:

8

I am trying to do this, I'm a full time front-end dev and am aware that I am yet to achieve this. When I am referring to OOP skills I am referring to understanding and being familiar with concepts like inheritance, polymorphism, encapsulation, abstraction. I am aware that it may be more likely to achieve what I'm after by focusing on another language in my spare time. This is the plan, but I'd be really intrigued to hear if anybody has managed to achieve this purely through JavaScript and how you did it.

It'd be even better to hear from strong OOP developers from who use different programming languages to know if they have worked with developers who have managed to achieve this.

Feedback:

Just in case people are wondering where I went from this -

  • I've taken a closer look at what prototypal inheritance means and how to use it better.

  • I've decided to spend more time properly learning ruby (could be any language that is class based) in my spare time.

  • I've decided to experiment (nonchalantly) with different languages so that I can gain not the intricacies/exact syntax of them, but more of an overview of how they approach OOP. I've started with Self, Scheme is next on my list.

Thanks a lot for the really helpful answers.

+3  A: 

There's no reason you can't develop strong object-oriented skills via Javascript - but Javascript is a prototype-based object-oriented language, which is quite different from other mainstream object-oriented languages (C++, Java, etc.), which are class-based.

You should familiarize yourself with both models as soon as you can (once you've mastered the basics of javascript), so you can learn from discussions about class-based models without too much friction.

Finally, in case you aren't already familiar with Douglas Crockford, I highly recommend visiting his site, reading his article JavaScript: The World's Most Misunderstood Programming Language, then reading his book Javascript: the Good Parts.

Jeff Sternal
+1  A: 

I mainly develop in C# and JavaScript.

Unfortunately I haven't met somebody who has only developed in JavaScript that has strong OOP skills.

It should definitely be possible though. JavaScript has all of the OO concepts baked in. You just have to learn how to use Prototypal inheritence properly to achieve your goals (or learn through a Framework like MooTools, which kind of defeats the purpose).

Justin Niessner
A: 

If you want to learn OOP, but you want an "easy" scripting language to do it in, you would probably be better off working in ActionScript via Flex.

Robusto
ActionScript is basically a dialect of Javascript (ECMAScript).
Pointy
@Pointy: In some ways, sure, but it has strong data typing, class-based inheritance, polymorphism, etc., etc., etc. The syntax is similar, but not identical. It would teach the OP about OOP concepts in a way that Javascript never could.
Robusto
Yes that's true; it is pretty different in some ways.
Pointy
+1  A: 

Many developers argue that JavaScript has no realy OOP functionality and some say you shouldn't even use the OOP functionality that is included. I also coded a lot in JavaScript objectoriented. But I also coded a lot in PHP and Java with all the OOP techniques around.

Important things that missing in JavaScript are static or final classes as well as interfaces. You use them quite frequently in languages such as Java.

I would say that if you only want to learn what OOP means and how it works in small cases, than JavaScript is enough. To really learn OOP im complete, you need to learn a language like Java, C++, Ruby or even PHP.

Kau-Boy
uh.... well, from what I've seen and used of PHP, I would wait for version 7 before suggesting somebody to learn OOP there.
Marco Mariani
It offers most of the tecniques of a OOP lanuage. If you really want to code pure OOP than even Java isn't your right choice. You probably have to take ruby in that case.
Kau-Boy
@Marco Mariani: PHP has almost everything you need for OOP. The only thing I can think of that it is missing is late static binding, which will come in PHP 6. I've studied Java in school for 6 years, yet I still prefer PHP's OOP.
Lotus Notes
Somebody said it better than me: "This is waxing philosophical, but in my experience, PHP has an uncomfortably low ceiling. Programming isn't just about putting one instruction after another; it's about building abstractions to better represent and solve problems. [...]
Marco Mariani
[...] The more complex the problem, the higher the level of abstraction needed to solve it cleanly. With PHP, I often hit my head on its low ceiling of abstraction, and it seems to require a great deal more effort and discipline (than in other languages) to avoid ducking down into the details of implementation when I should be focusing on the upper-level design." http://toykeeper.net/soapbox/php_problems/
Marco Mariani
Ah a comment from an expert :) Just because you can do things without OOP in PHP it doesn't mean that PHP is not an OOP ready language. In fact it is, no matter how much you argue against it. And as yaya3 told us, he even used OOP a lot within JavaScript what most of the JS developers will never do.
Kau-Boy
A: 

Im myself found "JAVA" as the strongest object oriented program i have encountered, i truly recommend it to develop OOP skills.

Good luck mate :)

WEBProject
-1 javascript not java
James Westgate
A: 

I'm gonna go with "No".

I've worked with several javascript devs, and I could always tell which ones of them where native to JavaScript, and which had a Java/C#/Delphi background

BTW, this is not a dis of javaScript, just an observation.

SWeko
A: 

I suggest you to practice with languages that let you create high level patterns without too much pain... like, why not, Python?

As for Javascript, this post by our Joel is quick to read and goes to the point:

Can Your Programming Language Do This?

Marco Mariani
+9  A: 

First, let me preface this by saying JavaScript is one of my favorite languages. I love using it, and I love its power.

JavaScript certainly does OOP, and once you wrap your head around it, it does OOP reasonably well. But I wouldn't recommend learning OOP via JavaScript for the following reasons:

  • JavaScript uses a kind of bastardization of Prototypal inheritance and Classical inheritance. In JavaScript, you don't define classes like you would in a classical language, but there are still remnants of classical inheritance - like the new keyword. This is extremely confusing for people who have wrapped their head around classical OOP.

  • JavaScript doesn't really have a normal concept of private and public variables like a classical language (like Java) does. Sure, you can define public and private variables, but the methods are kind of esoteric. Because JavaScript doesn't really do public and private variables 'out of the box,' the whole idea of data hiding and encapsulation doesn't naturally apply.

  • JavaScript can certainly do polymorphism, but it doesn't do it through regular function overloading/overriding. Instead, a function or method can take a variable number of arguments that can be added on the fly at runtime. Again, it can do polymorphism, it just doesn't do it like most of the more mainstream and popular languages.

Like I said before, I love JavaScript, and I love working with it. You can certainly do OOP in JavaScript, and you can certainly learn OOP by learning it from JavaScript. But I think that is an uphill battle.

I think you'd be better off learning OOP from Ruby first, then going to JavaScript. Ruby and JavaScript have different syntaxes, but the power and 'feel' of the languages are very similar. You can do similar things with both languages, and both languages have similar features and support similar paradigms.

Hooray Im Helping
+1 This is really informative
Dr. Frankenstein
+1. You *can* get strong OOP skills, despite working in Javascript. :)
Guffa