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?

yannis
  • 39,547
  • 40
  • 183
  • 216
Jose Faeti
  • 2,815
  • 2
  • 23
  • 30
  • 8
    If web development isn't (a special case of) software development, what it exactly is then?... – Péter Török Aug 30 '11 at 09: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 Aug 30 '11 at 09:09
  • 4
    I see dynamic typing as a huge drawback, and I also would like to get rid of null values. – Jonas Aug 30 '11 at 09:24
  • 2
    You mean "classical application development", not "software development", right? Better change your heading accordingly. – Doc Brown Aug 30 '11 at 09:29
  • @Doc Brown: thanks, I think I need to clarify more. – Jose Faeti Aug 30 '11 at 09:31
  • What is "classical application development"? Do you mean console applications? servers? GUI applications? or what? – Jonas Aug 30 '11 at 09:49
  • @Jonas: Compiled software for your favorite OS for example. – Jose Faeti Aug 30 '11 at 09:52
  • 2
    @JoseFaeti for the record windows 8 allows you to do some development in HTML5&JS – Raynos Aug 30 '11 at 10:01
  • @Raynos: Missed that entirely. I just quickly googled and found something "Windows 8 will run traditional Windows applications as well, but the company will encourage developers to adopt this new approach to application development that depends on the new wave of web technologies." That looks quite promising :) – Jose Faeti Aug 30 '11 at 10:04
  • @sa93 there is nothing wrong with hand written RIA. I have to say the use of jQuery can even be justified. It's just hard to do. – Raynos Aug 30 '11 at 10:33
  • @Raynos. jQuery is not suited to RIA and why would you if its 'hard' to do when they are plenty of RIA frameworks for JS out there. Ive seen some terrible examples. Think people trying to serialize lambdas to jquery validation functions via deciphering the expression tree etc... Anyway I removed my comment before you replied as I feel my anti-.Net dev rants coming on... – sa93 Aug 30 '11 at 10:35
  • @sa93 come join us in [JavaScript Chat](http://chat.stackoverflow.com/rooms/17/javascript) and recommend some RIA libraries. I personally havn't found anything good out there. – Raynos Aug 30 '11 at 10:42
  • The truth is because JavaScript is a pretty bad language by most metrics and people who don't have to use it (or didn't learn it as their first language), prefer not to. There's no real reason to restrict yourself to JS outside of the browser, where you could just as easily use a more thought-out language. This current trend is actually driven mostly by people who don't want to learn anything new rather than some conceptual innovation in bringing JS out of the browser. – idoby Jun 26 '15 at 12:28

5 Answers5

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/).

17 of 26
  • 4,818
  • 1
  • 21
  • 25
  • 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. – Mr. JavaScript Mar 30 '12 at 15:41
  • It's quite interesting to see that in 2016, the answer is now entirely obsolete by the evolution of the language. – Stephan Bijzitter Jun 12 '16 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript) 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 Jul 08 '16 at 19:37
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.

Saeed Neamati
  • 18,142
  • 23
  • 87
  • 125
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.

Raynos
  • 8,562
  • 33
  • 47
  • 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 Aug 30 '11 at 09: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 Aug 30 '11 at 09:33
  • "It's simply fact that most developers still see JavaScript. " I love people who use the term "simply fact", most developers changed that perception 2-3 years ago - although i have a classification of a developer that might not align with yours. Ive seen this in the .Net space a lot, problem with .Net developers are that unless its supported by a fancy IDE with Resharper style kungfu they dont like it, where as a more rounded "developer" will happily work with the best tools, framework, languages for the tasks at hand. – sa93 Aug 30 '11 at 09:41
  • @sa93 Whatever development platform your using for your servers & native applications (whether it's C/C++/C#/Java/Ruby/Python) would you throw it away and write _it all_ in JavaScript? Those of us in the web appreciate javascript is a powerful language, those outside the web treat it as a toy. – Raynos Aug 30 '11 at 09:43
  • @Raynos: you can be faster with other IDEs, but Visual Web Developer 2010 offers all the aforementioned common IDE features. – Jose Faeti Aug 30 '11 at 09:43
  • 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. – Péter Török Aug 30 '11 at 09: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 Aug 30 '11 at 09:45
  • @PeterTorok [VS is simply a broken IDE for javascript](http://lists.wikimedia.org/pipermail/wikitech-l/2011-May/053271.html). There are no JS IDEs. I know. – Raynos Aug 30 '11 at 09:46
  • @sa93 go read the question again, you just answered it. "Why don't we use JavaScript for desktop applications" – Raynos Aug 30 '11 at 09:48
  • IntelliJ IDEA provides a rich Javascript IDE – sylvanaar Aug 30 '11 at 17:38
  • @sylvanaar it provides a JavaScript IDE, it is arguable feature rich but it's buggy and get's in the way – Raynos Aug 30 '11 at 18:30
  • +1 to Raynos for referencing [the Douglas Crockford article](http://javascript.crockford.com/javascript.html). Until recently, decent compilers were not available for JavaScript and that held back its application to desktop and server systems. That obstacle is somewhat behind us, with [Jurassic](http://jurassic.codeplex.com/), [Rhino](https://developer.mozilla.org/en/Rhino_JavaScript_Compiler) and the like now available, although [we still seem to be lacking native code compilers](http://stackoverflow.com/questions/1118138/is-there-a-native-machine-code-compiler-for-javascript). – John Tobler Aug 31 '11 at 17:13
  • @JohnTobler you forgot to mention V8. – Raynos Aug 31 '11 at 17:24
  • @Raynos: That was included in my "... and the like ..." ;) [V8](http://code.google.com/p/v8/) is not a native compiler; it has it's own VM and runtime environment. Still, it is technically a compiler. – John Tobler Aug 31 '11 at 19:51
  • @raynos said:"There is no IDE, there are no development tools, there is no auto-complete or "intellisense", there are no click and drag GUIs." to which I would reply http://www.servoy.com – Alan B Mar 02 '12 at 15:37
  • @AlanB said: "servoy.com" to which I would reply LOL – Raynos Mar 02 '12 at 16:26
  • LOL away, doesn't change the fact that you were wrong when you said there were no JS IDEs with drag and drop GUI design, code-completion, etc. – Alan B Mar 03 '12 at 17:36
  • @AlanB apologies, I'll download [servoy developer](http://www.servoy.com/content.jsp?t=427&mt=393) althought I highly doubt it's better then WebStorm 4.0 (which isn't a proper IDE). – Raynos Mar 03 '12 at 17:44
  • @AlanB LOL, servoy developer is just a wrapper around eclipse. And it doesn't run properly on linux without hacking environment variables and it doesn't even allow you to open a folder of code or do anything useful :\ – Raynos Mar 03 '12 at 19:03
  • There's plenty of installed applications using it so it must be possible to do *something* useful ... a Linux application that needs some hacking? Whatever next! :) Here's the stack it uses: http://wiki.servoy.com/display/public/DOCS/Servoy+stack+info So basically it's all familiar stuff from the Linux world, the IDE is Eclipse-based with a form designer, database browser, source control (SVN) and the Javascript implementation is Rhino. You can open up the .js files outside it if you want, they're all there in the project folder. – Alan B Mar 05 '12 at 08:20
  • @AlanB the point is, for JavaScript development it's less usable then eclipse, and eclipse is horrible for JavaScript. It's not a proper JavaScript IDE. – Raynos Mar 05 '12 at 13:29
  • @Raynos: Same here: I use vim (gvim) for C, C++, Java, Scala, Pascal, Haskell, LaTeX or whatever code I have to edit. – Giorgio Mar 30 '12 at 14:34
  • 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 Jun 26 '15 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.

StuperUser
  • 6,133
  • 1
  • 28
  • 56
  • 1
    +1 completely forgot how a stdio library is kind of important. – Raynos Aug 30 '11 at 09: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 Aug 30 '11 at 09: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 Aug 30 '11 at 09: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 Aug 30 '11 at 09:38
  • I edited my question for clarity. Of course the language need low-level features to interact with the OS. I'm talking about the language itself, the syntax and the various programming solutions it offers. – Jose Faeti Aug 30 '11 at 09:48
  • @sa93 Indeed, it becomes trivial with node.js. When posting via HTTP, the JS's responsibility is to post the data to be persisted, not to write it to the disk, that's being done by the IO library for the code on the server. – StuperUser Aug 30 '11 at 09:54
  • I agree with StuperUser. Writing files to the file system has been replaced with HTTP POST. Files are usually the wrong way of thinking about storing data these days. – reinierpost Jun 26 '15 at 10:07
  • 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 Jun 26 '15 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.

JacquesB
  • 57,310
  • 21
  • 127
  • 176