Link Details

Link 363503 thumbnail
User 393532 avatar

By MikeMore
via net.tutsplus.com
Published: Feb 13 2010 / 10:05

JavaScript, if only by default, is one of the most popular programming languages available. Over the years, it's been labeled as a nightmare to work with, and, to some extent, this is true!
  • 30
  • 1
  • 7247
  • 1

Comments

Add your comment
User 388907 avatar

MCII replied ago:

0 votes Vote down Vote up Reply

There are more important things JavaScript got wrong.

User 72237 avatar

tb74341 replied ago:

0 votes Vote down Vote up Reply

... for example...? (no sarcasm here)

User 388907 avatar

MCII replied ago:

2 votes Vote down Vote up Reply

The weird (often 'doubled') syntax in general: 'normal' function definitions vs. function literals, creating objects with or without new(), 'global' prototypes, ...

User 374039 avatar

tofarr replied ago:

0 votes Vote down Vote up Reply

Another thing javascript got wrong is using reference counting for memory management - for simple scripts this is not noticable but for advanced ajax applications this can add up to big memory leaks

User 275943 avatar

OIS replied ago:

0 votes Vote down Vote up Reply

1,2,10 are minor. 3,4 is wrong. 5 is not the fault of javascript. 6,8,9. This is the same in some/many other languages.

I dont really understand what he means by point 7. That someone use & instead of && and it works anyway? I dont use that in my code, so doesnt bother me.

User 200691 avatar

lem z replied ago:

0 votes Vote down Vote up Reply

it's always amusing to watch people display their lack of understanding on a particular subject, especially when they are do it for the sake of sensationalism... are we entering into the phase where we are parroting CNN?

the author is clearly unfamiliar with scoping, how methods are passed, nor even with basic syntax of return() statement or even with how computers do math... very sad display.

it would be nice if the author at least bothered to google his points before assembling the article. what's even more disconcerting is the number of people nodding to this.

User 374039 avatar

tofarr replied ago:

0 votes Vote down Vote up Reply

As someone who codes a lot of javascript, I would say that I agree with some of the points the author makes. Point 6 (Scope inconsistencies) may be "the same as other languages", but that does not mean it is right. In cases where I have a class with private and public variables and functions, avoiding issues this causes typically involves making a defensive copy of 'this' (calling it '_this' for example) and using it in every function belonging to a class as a substitute for 'this') Otherwise when you pass a pointer to a function (for example as a callback to a mouse event), you can run into strange issues. This is a hack, and it means that you also have to explicitly deallocate the '_this' pointer when finished with an item to avoid memory leaks. The only alternative I know to this is to never pass functions directly but wrap them in a proxy function (instead of "element.onclick = foo.bar" we have element.onclick = function(){ foo.bar(); }) which is more verbose (and people forget to do it), and results in superfluous scopes and objects being created.) - If anybody has a better workaround for this I would genuinely love to know it.

I disagree fully with point 8 - being able to simply put "if(myVar){ /*DO SOMETHING*/ }" is very handy - it means I dont need explicit null checks like in java - in these cases I usually don't care if the item is null, empty, 0 or undefined (If I did, then I would put "if(myVar == 0)"). I view this as a useful feature, not a mistake.

I also disagree with point 9 - this is simply the way computers do math, and alternatives would be either impossible or more confusing.

Further additions I would add to the list are that the language should support a final keyword (resulting in clearer code) or that the watch/unwatch functionality for pointers should have been in the original spec. (So that we could rely on having it in all browsers.)

Now I'm finished ranting, I better get back to work...

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java