2

I am primarily a Java programmer. Because of its OO principles and the general paradigm of Java programming, like wrapping things in static variables, and having things return specific types, heavily aids me in "visualizing" a program. Instead of thinking of a big program, I can, instead, focus on smaller organized parts of my eventual program, and add functionality and build up from there.

Thus, I have trouble programming in other languages. Or at least, I have not been able to program in the same ability as I do in Java compared to other languages.

I know Javascript has OO principles, so I'd like to learn this language in a OO-based like I would program with Java. Is this possible?

6
  • 3
    Some concepts carry over, but in general it is counterproductive and confusing to try to program one language in another.
    – user40980
    CommentedOct 25, 2013 at 20:41
  • Java is class OO, JS is prototype OO, it just spawns off objects and you add attributes and objects inherit from other objectsCommentedOct 25, 2013 at 20:44
  • Sorry - I am still a bit confused. Do programmers generally conceptualize in different programming paradigms?CommentedOct 25, 2013 at 20:50
  • 5
    Its best to program Javascript like javascript, otherwise you'll be constantly fighting against the grain. If you want something more OOP-y in the Java sense, you might look at TypeScript which is a more tradional OOP language that compiles to javascript.CommentedOct 25, 2013 at 20:55
  • Do programmers conceptualize in different paradigms? Yes. Designing software or writing code in one language the same way as another rather than the way that language wants to be done yields poor results.CommentedOct 25, 2013 at 21:13

1 Answer 1

8

They are nearly opposites in terms of how they are arranged:

Javascript is a dynamic, weakly typed language that can be used in a functional manner fairly easily. It helps to think of everything in Javascript as being an Object, even the functions (since they technically are, kinda).

Objects are effectively dictionaries of variables (which in turn can be other objects) and functions (methods). These can be added on the fly, much as you could add a new key and value to a HashMap in Java. You can even change existing methods on the fly.

A prototype is effectively a property that is attached to an object (dictionary) that says "These are the things that you should already have initialized when you are created" and then has a list of those variables and methods that it has and that the new object will be created with. You can then add additional properties to that new object and further extend it down the line.

The weak typing will probably cause the most problems, just remember that when in doubt, use === rather than ==.

In a more general sense, you generally want to adopt the idioms and quirks of a new language as your own. Programming language X in language Y is usually a recipe for disaster down the road. Additional general points are effectively covered by this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.