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.

There is a lot of buzz around Dart recently, often questioning Google motivations and utility of Dart as replacement for JavaScript. I was searching for rationale of creating Dart rather than investing more effort in ECMAScript. In well known leaked mail its author is saying that

Javascript has historical baggage that cannot be solved without a clean break.

But there is only one concrete example given (apart of performance concerns) of "fundamental language problems", which is an

existence of a single Number primitive

So, my questions are:

  1. How an existence of a single Number primitive can be a "fundamental problem"?

  2. Are there other known "fundamental problems" in JavaScript?

share|improve this question

closed as not constructive by World Engineer, gnat, Jim G., Walter, Robert Harvey Apr 10 '12 at 23:18

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

Compatibility and speed are the main problems I've had with it. I love JS's capabilities but IE bloody hates it I'll tell you that much. –  Ben Brocka Oct 15 '11 at 0:38
Some of the bias is subjective. JS is "non-pythonic" and I hate that. –  Job Oct 15 '11 at 2:16
@Job Non pythonic? If anythng I've heard it's TOO pythonic (meaning high level as opposed to low level) so I'd love to know exactly what you mean. –  Ben Brocka Oct 15 '11 at 2:37
@SirTapTap, Scala is very high level and much hyped, but some Pythonistas claim that it is not "Pythonic", and I agree. Ruby is not that pythonic either, IMO. neopythonic.blogspot.com/2008/11/scala.html To give another example of a clean language: Clojure. C# is not too bad either (yes the language is large, but it also tries to do a lot). As I said, some of this is subjective. –  Job Oct 15 '11 at 3:37
@BenBrocka Just because you saw a few terrible apps in a terrible language, do not neglect C# - It is an elegant language, and an open spec - The Mono Project guys are doing a great job porting the CLR to other platforms. –  yati sagade Nov 23 '11 at 20:11

4 Answers 4

up vote 26 down vote accepted

1) All Javascript numbers are specified to behave as per the IEE-754 double precision floating point specification. This means that

  • You can't opt to use normal integers (for conciseness or speed). Your best bet here is having your compiler optimize this behind the scenes (but at the cost of perhaps having to add runtime checks and other annoying things)

  • There are no bignums built-in. If a Javascript Number "overflows" it starts losing precision.

  • There are no decimals so its annoying to work with currency and other cases that require more precision.

  • There is no operator overloading so you can't overcome these problems in a library (without having ugly, ugly syntax)

2) What are the other warts of Javascript.

Having been created in a 2-week hurry back in 1995 its actually surprising Javascript turned out to actually be pretty useable language. However there are lots of little mistakes around that we now have to live with in order to preserve backwards-compatibility with ancient browsers. Some of the more egregious problems:

  • There are no modules and no native way to provide encapsulation. The most common solution involves managing namespaces by hand in the global scope.
  • OO-style programing is kind of weird. It uses a prototypical model but has a very weird pseudo-classical syntax that serves only to confuse. The this special variable doesn't have lexical scope and can clobber the global scope in some cases (in non-strict mode).

You can probably find a more comprehensive list in any good Javascript reference. I recomend Javascript: the Good Parts as a good book to both learn the language and about some of the warts and wtfjs if you want little snippets of the weirdest corner cases.

Now for the Dart part I will get a little more subjective. In my impression, Dart looks less like a "Javascript-sucessor" and more like an evolution of the Google Web Toolkit, a set of tools that allow web apps to be written in Java. The heavily class-oriented mindset in Dart and its type system are very Java-like and I don't think this is really the kind of "revolutionary break" that would be expected from a candidate be the next ruler of the web landscape.

share|improve this answer
+1 GWT, yes had the same feeling at a certain point. Like it's something meant to play well in their ballpark. GWT: something that most people don't want to deal with while they invested heavily in. –  ZJR Oct 15 '11 at 1:25
I'd say that encapsulation within an execution context of an anonymous function is a native way to provide encapsulation, albeit one not easy to grasp for newcomers to the language. –  scrwtp Apr 11 '12 at 12:32
@scrwtp: You are right. I was thinking more about module-level encapsulation though (and the lack of a standard module system) –  hugomg Apr 11 '12 at 22:47

Some known problems with javascript are:

  • Many don't understand some core JS concepts, like the prototype concept

    …those people usually claim they miss:

    • some clean cut class syntax
    • some clean cut inheritance and interfaces
    • static typing

    They want the whole OO package, just as college taught them over Java, and they ain't gonna bend much.

Note: misconceptions run really wild in the js ecosystem.

There is also people that cannot understand the fact javascript isn't "a loosely typed language based on java with a lot of syntax sugar". (i.e.: groovy)

That's a die hard misconception related to the naming confusion Netscape introduced by baptizing javascript as such.

  • Many people also, don't get the virtues of:

    • happy, careless, method aggregation
    • object enrichment, that is, "slapping in properties, on need".
    • code hijacking, done at runtime, using the prototype trick

    They regard those as form of dangerous anarchy that will destroy western civilization as a whole.

Note: Actionscript, (used in Flash by Adobe) is an ECMAscript language (hence an extension of javascript) and it gives those people what they ask, without spoiling the fun for the rest of the punks or killing javascript simplicity in the process.

So, the OO class/interface/inheritance requests, may look boring, but certainly are addressable without rolling out a brand new syntax.

  • Memory allocation is very dynamic (prone to leaking, not very efficient)

I'd like to know how many of those OO people's issues are really being targeted by Dart, but it's so hard to bother enough about such an impractical, superfluous, non backwards compatible language for the web, to perform some serious checking.

share|improve this answer
You don't need classes, you don't need interfaces, you don't need static typing but I would give that as potential for improvement. –  Josh K Oct 15 '11 at 0:27
I actually would consider classes as a step backwards. If you want to do OO the prototypal pattern is just as good (and perhaps even more powerful) and if you want modularization an actual module system that doesn't abuse the class system is much simpler and saner. –  hugomg Oct 15 '11 at 0:45
@SirTapTap: A static type system is not that bad actually. The more advanced type systems can handle generality pretty well and you can also use the Dart approach of having a flexible type system that just helps give some warnings. (And btw, I don't think C, the king of unsafe casts and void*, is that good of a poster boy for static typing :P) –  hugomg Oct 15 '11 at 0:48
@SirTapTap: A static type system can let you be more bold when refactoring code, since the compiler will help find all the broken pieces that need to be changed. That said, a more loosely typed system can allow you to run the program in an unfinished state, rolling changes more incrementally. –  hugomg Oct 15 '11 at 1:12
A message from your friendly neighborhood answerer: I don't bother about classes, interfaces, and static typing too. I find javascript refreshing in that respect. But then, big industry wheels are obsessed with that stuff. At least as much as they are obsessed with code reuse, and many believe it cannot happen without the whole OOp experience thing. So... yes, from that POV, those features are missing. –  ZJR Oct 15 '11 at 1:34

There is nothing wrong with Javascript at all. I write in javascript for last 3 years and I that is my primary language cause I use an ExtJS framework.

At one moment I was convinced to use JSLint - saves me from most of stupid errors. Also I had to realize what is prototype, function, constructor, THIS (that was really hard at first but one moment I started to understand it pretty well), inheritance emulation, module structure, minifying and other important parts for every web developer.

At one moment(probably a year go) I just got enough experience and understanding to think completely in javascript. A lot of programmers want to program in javascript like in Java, C#, ruby. That is the most serious issue, I think.

And I am sure as soon as we get breakthrough in processors speed and browsers have better JS engine, the javascript will be used as an 'assembler' for

smalltalk (Amber Smalltalk based on jQuery)

ruby/python (look at http://repl.it )

whole linux kernel (dont remember the link, but there is a port of linux kernel for javascript)

native video encoder.

And thats all is just evolution, not a revolution with selecting a totally new language as default one for browsers.

share|improve this answer
"inheritance emulation" We don't emulate inheritance we use prototypical inheritance. –  Raynos Nov 23 '11 at 16:52
"I write in javascript for last 3 years" I think the surgeon general warns that this may cause brain tumors... –  Rig Apr 10 '12 at 5:17

JS got plenty of things right, but IMO there are also plenty of things wrong:

  • The lack of a import / module system
  • How easy is to make a variable global without noticing
  • The very awkward syntax for defining a prototype chain (having to define a function and then add stuff to the prototype of the function). There is a _ proto _ object that is extremely intuitive cannot be used in all browsers.
  • The handling of numbers (only floats), you cannot make reliable calculations of decimal numbers in javascript
  • Some syntax inconsistencies like the instanceof operator. E.g. (x instanceof Object).
share|improve this answer
module system exists, AMD / CommonJS. Use ES5 strict to avoid accidental globals. Use Object.create for elegant prototypes. Numbers is a valid complaint, syntax complaints are iffy –  Raynos Apr 10 '12 at 5:37
Unfortunately, not all libraries will support AMD, which means you have to patch them if you want to use AMD. I agree for use strict. And no, Object.create is anything but elegant - you just cannot set the properties as in object literals; you also have to declare whether they are enumerable, configurable and so on. –  Andrea Apr 10 '12 at 10:38
@Andrea Agreed defineProperties is ugly, You can use something like extend though example –  Raynos Apr 10 '12 at 13:14

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