Is JavaScript's eval really evil?

"eval() is evil."

If you're a Web developer, you've probably heard this, along with other JavaScript commandments like "don't use with()" and "don't use ++ or --". Doug Crockford's list of "bad" JavaScript language elements is pretty long, and they're pretty subjective.

Meanwhile, Crockford had for much of his JavaScript career been a driving force behind what I call the "Javafication of JavaScript". That is, making complex hunks of code in JavaScript to simulate Java idioms and behaviors (like classical inheritance).

While Crockford has since recanted much of that "Javafication", the ripple effects are still with us today. Further, his "bad parts" of JavaScript stem from the same mindset. Basically: JavaScript is somehow "broken" and we must avoid tangling with complexities like when you need curly braces.

An open-minded approach

We should all be aware of the features and complexities of JavaScript. Instead of blindly following word from on high about what we should and shouldn't use:

  • learn the language
  • experiment with the language
  • all of it

Then decide for yourself.

As a side note: no lint utility for any language should be in the business of flagging coding style. jslint loves telling me not to use single line conditionals. I'm a big kid, Doug, I'll code how I want.

Evolving

Every time I find myself spouting some random "truth" about programming I heard or adhere to, I check it. Code against it. Really get to know the truthiness of it before I spout it again.

I know time is hard to come by these days, and it's easier to blindly accept someone else's coding rules. The thing is: following those rules doesn't make you a better programmer, nor does it make your code better. Nothing replaces understanding and experience, so bite the bullet and dig in.

Above all: have fun with coding. Learn the deep capabilities of your language of choice and make up your own mind.

Too heavy? Have some fun with GOTOJS!

Endorse davebalmer on Coderwall submit to reddit
comments powered by Disqus