Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
7  
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 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 Aug 30 '11 at 9:09
2  
I see dynamic typing as a huge drawback, and I also would like to get rid of null values. –  Jonas Aug 30 '11 at 9:24
1  
You mean "classical application development", not "software development", right? Better change your heading accordingly. –  Doc Brown Aug 30 '11 at 9:29
2  
@JoseFaeti for the record windows 8 allows you to do some development in HTML5&JS –  Raynos Aug 30 '11 at 10:01
show 7 more comments

4 Answers

up vote 10 down vote accepted

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.

share|improve this answer
    
Must be like that, and I looks like something is actually moving now :) –  Jose Faeti Aug 31 '11 at 9:45
add comment

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.

share|improve this answer
    
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 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 Aug 30 '11 at 9: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 9: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 9:43
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 9:45
show 17 more comments

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.

share|improve this answer
1  
+1 completely forgot how a stdio library is kind of important. –  Raynos Aug 30 '11 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 Aug 30 '11 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 Aug 30 '11 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 Aug 30 '11 at 9: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 9:48
show 1 more comment

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

share|improve this answer
    
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. –  ajax81 Mar 30 '12 at 15:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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