4 ms·
Wrong. What makes JavaScript popular is how good it is. You can't explain its mass popularity growth in non browser setting (node js ) with its ubiquity. It is
by vectorjohn 15y ago
Wrong. What makes JavaScript popular is how good it is. You can't explain its mass popularity growth in non browser setting (node js ) with its ubiquity. It is a great language, and perhaps ubiquity was needed to get a lot of people to try out new concepts.
- tomjen3 15y agoHave you used Javascript? I mean to do real-web apps, not to enhance some webpages with a bit of JQuery (as useful as that is). Var is broken in js because it does not obey sensible semantics for(var i.... does what you think it does. In every language except javascript it would declare i only inside the loop. In js it declares i in whatever function scope the loop is inside. A = function(){ console.log(this); } A.prototype.q = function(b){ this.h = b; } imp = new A(); setTimeout(100, imp.q) //later, in a response to a user event console.log(imp.h) prints undefined. Why? because in Javascript the value of this changes. There is literally no other language where this is dynamically (as opposed to lexically) scoped. Don't even get me started on the lack of ints, the lack of static types (which means your IDEs suck). As for why node decieded to go with js? No idea, though it is one of the things I hate most about node. Haskell would have been a better choice, as would Lua.
- jd 15y ago> Var is broken in js because it does not obey sensible semantics Scoping is broken in pretty much all modern dynamic languages. Take Ruby for example: i = 10 [1, 2, 3].map{|i| i * 3} [1, 2, 3].map{|j| j * 3} puts i # prints 3 puts j # raises undefined local variable Or let's look at Python: def maybe_append(b=[], n = None): if not n is None: b.append(n) return b print maybe_append(n=20) # prints [20] print maybe_append(n=30) # prints [20, 30] So there's only a single instance of [], so that the default argument "grows" over time.
- moonchrome 15y agoIt's things like this that make me realize how right Clojure gets it (and I've been burned by python on that same "bug").
- deleted 15y ago[deleted]
- vectorjohn 15y agoYour argument makes it pretty clear it is you that have not used Javascript very much. setTimeout( 100, imp.q) // DOESN'T DO ANYTHING, 100 is not a function And if you thought about it for more than a few seconds, you would realize that the behavior of "this" makes sense and is less magical than in other languages. Since "imp.q" is not a function call, it is a reference to a function, you are simply passing in a function. Since javascript "classes" are just objects with function references, you can't somehow decide what object "this" should point at unless it is explicit. In the case of "foo.bar()", it is explicitly "foo". In the case of setTimeout( foo.bar, 100), all setTimeout gets is a function pointer with no notion of what this should be. Anyway, the rest of your gripes just sound like you don't like untyped languages, which is personal preference and I guess I don't share your preference.
- tomjen3 15y agoI haven't used setTimeout much, but I do use js everyday (it is my fulltime job). And it may be nice to have 'just objects with function references' when you are writting a few lines of code to validate emails or something like than. When you start pushing 2k lines of code and more than two developers you need much more structure than than that. Anyhow C++, Scala and C# all have reasonable understanding of this. If all you have are function points, don't have this.
- batista 15y agoWrong. What makes JavaScript popular is how good it is. You can't explain its mass popularity growth in non browser setting (node js ) with its ubiquity. Sure you can. Node.js is not even that impressive: similar solutions exist in lots of other languages, Ruby, Python, even Java. The Node guy wrote Node in JS for two reasons: V8 was a good and fast environment, and JS didn't have much existing libraries, so people could start making new async libs.
- rdtsc 15y ago> What makes JavaScript popular is how good it is. If you are trying to be sarcastic, you are not doing it right.
- vectorjohn 15y agoHah, no reason to get defensive. Javascript is a great language. If you don't like it, you are free to feel that way. But there is a huge number of people who like it. Personally, it is my favorite programming language. It just feels right. And I've only been using it for a few years. It really isn't hard to get past the bad parts.