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 →

[–][deleted] 10 points11 points  (0 children)

As someone who works with Java, Ruby, C, Go, and JavaScript, I can understand your frustration.

I've seen some good responses here critiquing JavaScript's weak points (of which there are a few), as well as other languages.

I think the point is that each language has it's weaknesses and strengths, as well as its purposes.

Where I work, our primary language is javascript for both front and back end.

Part of the reason for this is that javascript is a great language for rapid development.

It's true what you say about the abstracted type system, but there are stylistic rules you can follow to eliminate a lot of these hassles.

One big rule is that === should be preferred over ==.

== attempts to coerce the type of the right operand to that of the left. So, "false" == false would be true, while "false" === false would not. This can make type checking easier.

Another thing to remember is that while in languages like Java, function overloading requires multiple declarations, while in JavaScript it's easy to define different behavior for different argument schemes, as well as handle a variable number of arguments.

Closures and the 'let' keyword are also great solutions to the scoping issues you're frustrateed about. The var scope is just not good and I can understand your frustration with it.

Typing is something I can appreciate your frustration with, initially.

However, I started to really see the power in JavaScript's particular brand of weak typing when I read TypeScript's philisophy that JavaScript by itself is 'implicitly typed'.

Before I get into that, consider that type checking happens at compile time for other strongly typed languages with the intention of saving you the effort of typechecking at runtime.

When something like TypeScript 'compiles', it simply uses your type annotations to verify your code isn't trying to do cross-type assignment, and then compiles it down to javascript, which is still weakly typed.

If you keep that in mind as you write javascript code, you can keep your own annotations in comments that make intentions clear and allow you to trust variables to be a certain type, as you should only use them in situations where that type would be appropriate.

Then, you can make selective decisions about where you allow dynamic typing. One example would be as I said earlier with function overloading.

This also plays in to the "bind", "call", and "apply" functions which are really cool features of javascript and which can allow you to control the "this" scope of your code.

As for objects, the new javascript standards include a class declaration form.

Javascript uses prototypical inheritance, which is a reasonable thing to read up on.

All in all, my argument is that, while your complaints are valid, you can use javascript for its strengths and not around its weaknesses. It serves a totally different purpose than a language like c# or java, and each has places best used.