Why I Chose Javascript Part 2

In part 1 I discussed why I found HTML/CSS so easy to work with. In this article I’ll look at javascript.

Code verbosity

If there was any one thing that stands out as the dividing line between javascript and my previous experience with java it is all the extra typing.

Boilerplate

Compared to

I remember that it took months before I was able to start writing a program without having to check back for a refresher on how to start a program in Java. Javascript was just much simpler to get something up and running.

Imports

Similarly import statements were completely mystifying.

Sure the more general import helped, but only if you knew how that worked. Combine that with the fact that that both of the below are necessary because awt.event is a completely separate package from awt. All of this is a sure way to make a beginner give up.

Initializing Objects

I think this is pretty self-explanatory.

Extra typing comes at a cost

You might point out that its just a little extra typing. But part of the problem is the added complexity, especially for someone starting out. Understanding why you need public static void main is a problem and if you are taking a course they just tell you to accept it and move on. The same is true of objects not only did it feel incredibly redundant to type out <String> twice. I had no clue what most of the syntax was doing which made it even harder to remember it accurately.

I’m not saying that javascript doesn’t at times feel awkward or redundant, but as a whole it was easier to type the code. Which also meant that when there was an error it was less likely to be in some part of boilerplate that I mistyped because I didn’t know what it was in the first place.

Types

This is more of a general point on the difference between compiled versus scripting languages. In javascript except for 6 distinct primitives everything is an object. Java for instance has 10 types of numbers. Which is great if you are writing something that depends on the performance and memory difference between using a byte and int, but many applications don’t need the that level of optimization.

I don’t want to repeat the hundreds of articles out there arguing for or against static types. But I know personally var was easier to code with because again less complexity made it easier for me to focus on the problem I was trying to solve.

Some final thoughts

Ironically I didn’t really understand objects and OOP until after I started using prototypal inheritance in javascript. One day when working with javascript object it just clicked how OOP was supposed to work. In Java I tended to get so bogged down in syntax that it I never quite got a good grasp of what the whole point was.

Another pain point was when trying to work with regex and strings. Java’s implementation is  more complicated. I wrote a program centering around string manipulation in both javascript and java. Java’s was limited and error prone whereas the one written in javascript was easier to develop and much more stable.

One key thing is the accessibility of developing in the browser. I found it so easy to get up and running. Related to that is the amount of information on the web. Not everything on the web is of the same quality, but there were tutorials, code examples, and articles in abundance. Which is great because almost any problem you run into someone has written something about it.

Finally I’m not saying that Java has no place. What I am saying is especially for someone new to programming javascript presents a lot fewer barriers to entry. Add to this the fact that the power behind languages like Java and C++ is overkill for many programs being written today. Personally despite its quirks I have come to enjoy programming in javascript. I’m not sure I ever was going to be able to say that about Java.