14

During my years of web development with JavaScript, I come to the conclusion that it's an incredible powerful language, and you can do amazing things with it.

It offers a rich set of features, like:

  • Dynamic typing
  • First-class functions
  • Nested functions
  • Closures
  • Functions as methods
  • Functions as Object constructors
  • Prototype-based
  • Objects-based (almost everything is an object)
  • Regex
  • Array and Object literals

It seems to me that almost everything can be achieved with this kind of language, you can also emulate OO programming, since it provides great freedom and many different coding styles.

With more software-oriented custom functionalities (I/O, FileSystem, Input devices, etc.) I think it will be great to develop applications with.

Though, as far as I know, it's only used in web development or in existing softwares as a scripting language only.

Only recently, maybe thanks to the V8 Engine, it's been used more for other kind of tasks (see node.js for example).

Why until now it's only be relegated only to web development? What is keeping it away from software development?

13
  • 8
    If web development isn't (a special case of) software development, what it exactly is then?... Commented Aug 30, 2011 at 9:05
  • @Péter Török: I think you get the point. What I mean is that until now it's been used only as a scripting language by softwares, to enhance features. It's never been used to actually program a software application for a OS.
    – Jose Faeti
    Commented Aug 30, 2011 at 9:09
  • 4
    I see dynamic typing as a huge drawback, and I also would like to get rid of null values.
    – Jonas
    Commented Aug 30, 2011 at 9:24
  • 2
    You mean "classical application development", not "software development", right? Better change your heading accordingly.
    – Doc Brown
    Commented Aug 30, 2011 at 9:29
  • 2
    @JoseFaeti for the record windows 8 allows you to do some development in HTML5&JS
    – Raynos
    Commented Aug 30, 2011 at 10:01

5 Answers 5

14

Recently node.js has brought server-side development forward. So, it's now possible to write JavaScript, for development.

That's true. In history, it hasn't been used as a development language. But, hey, even scripting in client environment (User Agents) is a type of development. Isn't it?

The main reason that I've heard and read in many weblogs, is that, people didn't know about its power and uniqueness till recent years. What made this happen, was maybe that other languages were doing their job just well enough, and nobody ever thought about making something parallel.

1
  • Must be like that, and I looks like something is actually moving now :)
    – Jose Faeti
    Commented Aug 31, 2011 at 9:45
15

From here:

Note that I am basing all my arguments on real-world use cases. Counter-arguments that can't be backed up with an example of use in a real, complete, interesting, useful applications are invalid. I've seen the little "language demos" everyone else has, I've seen the blog posts detailing how prototypes and dynamic typing make some trivial little example a few lines shorter than it would be in C#, but those simply aren't relevant to the problems you run into writing real code rather than micro-demos and toys. So here's my gripes with JS:

a) Magic 'this'. This is this, except when this is that. JavaScript pushes you to use anonymous functions all over the place, except they always end up losing the proper context for the 'this' variable, so you end up having goofy code like "var _this = this" all over the place and then using that inside your callbacks or other functions. Some days I swear that the number of functions I manage to write that don't use a renamed 'this' are actually smaller than the number that do.

b) 1 + "1" - 1 = 10. Also, "1" + 0 = "10". Yes, this actually has caused bugs for our applications, where data that's expected to be a number was loaded from a JSON file as a string due to a bug in another application, and the result was not good. All our loading code had to be updated to add a ton of type conversions all over the place. When I need something to be a number I really freaking absolutely want it to be a number, not a string or an object or null or anything else. Lua, which is very similar to JavaScript in most respects, fixed this problem by just not being retarded enough to use the same operator for addition and string concatenation.

c) Global by default variables. So even if you take the argument that dynamic typing is just "easier" because you don't have to think about variable declarations, JavaScript throws that argument out the window by making you put 'var' in front of new identifiers all over the place. And then it silently screws you if you forget to.

d) Prototypes instead of classes. There are very few large-scale real-world JavaScript applications in existence that don't plug in their own class system to work around the inherent uselessness of prototypes in large application architecture. Those same apps make minimal use of prototypes to extend the base JavaScript types, and only because JS was so poorly designed that even the two interesting built-in types it comes with are lacking half the features you'd expect them to have.

e) Inability to create pass-by-value types. This is a frequent problem in just about every language aside from C++/D, actually. For those using JavaScript to write WebGL apps, take a look at all the linear algebra libraries for JavaScript. In 3D apps, you almost use vectors more often than you do scalars. Imagine if every integer in your app was passed by reference, so that "a = 1; b = a; b++" made both a and b equal to 2. Every little three component vector is a complete full object. They are passed by reference (the source of almost a half of the bugs in our WebGL game so far, in fact). They exist in great quantity, are heap-allocated, and are garbage-collected, which puts an intense amount of pressure on the GC which can and does result in GC pauses in even simple WebGL games, unless the developer jump through ridiculously complicated hoops to avoid creating new vectors in all the places where it's logical to create new vectors. You can't have operator overloading, so you have very large and ugly expressions to do basic operations. Accessing individual components is slow. The objects aren't natively packed and hence are incredibly slow to push into a vertex buffer, unless you implement them as a Float32Array instances, which confuses the crap out of the optimizers of both V8 and SpiderMonkey currently. Did I mention they're passed by reference?

f) No built-in include or require functionality. Seriously, still. Third-party libraries exist but almost all of them have some kind of bug or another, not least of which is a confusing caching problem in at least Chrome making doing actual development a pain in the butt.

g) Dynamic typing. Yes, I'm willing to start that argument. You start noticing it the most the second you stop writing little Web apps or Web pages and start writing large apps where you actually have data that persists for longer than a single mouse click or request/response cycle: add the wrong kind of object to an array to process later and get a crash later from a missing method or member in a completely different bit of code than where the actual mistake was. Fun times. Yes, Java makes static typing seem evil. No, Java/C#/C++ are not the one and only way to do static typing. Type inference, implicit interface binding, etc. give you all the "easy to deal with and not a lot of keystrokes" advantages of dynamic typing without all the bugs. The second most popular Web language -- ActionScript 3 -- is statically typed, in fact, despite otherwise being identical to JS/ECMAScript. As an aside, I get more crashes from the Python apps on my Fedora desktop than I do from the C/C++ apps (actually, none of the C/C++ apps on my desktop crash, now that I think about it). Missing member exceptions == so much easier to develop and maintain apps, right?

h) Speed. Yes, there has been some ridiculously immense amounts of effort by a large number of super bad-ass developers put into the language runtimes to make JS almost half as fast as a low-grade C compiler that a single college Junior could write in a few months. And LuaJIT is in the same boat as JS in terms of fundamental language limitations but manages to do better than every JavaScript implementation anyway. People who don't understand what all the JS optimizations in V8 or such actually do like to claim the JS can do amazing things speed-wise, but the reality is that all those optimizations are basically just "try very very hard to analyze the code to figure out types for variables and then compile it like a slightly retarded statically-typed language's compiler would do it." Oh, and there's tracing, but then tracing also works on statically typed languages (and works better due to a lack of need for type guards in the generated machine code). Not a single one of those whizbang optimizations was invented by or for JS, in fact; most were taken from research JVMs (Java is evil!) or classical OOP languages (prototypes are awesome!).

i) No IntelliSense even possible. Want to see what methods exist on that variable you've got there on line 187 of foo.js in your text editor? Too bad. Go trace through the code until you figure out where it was initialized, then go trace through the code to find out what its prototype has on it. And then hope there's no code dynamically changing the prototype behind your back. In fact, just run it in a browser and set breakpoints, because finding out anything useful about the value any other way is basically impossible for any codebase larger than the toy_web_app.html sites that JavaScript apologists use to glorify the ease and simplicity of JavaScript. Some code editors try really hard to do better, and almost kinda sorta succeed for the really simple cases, sometimes, once.

j) No advantage. JavaScript isn't even special compared to other dynamically typed language. It is not capable of doing anything interesting at all all that can't also be done by Lua, Python, Ruby, etc. None of the JS implementations are any faster than LuaJIT or PyPy or various other advanced JIT-ing implementations of other dynamic languages. JS has no plus sides to it compared to other commonly available languages. Oh, except it runs natively in a Web browser without a plugin. Which is the only reason in the world why it's so popular. In fact, it's the only reason it event exists. If someone 10 years ago had just thought, "heck, let's drop an existing well-designed and well-established language into our browser and get the other guys to do the same instead of making everyone use this goofy little hackjob that NetScape came up with," the Web would look a lot different (better) today. Just imagine the future if Chrome dropped Python into Chrome as a supported language. Or actually, imagine this: Google drops C/C++ into Chrome as a supported language (http://code.google.com/p/nativeclient/).

3
  • This is a really interesting post. I'd be curious to see his use-cases that form the foundation of his arguments. I'm not disagreeing with his points, but I've been developing corporate-sized JS applications for almost 10 years and haven't experienced some of the things he mentioned (in particular, his first point about "magic this"). Going on my own experience, arguments against javascript like the ones in this post tend to made by people with heavy traditional oop backgrounds...in which case, I would understand his confusion. Commented Mar 30, 2012 at 15:41
  • It's quite interesting to see that in 2016, the answer is now entirely obsolete by the evolution of the language. Commented Jun 12, 2016 at 15:39
  • @Mr. JavaScript ​Hi. Do you know of a series of tutorials that concentrate on solving examples of real-world problems rather than just exploring JavaScript and its features and mechanisms? I am not having any luck with keyword searches. For example, instead of going through such a detailed tutorial link and its millions of examples and features, where do I find a repository of small tutorials on how to make a GUI application to manage some insurance system or doctors or school or an operational part of a supermarket? Thank you
    – Mary Jane
    Commented Jul 8, 2016 at 19:37
12

Why?

JavaScript the most misunderstood language

We were in the dark ages and still are for the general development community to accept that JavaScript is a powerful and versatile language. It's simply not mainstream.

The only recent advance is that node.js has become buzz-wordy and people are starting to accept that javascript has other uses..

I've been keeping an eye on the JS & HTML5 development for windows 8 and the reaction from the .NET community was "dear god why?".

It's simply fact that most non-web developers still see JavaScript as that toy language you use to make those scroll over menus in your browsers.

Admittedly JavaScript doesn't align with "modern development practices". For me JavaScript is still a hacking language I crack out with vim & the internet is my documentation. There is no IDE, there are no development tools, there is no auto-complete or "intellisense", there are no click and drag GUIs.

In the world of Java and .NET developers they are wedded to their GUIs & IDEs and would not be able to program in vim.

23
  • 1
    I agree with you except "There is no IDE, there are no development tools, there is no auto-complete or "intellisense", there are no click and drag GUIs." Actually you can get all that using many various IDE out there, I use Visual Studio for example and it's simply great.
    – Jose Faeti
    Commented Aug 30, 2011 at 9:28
  • 1
    @JoseFaeti sorry, Visual Studio is not a javascript IDE. I'm faster in vim then in VS2010. This means VS2010 is a leaky JS IDE.
    – Raynos
    Commented Aug 30, 2011 at 9:33
  • 2
    @Raynos, "I'm faster in vim then in VS2010. This means VS2010 is a leaky JS IDE." - or maybe this simply means that you don't know VS as well as vim. Commented Aug 30, 2011 at 9:44
  • 2
    Absolutely not, but Im not going to build a RIA frontend in Silverlight because I love Resharper and LINQ, or ASP.Net MVC app with a thin jQuery layer, because again its .Net friendly, when there are rich client side Javascript languages at hand that are better suited for the job.
    – sa93
    Commented Aug 30, 2011 at 9:45
  • 1
    Just adding my voice to the chorus of people stating that there are JavaScript IDEs. It's frankly silly to claim otherwise. You might not like the IDEs and they may not be perfect, but they're still IDEs. Or have I been imagining the intellisense and code completion of VS when working with JS?
    – Ian Newson
    Commented Jun 26, 2015 at 14:07
10

Your list does not contain anything about writing files to the system, which is a massive part of software development.

People would not think of using JS to build an application because it the de facto scripting language for web, and you would always use the right tool for the job.

Why write acres of JS to write out a file when it is a trivial operation in Java/.NET/C/C++?

With that said, as others have mentioned, node.js and its libraries have made server side operations trivial and with node.js becoming popular, learning it will become a skill for a CV, since you will be able to maintain/extend/build applications with it.

8
  • 1
    +1 completely forgot how a stdio library is kind of important.
    – Raynos
    Commented Aug 30, 2011 at 9:35
  • 1
    For filesystem as you put it we do have local storage APIs now, although you wouldnt count on them for serious durability. However writing to a filesystem need not be direct, your javascript could be making restful calls to a server that (written in LOLCode or C or JS itselfs) that writes to some form of storage.
    – sa93
    Commented Aug 30, 2011 at 9:36
  • 1
    On the server side. NodeJS file API is just a trivial as C etc... <-- if your doing IO correctly in C (non blocking). Also an Ajax call with any sane wrapper can be 2-3 lines. MyLib.Ajax.post('/persistence/Something', { data: blahObj })
    – sa93
    Commented Aug 30, 2011 at 9:37
  • @sa93 please don't confuse the browser host environments with JavaScript. localStorage is a host API in browsers. It's not defined in the ES5 specification.
    – Raynos
    Commented Aug 30, 2011 at 9:38
  • 1
    @reinierpost Writing files to the file system has been replaced with HTTP POST. Not if you're writing the APIs that are handling the posts.
    – StuperUser
    Commented Jun 26, 2015 at 10:11
5

Most languages in common use are more powerful and better designed than JavaScript. All the features you mention are supported by other dynamic languages like Python or Ruby which are overall better designed. And some of the features you mention are not necessarily desirable anyway - many would consider static typing with type inference preferable to dynamic typing, if you have the choice.

I'm not saying this to diss JavaScript. I quite enjoy working with JS when developing web. But looking at it objectively, JS has a number of drawbacks compared to other languages:

  • Numerous unfixable flaws. Many mistakes were made when initially developing JS. No need to enumerate them here, they are well documented. All languages have mistakes in the initial design which are later fixed. The difference with JS is that the language was developed and released far to quickly and these mistakes can never be fixed due to the requirement of backwards compatibility in browsers.
  • Extremely slow process for introducing improvements and new features. Since all browser vendors have to agree and might even for various political reasons want to slow down the development of the language. Look at C# which is actually a newer language than JS. When C# was introduced it didn't have eg. closures or higher order functions like JS, but after multiple iterations it now has all that and furthermore features like Linq and async syntax which JavaScript developers can only envy.
  • Impoverished standard library. Modern languages like Python, Ruby or anything based on Java or .net have extensive standard libraries for almost anything you could need. In JS you can't even read a file without 3rd party libraries. You mention Regex, but all modern languages have that and a thousand things more.
  • Other languages have caught up with the few JavaScript advantages. Features like closures and first-class functions were powerful when compared to clunky static languages like Java ten years ago, but dynamic and functional languages have long have had these features, and even Java, a pretty conservative language, has added this in Java 8.

The only feature which really sets JavaScript apart from other modern languages is prototype-based inheritance (as opposed to class-based), and the advantage of this model is dubious since everyone just use it to emulate class based inheritance anyway.

There is simply no reason to choose JavaScript if you have the option of choosing another modern language. Only reason would be if it was the only language you know.

Not the answer you're looking for? Browse other questions tagged or ask your own question.