160 points · by CmonDev · 13y ago · 238 comments
"Being nice will not help it, and CoffeeScript is not radical enough."
As the guy who started CoffeeScript, I agree. It's an intentionally very conservative approach. But there's more than one good way to skin the JavaScript cat. I think it would be fun to take another run at the same problem — attempt to find a minimal, readable, and easier-to-learn language that fits in the same role as JavaScript — but to do so with a much more radical design. Whereas previously such a thing would have been unusable in practice, having good sourcemap support in most browsers these days makes it viable, perhaps. I've been playing around with it a bit...I've tried to think about potential improvements to CoffeeScript, but I have to say that I'm completely satisfied with the language now. Many of the things that I think would sweeten the language even more are easily achieved by simply including 3rd party JavaScript libraries.
Thank you so much for contributing 3 great pieces of work to the community!
Do you think ClojureScript could fit this category? We have teams that use it in production without any significant problems at all.
But it also connects to a larger universe of Clojure libraries and practices, and a vast history of Lisp tradition — most probably for the best. In that sense, it might be more of a maximalist approach than what I'm looking for. (And (of course) readability is in the eye of the beholder ;)
I still think the main point around javascript is the type system or the lack thereof. I don't mind dynamic typing, but the javascript data types are central to all HTML5 APIs and most existing libraries. CoffeeScript gets this right, many others don't.
> CoffeeScript gets this right, many others don't.
I'm not sure what you mean by that — as CoffeeScript's "type system" has no difference from JavaScript's.By the way, thanks for your work on _ & Backbone!
> Have you considered porting Ruby directly to JavaScript?
No. It's been attempted before, and it doesn't turn out to be terribly useful in the end, because of the vast semantic mismatch between the two languages. See: https://github.com/jashkenas/coffee-script/wiki/List-of-lang... > I've never gotten over the usage of "->" or "=>" to signify a function.
Give it a try, perhaps. It's critical not to use "def" and "do" when your functions are first-class values that can be passed as arguments, or assigned to variables. It's for this reason that Ruby 1.9 has a new lambda syntax that looks a great deal similar to CoffeeScript's. For example: request(url, def callback(response) do
...
end)
... that kinda thing is no good.The reason it's an arrow is because in any decent function, the input determines the output, eg. input points to output. And therefore, the CoffeeScript syntax: (input) -> output
True, I'd chose CoffeeScript over Opal.
>> Give it a try, perhaps.
Oh, I dig it, especially the fat arrow.
>> It's critical not to use "def" and "do" when your functions are first-class values that can be passed as arguments, or assigned to variables.
Still, I find "def" to be more `readable` than arrow symbols. I'm not sure how JavaScript's first class status for functions would deter a keyword containing letters. Considering JavaScript itself uses function as its.
>> The reason it's an arrow is because in any decent function, the input determines the output, eg. input points to output. And therefore, the CoffeeScript syntax: (input) -> output
That definitely makes logical sense. Still, I feel the readability might be increased by using words, which the mind is more attuned to quickly applying meaning to.
Edit: Great job, on CoffeeScript, regardless!
[1] http://www.nczonline.net/blog/2013/09/10/understanding-ecmas...
But in any programming language you're already indenting blocks for humans. Why repeat the same work? Especially when it allows for inconsistency between how a human and how a machine would read the code.
The -> comes from Haskell's lambda syntax (\x -> x+1). It's a nice solution. 'Def' doesn't really work for lambdas, do does, but curly-brace blocks are nicer in Ruby if you put them everwhere {|x| x+1}... Keep in mind that Javascript is alot like Scheme in that there isn't really a difference between named and anonymous functions. You can write Scheme and Javascript pretty much the same way...
It's been done. Check out Opal. I can't say I miss Ruby's ends in CS.
Tell us more!
The web that we build for today is a rich, almost entirely backwards-compatible stew of nearly two decades of browser development and standards work, resulting in a triumvirate of very different languages that need to come together in order to make a web application happen: HTML + CSS + JS. Two of them are weak, data-description languages, one is strong and general-purpose. You have to learn all three, and learn about the quirks and sunspots accumulated over the years.
So, as a thought experiment, imagine what it would be like to work with a single language that was general-purpose, but also excellent at describing data, especially the trees (HTML) and property lists (CSS) that make up web documents. Perhaps it knows about the intended lifecycle of your HTML in a more structured way. Perhaps other flatly descriptive parts of your application can be merged with the "flat" styling of your CSS descriptions. Perhaps the idea of "binding" is built-in.
After that, there's technical hoopla. If it's interpreted in the browser, you need to be light and parse quickly, you need to be able to "JIT" chunks of code into optimized JavaScript when necessary, and you need to be able to dynamically generate the appropriate source maps, so that it feels closer to a seamless experience.
Is such a unifying language possible? I don't know. But imagine how much more fun it might be to work with — and more importantly, how much more accessible it could be for folks just getting started.
But when there is something to show, y'all will be the first to know...
You can accomplish this pretty effectively with a clojure/clojurescript stack, though it takes some work to get going and isn't perfectly seamless. Code-as-data seems really well suited to unifying the declarative and procedural.
Personally, I love the ideas behind clojure, but I prefer the experience of writing coffeescript to clojurescript. I think it would be very cool to see you combine your penchant for pragmatism and nimble syntax with the solid engineering principles of functional languages.
Now this is interesting. Working on anything!
> [1,10,5,-15,-2,4].sort();
[-15,-2,1,10,4,5]
And yes saying "oh but it is because it has weak types" doesn't excuse it, it is broken and that's that. Naming the brokeness with a label or showing why historically it is there, doesn't fix it.On the other hand they do have nice closure support, I do like some of that. But in large, the language makes me angry every time I have to use it.
Someone mentioned Dart, I am hopeful for that. But who knows how long till dartvm is embedded in Chrome. For now dart.js and source maps might help.
There is a bit more palatable Coffeescript. But it only puts some band-aids over JS's brokenness.
Also agree with callback hell. It is funny people extol is at the next big thing -- whoo, asynchronous calls! You can callback in your callback while you callback. No, no, no. That is a horrible way to handle large concurrency problems! (Good for quick one page examples though!). Async and friends help. But why the heck do I need to stick a callback in the middle of my logic if all I need to do is make a request to the database or another GET request?
The only sane way I know how to best handle concurrency is using a language with support of goroutines/isolates/tasks or even threads and queues. Even deferreds are just sugar on top of callbacks. We all know how Python's Twisted has taken over the world, right? Oh wait, it hasn't. Calling them Futures or Tulips or whatever doesn't fix the underlying problem.
> I can understand that some people wanted to escape the MRI infrastructure by going Node, because - you know - learning Japanese is hard.
Granted node is fast. (And according to its author scales linearly across CPU cores, sorry couldn't resist the mandatory jab at that). Ok it doesn't really scale across cores and it will block everything if you do a for loop in the middle of your logic. But it is really fast, amazingly so. And that is like crack. It gets people hooked.
EDIT: JS has weak types not just dynamic, one can have dynamic and strong types for example, like Python ( https://en.wikipedia.org/wiki/Weak_typing ). Thanks makslinn.
It has nothing to do with dynamic types[0]. It has to do with
> If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic[0]
period end of the story. You might argue it's a shitty default, but please argue against reality, not what you (wrongly) believe it is.
[0] this is the MDN translation, the exact specification is steps 14 to 18 of the SortCompare abstract operation, defined in ECMA-262 5.1 15.4.4.11 "Array.prototype.sort (comparefn)":
13. If the argument comparefn is not undefined, then
a. If IsCallable(comparefn) is false, throw a TypeError exception.
b. Return the result of calling the [[Call]] internal method of comparefn passing undefined as the this value and with arguments x and y.
14. Let xString be ToString(x).
15. Let yString be ToString(y).
16. If xString < yString, return -1.
17. If xString > yString, return 1.
18. Return +0.
[0] your edition to "weak types" is just as wrong as the previous version I quoted was.> `If compareFunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic` period end of the story.
As I said explaining the historical context or labeling the brokennes with something like "weak typing" doesn't excuse. It still stays broken.
> You might argue it's a shitty default, but please argue against reality, not what you (wrongly) believe it is.
Surprise, I know it is possible to eventually sort things in JS. I too have seen sorted tables in JS done entirely in JS. That's not the point. The point is, it is has fundamentally broken type system.
No, it does not. You could define the exact same default function in Java, Haskell (requiring that the sorted type be a Show instance) or Python (hell, getting the exact same behavior in Python could hardly be simpler: `ar.sort(key=str)`. There, I broke it. That is near literally how the ECMAScript spec very explicitly defines the default comparison function. The behavior of the sort function is not a consequence of weak typing).
> As I said explaining the historical context or labeling the brokennes with something like "weak typing" doesn't excuse.
Which you'd know is not what I'm doing, if you could be arsed to read instead of trying to substitute your imagination for objective reality.
> The point is, it is has fundamentally broken type system.
That might well be, but the default sort comparison function is not a demonstration of it. As opposed to the comparison table of 0 and null for instance:
> 0 < null
false
> 0 <= null
true
> 0 == null
false
> 0 >= null
true
> 0 > null
false > [1,10,5,-15,-2,4].sort(function(a,b) {return a > b})
[ -15,
-2,
1,
4,
5,
10 ]
> [1,10,5,-15,-2,4].sort(function(a,b) {return ""+a > ""+b})
[ -15,
-2,
1,
10,
4,
5 ]
Perhaps .sort was initially designed to do something else, like sorting strings, rather than integers.If such a petty and trivial "problem" is what you have against Javascript, then you are basically saying it's a good language :--)
[1,10,5,-15,-2,4].sort(function(a,b){return a-b}); [-15, -2, 1, 4, 5, 10]
> [1,10,5,-15,-2,4].sort();
> [-15,-2,1,10,4,5]
[1,10,5,-15,-2,4].sort(function(a,b){return a-b})
[-15, -2, 1, 4, 5, 10] [1,10,5,-15,-2,4].sort (a, b) -> a-b
You're right; that was totally difficult. Safari/Chrome: SyntaxError: Unexpected token '>'
Firefox: SyntaxError: syntax error
In a discussion about Javascript maybe it would be a good idea to give examples of Javascipt that actually run in a Javascript console? [1,10,5,-15,-2,4].sort ((a, b) => a-b).toString();
"-15,-2,1,4,5,10"Sure, it has a bunch of quirks. Sure, it's not good for everything (I do mostly relatively simple CRUD apps). Sure, in the browser, it gets slow when the DOM is involved. Sure, this is hardly a rebuttal of the points in the original article.
But, still, I love JavaScript.
I think the problem is that the author is writing JavaScript as though it's Ruby. A JS developer switching to Ruby would have similar problems.
But I could forgive all of that.
JavaScript is not well designed for work in a team environment, nor is it well designed for Large Code Bases.
But I could forgive all of that.
All the best languages have a group of scientists that have chosen that language to be their defacto language. That is why we see Python, LISP, Fortran (yes still), MatLab, all living on long beyond the "trendy" languages.
JS only picked up steam because Flash died. Not because it was a great language. If it were a great language people would have started optimizing it 5 years ago. It isn't. So they didn't. The new optimizations are out of necessity. And because it lets front end pretend to be backend. That may sound snobby, and it is, but JS for backend is like writing in Visual Basic. These days you can do anything in it, it will be fast, but that doesn't make it the right choice.
Very much ^this.
I never cease to be amazed by the defensive attitude and excuses coming from JavaScript developers. Usually the premise is "I can get shit done in it, so it must be good", which isn't a particularly strong argument.
If you would make up 20 completely different metrics to rank programming languages on, and score every popular language using each of them, JavaScript would be near the bottom of almost all of them, and near the top of none. It's not terrible in every way imaginable (it would score reasonably well on 'productivity' for example), but it's not great in any of them either, which frankly makes it a shit language that only exists as a historical accident.
JS is the fastest dynamic language next to SBCL's Common Lisp implementation.
> JavaScript is not well designed for work in a team environment, nor is it well designed for Large Code Bases.
Why is this a problem? Most web problems don't need a large code base. A small, dynamic language is suited to web problems. And judging by the amount of things being built with Javascript, enough people have figured out its quirks.
> All the best languages have a group of scientists that have chosen that language to be their defacto language. That is why we see Python, LISP, Fortran (yes still), MatLab, all living on long beyond the "trendy" languages.
To a certain degree I agree, at least about LISP and Fortran. You should add Haskell to the list. One language has also lived long beyond most of the trendy languages: COBOL. Take that for what it's worth.
> but JS for backend is like writing in Visual Basic. These days you can do anything in it, it will be fast, but that doesn't make it the right choice.
Why this is even an issue is beyond me. Nodejs is good for people writing a small backend to interact with a single page app on the client side. If you're writing giant Nodejs apps you're doing it wrong.
Besides, with pretty much every language having web frameworks and every language compiling to JS, you have plenty of choices.
Despite all of JS' quirks, people still write amazing things in it. That should tell you something.
This is demonstrably false the second you start to use JS on the backend. Just because most of the problems you've seen require only tiny codebases does not mean that they all do.
In comparison to what? JS is one of the faster script languages out there. V8 is way faster that Ruby and outperform python a lot of time as well. It's regex is blast fast as well.
Performance was one of the selling points of Node.JS for me.
This part of Javascript sounds the most absolutely insane to me: Silencing an error like that is catastrophic.
>if you're passing more than a few parameters into a function
I didn't know you had to have "more than a few parameters" before you could make a coding error related to the number of parameters you pass something.
Javascript's squishiness is the thing I like the most about it. It's far from perfect, just like any other language out there - but it's fun.
We're talking about programming errors. Are you suggesting the solution to human error is to just not make errors??
Note, of course, that wrong arguments will frequently not arise from a function call you just wrote -- but from changes in the code.
Say you merge in a trivial merge of some code, which changed a function's signature/parameters. The merge succeeds trivially. Now every single function call is a bug that is not only uncaught by a compiler. It won't even necessarily be caught at runtime. Instead, it may escalate to catastrophic, undefined/unexpected behavior.
It's like someone complaining that git let them make a mess after they merged master into their feature branch and then merge it back into master.
You say "use to your advantage", but what's the advantage? You could have a "*args" like Python, and get the benefits without the (huge) drawback.
The typing debate is mostly about how much effort we should exert to catch errors at compile time rather than run time. In JS, it is much worse: It defers error catching forever, and never even catches them at all! It converts them to silent bugs, instead :(
Silencing an error would be a problem, but in JS, it's not an error, because there's no concept of "wrong numbers of function arguments" built into the language. That's not to say you can't inspect the number of arguments yourself and throw an error, if some situation warrants it. But you don't have to do this. It's a very flexible, dynamic language. In some ways this flexibility makes things easier and more expressive, in other ways it necessitates more manual checking (or slower debugging). There's no catastrophe, just design differences.
See, there's the problem. Glossing over issues by explaining them away as "design differences". Nothing about an expressive language necessitates making life hard for the programmer. If your function call doesn't match the signature then it is very likely to be in error, and instead of failing silently the language should make such mistakes easy to spot. I like how most other dynamic languages require you to be more explicit about function parameters (with the exception of PHP).
(function(window, undefined) {...})(window);Here's a clue folks: you're the programmer, it's your job to work out how to programme for your target platform, and if you can't then fuck off and leave it to the professionals.
Wait, what? That's the definition of a closure.
Most of this seems to boil down to the author saying "my programming brain was hardwired by Ruby, and I'm annoyed JavaScript is different." OK, I feel your frustration. As a reader, though, I'd far rather see a post from someone who has spent the time to become proficient in both ecosystems and can offer more considered pro/cons.
On one point, I'll agree: I wish Javascript had an easy way to say "referencing an undefined property of this object should throw an error."
The problem is that you hardly have a choice nowadays. Python, JS and PHP are dynamic, Java is a great language but crappy concept (don't tell me it isn't slooo... <wait for GC... ok, done> ...ow). Ironically, the ugliest language I have ever coded in (ObjectiveC) has the best design decisions (IMHO). ARC instead of manual memory management or GC, strongly typed but still allows generic object pointer (id),...
It's funny, because objects in Objective-C are dynamically and weakly typed, and as flexible as in JS. The syntax has unnecessary rigidity that doesn't map well to actual semantics of the language.
Message passing in ObjC doesn't care about types (you can send any message to any object, and the receiver can capture the message and do whatever it wants). You can change/add methods (and "associated" properties) at run time, of instances and class definitions, just like in JS.
e.g. Cocoa bindings will subclass your objects (create a new subclass at run time and swap identity of your object) to replace setters with ones that notify the UI.
https://developer.apple.com/library/ios/documentation/cocoa/...
Because you don't have to write a lot of boilerplate to tell the language things that it should be able to figure out for itself.
I mean, if I have a variable I ALWAYS know what kind of data I expect in it.
But that data might not always be of the same type. For example, in Python, I might want a variable to hold strings but also None, so that I can differentiate between, say, "the user explicitly entered an empty string" and "the user hasn't entered any string at all yet".
Yes, there are ways to do this in statically typed languages (for example, Haskell's Maybe), but it's still extra code that I have to write.
This is exactly my point; compiler can't figure out what kind of data I want, at least not in general. A good example is jQuery $.data() which tries to guess what kind of data you have in your HTML tag attribute. Guess what happens if you have a MongoDB ObjectId (as string), for instance "52259986890d6f24e9000000"? Exactly - it is a floating number. Believe me, it leads to some interesting debugging sessions... :)
I agree with you however that it is beneficial to have a way to set the var to None/null/..., indicating "not initialized". Win some, lose some I guess.
But that's a matter of semantics, not static typing. You're going to have to do type conversion on the string regardless, because "MongoDB Objectid" isn't a native type for the compiler. But with static typing, you need to tell the compiler the type of the variable in addition to telling it how to do the type conversion: for example, in C++, you might have to say...
var MongoObjectid id = new MongoObjectid("somestring");
..whereas in Python, for example, you could just say... id = MongoObjectid("somestring")> I mean, if I have a variable I ALWAYS know what kind of data I expect in it
Really? Why did people invent generics/templates, interfaces and class-inheritance then? You won't always know what type you are receiving, and alot of the time you don't really care either, as long as it meets your criteria.
> The problem is that you hardly have a choice nowadays
Course you do: C/C++, Haskell, OCaml, Go, Nimrod... Soon you'll have Rust to play with as well.
> <wait for GC... ok, done>
Depends on your usecase. As long as your active memory use don't number in multiple GBs, GC is quite fast. I have an application spawning 1GB of garbage a second, this takes 5ms (a second) to collect. Not bad IMHO. The work they are doing on the new G1 collector also seems promising. Btw, GC can in many cases have lower overhead than ARC (Python also does ARC btw).
> strongly typed but still allows generic object pointer (id)
Last I checked, most of Obj-C prefers dynamic typing. NSArray and NSDictionary for instance, can contain any type. Regarding (id), most languages allows this. "Object" in Java/C#, void* in C/C++, interace{} in Go etc.
In the end, it doesn't really matter what language you use, as long as it gets the job done. If your language isn't available, you're mostly able to use another language anyway. Almost every language nowadays has a JS-compiler. There exists a Java Bytecode -> Native code compiler, same with C#.
Shouldn't you just pass the 'age' property then?
This is a poor example, i know, but the point is that while both is simple operations in both static and dynamically typed languages, dynamically typed languages allow you to do this without writing an interface, generic function, abstract base class or whatever and restricting the function to that particular use case.
The tradeoff is flexibility vs safety. I personally prefer dynamically typed languages as I've found that with a combination of discipline and unit-tests (which, IMHO, you should have anyway) I never really miss the static type-checker. But I understand those people who prefer static typing very well.
Obviously Node (and JS) has some things that it is strong in. People use it to build those things. Good developers won't use a tool in their box which is inferior to another tool they can use effectively. In between, there is a lot of room for "good enough" where tools overlap.
I think some developers are able to largely stick with a certain tool because development goes in waves. I can spend multiple months on a certain profile of work and then get hit with the same type of project a couple more times. Maybe by then I become an expert with that thing and I just keep doing those sorts of projects. You might think I'm crazy because I'm a "Node developer" but you probably don't know the nature of the work that I do.
Eventually I get hit with a different project and everything falls apart if I try to keep using the same tools as I had been using. So, I curse myself for being stupid and wasting time and start over with the tool I should have been using in the first place.
Some developers might have such a limited set of tools that they can't (or won't even try) to switch.
"So, I landed a big gig for the government. It's a healthcare site. I'm going to build it in Wordpress."
Following this thread further, look at some of the selling points of Node.
* It's great because as a front-end developer, you probably already know JS. With Node you can use JS on the back-end also!
* Because the front-end and the back-end are both in JS, I can use one programming language and re-use libraries for each side.
Great, let's encourage people who only know one programming language and a limited range of tools to just stay in that box.
There are things that X tool does well. There are things that X tool is horrible at. Perhaps rather than ragging on Node, the author should write an article explaining that developers should be expanding their tool-set so they have flexibility in handling different types of problems.
People use JavaScript not because it's good but because it's the only option to develop in a browser. Having the same language on the client and the server is a very strong point, that's why they use NodeJS.
Only if you're so incredibly strapped for cash that you can't hire real devs that can pick up another language in a day or two.
Almost every language used commonly on the serverside is vastly preferable to js.
This whole "well, it's THE SAME" benefit simply isn't. It's a red herring.
I'm convinced the whole ecosystem has sprung up because of hordes of terrible copy-paste browserside devs that don't actually fully understand what they're doing in js, who resultantly would be incapable of building anything serverside in another language at all because their overall comprehension of programming is marginal at best.
Anyone not stupid or insane just learns ruby or python or scala or go or even php or .NET.
PS: cue replies from all dozen people on the whole internet who know pointer math and still like coding webapps in js, who don't realize that I'm not talking about the 12 of them but the 12,000 who are doing the js/node problems on codeacademy this instant.
If your application is more complex on the client than on the server, that's the way to go.
I personally, prefer GWT here. Java on the client and the server is much better than JavaScript on its place.
I started with PHP and C#/VB.NET, before learning JS. I know Python, Scheme, Java, I've played a bit with Clojure and Ruby[0]. After all that, JavaScript (admittedly, usually through CoffeeScript) is my favorite language. It provides everything you need to build almost anything you want, wrt tooling.
I understand and agree that it has warts, as does every language. But to call its use "stupid or insane" is ridiculous.
[0] I have yet to understand the concept of blocks, as they seem to be just a half-assed implementation of first-class anonymous functions. If someone can show how they improve on them, that would be much appreciated.
Node covers a lot of "good enough" space for what a lot of people are doing. The people who complain the loudest about Node are likely those who are working on things which aren't covered by that "good enough" circle.
I wish people would use real life project examples or include the sorts of work they do when they makes these kinds of arguments. It would help us see where this person is coming from.
Node is fantastic for rapid prototype development, or tiny little startups that need to do the absolute minimum amount of work so they can finish before running out of money.
Everything goes sideways when these cute little Node apps get pushed out to real production use (if you measure things in anything other than dollars per second, you don't get to chime in here and redefine production). Then the heavy hitters have to come in and patch Node itself, or rewrite it in another language.
I've gone in to a growing startup over a weekend and saved them $1000/mo in AWS instances by rewriting a Node app in 30 lines of Go.
I hate to cite examples of real world projects in threads like this, because it just devolves into "OMG YOU NOOB THAT WAS FIXED IN THE BASHFUL BADGER RELEASE" when said fix was the result of a bug you opened or a patch you submitted.
Consider for example a rich text editor, or diagram editor with a complicated automatic layout. Doing such things in JS is extremely painful.
- Flash? That's almost the same as JavaScript and it's getting obsolete.
- Java? No one enables it on the client, thanks to security problems.
- Asm.js/LLVM? These are immature and can't be used for production.
As it turns out, many of the issues outlined are not only very much solvable by making a new ECMA spec but either already solved in ES5 or solved in ES6.
> JS has callable attributes
> This is a shitty design decision
I strongly recommend not following the provided link, which is basically inane, uses the term "slots" in a rather disturbing manner and makes completely incorrect assertions e.g.
> Self [is] slot-based. This gives one substantial advantage: not having to specify that you want to move a block of code as a value explicitly. So you can do, for example in JS
// boom! we transplanted a method
someVar.smartMethod = another.otherMethod;
to my knowledge, you most definitely can not do that in such a manner in Self. Slots manipulation in Self can only be done through primitive messages (e.g. `_AddSlots:`, which takes an object whose slots should be copied into the receiver).> Hobjects are unusable for stable keys
> The mixup between objects and hashes is also a very bad idea, because it defies the premise that objects can have metadata on them - which alllow you to establish a rudimentary type system or at least any kind of introspection.
Magnificent baseless assertions. Javascript allows for object metadata through the prototype, or through properties (Object.defineProperty/Object.defineProperties) which — amongst others — allow setting non-enumerable properties. ES6 also introduces the concept of names. I'm not saying maps-as-objects is great, but I am saying these assertions are 1. wrong and 2. nonsensical.
> Fobjects are unusable for type systems since an object does not carry any type information.
> This one is a biggie. Even in the Ruby world, where everything is happily quacking like a duck, we often use the Object#class to get information about an object.
In ES5, the exact same behavior is provided by Object.getPrototypeOf providing access to the internal [[Prototype]]. Most implementations also provide direct access via the __proto__ property, which IIRC ES6 standardizes. And of course the `instanceof` operator has been there since ES3, but that's only ~13 years ago.
> Nothing will happen. Since ojects are hashes[...], our constant with the wrong key will be undefined, and will happily bleed into the callee. This makes stack traces huge.
'Nothing will happen' (and the related "What is the error that you will get if MyApp.Views.WidgetView is not defined yet? undefined is not a function of course! [...] And why? Simply because everything is a hash and the language is incapable of doing any kind of introspection." later) and 'objects are hashes' have nothing to do with one another. Hashmaps does not actually require unmapped keys to return nil or undefined. Javascript does because it is shit. Same for Ruby or Java. Python does not have that issue, accessing an empty key will raise a KeyError.
> and the language provides zero facilities for constants
All runtimes but MSIE (unless they've added it in IE11) already implement `const`, and it's standardized in ES6.
> Callback hell
> [...] In a normal situation this would have been fixed simply by adding a wait primitive to the language which would schedule the events when the result is still being fetched.
You mean, something like ES6's yield?
> Terrible exception handling
No objection there, javascript may well have a worse exception handling than Go, a language whose users try very hard to make others believe doesn't have exceptions in the first place. At least runtimes are finally trying to generate callbacks worth reading.
Not that this help when mixing with async, as your final traceback will lack 90% of the necessary context.
const implemented currently is very weird thing. It's more or less a read only variable, which silently ignores updates
var i = 0; for (var j = 0; j < 10; j++) { const C = i++; } // i == 10, C == 0 here
This is not something one would expect of constants honestly.
> You mean, something like ES6's yield?
yield is shallow, caller must be ready to cope with yielding explicitly, so it's not really a good replacement to proper coroutines that can pause arbitrary deep stacks.
TFA invokes C#'s `await` which is also cooperative and "shallow". Granted in C# there are APIs available for a synchronous function to "block on" an asynchronous one, but aside from that it's equivalent (the limitations are those of the underlying platforms, core.async loses the same features when doing from Clojure/JVM to ClojureScript/JS).
> so it's not really a good replacement to proper coroutines that can pause arbitrary deep stacks.
I agree, but I foremost went with the examples of "doing it better" which TFA provided, and TFA used `await` (if he'd used gevent or Erlang, I'd have been hosed)
> to my knowledge, you most definitely can not do that in such a manner in Self. Slots manipulation in Self can only be done through primitive messages (e.g. `_AddSlots:`, which takes an object whose slots should be copied into the receiver). This is probably true, I haven't used Self in anger so I will remove that.
> I'm not saying maps-as-objects is great, but I am saying these assertions are 1. wrong and 2. nonsensical. First thing you do to diss a statement is call it flat out nonsense.
> In ES5, the exact same behavior is provided by Object.getPrototypeOf providing access to the internal [[Prototype]]. Most implementations also provide direct access via the __proto__ property, which IIRC ES6 standardizes. And of course the `instanceof` operator has been there since ES3, but that's only ~13 years ago.
Why do there have to be `typeof`, `instanceof` and `.prototype`? Whereas you actually want one way to get at the object's type?
> All runtimes but MSIE (unless they've added it in IE11) already implement `const`, and it's standardized in ES6.
Maybe I should note that I was talking about JS as it is deployable today, to narrow the scope.
> You mean, something like ES6's yield? This one? http://stackoverflow.com/questions/2282140/whats-the-yield-k... > Terrible exception handling No objection there, javascript may well have a worse exception handling than Go, a language whose users try very hard to make others believe doesn't have exceptions in the first place. At least runtimes are finally trying to generate callbacks worth reading. Not that this help when mixing with async, as your final traceback will lack 90% of the necessary context.
If your stack records the necessary metadata it could easily give you something like `closured on line X in Items.fetchItems` insted of the 'anonymous function' 5 levels deep.
> They are not solvable by making a new ECMA spec.
I consider using the upcoming ("new") ECMA spec more than fair game to refute his assertions.
[0] although a number of its features are shimable, precede it by a few years, are already (possibly partially) implemented in some runtimes or are available through ES6 -> ES5 compilation via Traceur. See http://kangax.github.io/es5-compat-table/es6/
It sucks, but it's not quite as bad as the impression you get from "ES6 isn't done."
My view is: instead of ranting about languages (think about the meaning of that word), why not instead dissect what we do with them: programs, and find ways to improve them ?
The way to improve a lot of programs is to write them in a different language.
* lexical scope
* first-class functions
* prototypal inheritance
goes back to happily writing JavaScript
No seriously, you might be trying to use a fast glue/prototyping/event processing and browser deployed language to do something that should be done in a different environment. If your core logic task is algorithmic, consider C or Go and call that from your event framework. If it's data integrity/type-safety related, consider using your sql dialect.
(not a flamebait, but nosql is just a big distraction, please seriously consider postgres, it rocks, esp with json and plpgsql stored procedures that can be used to enforce data integrity braces and as independent unit testing for your data structures)
AngularJS, Express, node, and postgres is the most potent combination I've used in a long time.
Cheers,and good luck! F
I think everybody agree that different languages for frontend / backend development are the not the best solution, so JavaScript is a big step forward.
But i think soon it is necessary for a complete rebuild for a new language, with all the things included that we learned and invented from the "old" languages.
Dart, TypeScript, Coffescript, and the 1.000 other language Modifications / frameworks try all to fix a little part of the problem. Thats nice but annoying too.
Edit: I mean stuff like "callback hell", does it allow me to programm normally and still avoid blocking the loop?
As for callback hell, Dart has "Futures" which are basically Promises. If you like Promises, you could use Dart...or one of the many excellent Promise libraries for Javascript; the syntax is almost identical.
(The linked article savages Promises for no obvious reason. I happen to like the syntax. In any case, Dart uses the same syntax, so if you buy the articles criticisms, Dart is no panacea.)
A syntax would be something like the async/await support in C#. Or the async and let!, do! etc along with pipelines in F#.
Anyhow, what I was trying to say is that the linked article trashes Promises, and Dart has Promises, so Dart is at least in that respect not a solution.
I read about function* and yield, but this seems to require all functions to be rewritten.
Also I don't quite understand how this accomplishes to run 2 functions in parallel, if they are async.
But on other side I see JS bytecode as great alternative to Java and JVM. Modern languages usually include JS as compilation back-end.
Then don't use Javascript.
I'm not sure I can really appreciate another rant about how one language, framework, pre–compiler, VM, etc is terrible and everyone should stop using it.
Javascript's popularity has emerged organically. Its not because it has the best design. Its because it can get the job done and is browser based–and now server-side too. The browser is the next OS, the ultimate VM, if you will.
If you just stop picking at it and appreciate it for what it is...it is f'ing awesome.
People rant about JS not because it's shit, per se. Everybody knows that. They rant because they long for better languages that are available across all web browsers.
I would like to see a standardised CLR-style VM that allows language modules to be loaded as requested by a particular web page. Otherwise we'll just be replacing JS with what will probably be another old fashioned imperative language (see: Rust). We don't want that. We want freedom to use whatever language we want.
Like people have the choice. "Dont like HTML ? so dont write it" sounds stupid doesnt it.
On that note, at what resolution, if any, do embedded code snippets from GitHub and the like stop getting get cut off on the mobile? At 800x480 they get cut off even in landscape mode.
You can just do
if(myObjectToTest instanceof typeOfObjectIExpect)I'll stop there and let you expand the list if you want.
Turns out the whole computing world is built on top of this terrible tech which many people hate, yet somehow it's moving forward.
Personally, I find such people childish in a way.
It's a tool in a toolbox. I've never seen a mechanic rant about the substandard design of a standard screwdriver because he pulled it first despite actually needing a phillips screwdriver.
Well, yes. Your hyperbole is actually the current state of affairs. Progress doesn't mean the things you're building on are good, just that they can be made to work. In fact, progress is the evolutionary process of throwing away some of the old stuff, calling it shit, and replacing it with the new hotness.
I find most of the problems listed are related with dynamic type system of JS. These all can be solved most easily by a statically typed language.
Therefore the debate mostly is between static vs dynamic typing.
Or DEBUG_ON && Object.seal(this); at the end of every constructor.
Here, I've fixed "Hobjects" for you.
JavaScript allows you to write shitty code, but whether you do it or not is just a matter of skills and tools.
Fortunalty you can chose the language you want on the server.
Foul English is far, far worse in my eyes at least than JavaScript.
Having someone who wrote this on a website that spend 30% of the screen estate for page footer isn't very convincing.
* dart:async give you Futures (Promises in JS, no need for Q) and Streams
* dart:core and dart:collections give you real data structures like List, Map, Set, Queue, LinkedList, LinkedHashMap, etc. Much more comprehensive than underscore.js
* dart:html is much improved over JS's DOM, and have most of jQuery's functionality (see ElementList).
* New and upcoming standards like Shadow DOM, custom elements and template binding let you declaratively define your HTML template in HTML with data-binding, which is the foundation of frameworks like Ember, Angular, Knockout, etc.
* Polymer is a JS and Dart library for helping you write custom elements.
Also, the package system in Dart, pub, is very similar to npm and encourages smaller, focused packages rather than sprawling frameworks.Check it out, it's a very nice language and environment. But I'm on the Dart team, so I'm obviously biased.
Of course "best" is subjective, but I believe that the combination of Node.js's superior module system and the available packages, the clarity of the language (which actually surpasses Python) combined with the asynchronous single-threaded event-based model, and ToffeeScript syntax which makes asynchronous code read like synchronous code, makes this a superior platform.
I do think that Go is a wonderful evolution of C, but the module system or at least ecosystem is inferior to Node's, and the language syntax and concurrency approach (although very useful and better than Node's in many circumstances) is old-fashioned.
Many people don't trust, don't learn, and ultimately cannot objectively evaluate JavaScript, simply because it is too easy to use. [sarcasm] And everyone knows that real programmers don't use easy languages. Those are for beginners.[/sarcasm] That's the real explanation for most of the JS hate. The other part of it is the people who did try to learn it, found out there were problems, and then for whatever illogical reason decided that they couldn't use CoffeeScript or any other similar language to compensate for those problems.
I love JavaScript, but I totally agree with this.
The fact that many are eating gavno and are feeling happy about it does not make it healthy or tasty. The problem is when there are no other food to choose (browsers).
That's why I love backend development. I can choose a decent, compiled, strongly typed language and well-supported framework.
When faced with a new thing to learn, point out all the mistakes and flaws that give you reasons to not learn this shitty thing in the first place.
Or it could be the 3rd stage of grief :)
Oh by the way I agree with half of what he said (just half) but I still enjoy javascript.