6 ms·
Four Solutions to the JavaScript Problem
- izolate 12y agoIf you're still whining about the "JavaScript Problem" in 2015 without trying ES6, it's going to be hard to take you seriously.
- Zikes 12y agoThe "JavaScript Problem" is not about what JavaScript can or can't or will be able to do, it's about JS being the only option available, period. The web needs a bytecode language that other languages can compile to. Some people say JavaScript can be that bytecode, and asm.js is a big step in that direction, but for the web to grow to its full potential developers need the freedom to express their ideas in the languages that suit them best.
- tracker1 12y agoWith the number of languages that transpile to ES5 or asm.js, I don't think that's really the problem.
- steveklabnik 12y agoES6 doesn't exist anymore, it's ES2015 now.
- angersock 12y agoReally? That's...silly, I guess?
- steveklabnik 12y agoEh. I feel pretty neutral about it. It seems to reflect the mentality of shorter, more frequent updates to the language. Nobody wants another loooooooong wait like the current one.
- izolate 12y agoI know. But my comment was directed at OP, who seems pretty unfamiliar with JS, and would more likely know what ES6 is. Also, I didn't want to write "2015" twice.
- bsimpson 12y agoEnough. You don't like JavaScript. We get it. The number of people who don't like JavaScript are as "well-documented and well-understood" as your problems with the language, as are the solutions you mentioned (use a subset of JavaScript or something that compiles to it). I'm more than happy to read novel criticisms or novel ways to improve the language, but the ecosystem really doesn't need yet another blog post rehashing common knowledge (anyone who cares knows about The Good Parts, CoffeeScript, and GWT) and beating the "JavaScript sucks" horse.
- dmarg 12y agoI completely agree. I just posted a comment pretty much on these same lines but I guess your comment got there first. The hate on JavaScript "horse" is past being dead. Maybe we can start a Javascript is ok/has good parts but is here to stay "horse"!?
- swalsh 12y agoDid you know that income equality is a large problem in the US? That social security/medicare/medicaid are looming issues, and that the solution to climate change requires drastic retooling by factories, and habit changes by consumers? To me, removing javascript in its current form from the web is in the same class of insurmountable issues. To "Solve" the issue action needs to be taken by literally everyone who is involved in the web. To do that the first step to that action starts with admitting there is a problem. I'm in favor of beating the dead horse, because every once in a while, i see it try to breath again.
- deleted 12y ago
- dmarg 12y agoThe post starts off with: "The JavaScript Problem is two fold: JavaScript sucks, but we need JavaScript." Can we just got over this JavaScript sucks issue. We get it. There are a lot of people who hate JavaScript but we know the issues so start using JS the proper way.
- AlexeyBrin 12y agoIt is difficult to take seriously an article that starts with The JavaScript Problem is two fold: JavaScript sucks, but we need JavaScript. and ends with Where you want to be on this continuum depends on how much you hate JavaScript.
- xtrumanx 12y agoIs option number 1 "Use JavaScript Carefully" really that hard? Bjarne Stroustrup's quote seems more and more relevant to me every time I hear complaints about JavaScript. "There are only two kinds of languages: the ones people complain about and the ones nobody uses." Edit: Well this is hilarious. I started writing this comment with no comments on the page and by the time I submitted it several posts seem to complaining about the constant complaints about JavaScript. Great minds think alike or JS devs are super-defensive?
- lmm 12y agoYes, it's really that hard. When Chrome fixes "undefined is not a function" and ES6 arrives with lexical scoping and classes, Javascript will reach approximately the functionality of Java 1.0 (plus lambdas, which sure, are a big flaw in Java 1.0) - only twenty years behind the state of the art for slow-moving large companies. I'm finding it hard to find the words to express how much better a real type system makes programming, but let's just say it would eliminate all the angst about callbacks and promises without breaking a sweat. Writing a big program in Javascript is like... it's like writing a novel in Up Goer Five style. Every time you think of something you have to stop and disassemble it into smaller pieces so that Javascript can talk about it. You copy-paste phrases that represent a word in your head, because the word in your head can't be represented in that language except as this four-word phrase that even then doesn't really capture what you're talking about. You write a paragraph and feel really proud of yourself, and then you realise that what you actually wanted to say was just a single sentence.
- xtrumanx 12y agoI'm not too knowledgeable about type systems but to me "undefined is not a function" is simply the by-product of a dynamic/weak type system. That complaint can be equally applied to ruby, python, etc. Can't I misspell a property or variable in such languages and get a similar error to "undefined is not a function"? Yet I don't see people complaining about them as much as JavaScript.
- lmm 12y ago
- aberatiu 12y agoProblem? What problem?
- codesuela 12y agoSolution 5: Use ES6
- bcg1 12y ago> And really, there are only four classes of solutions. There might be a fifth solution: learn JavaScript. Its not actually that hard to be productive - I realize mastery always takes time and effort, but its pretty quick to get started and be able to write some decent stuff. I don't primarily code in JS but I keep it near the top of my toolbox. I'm not up to date with the latest and greatest (which I'm sure it getting better and better) but even in 2011 when I had the opportunity to do some stuff with node, I was pretty satisfied with what the language provided. Some of the syntax was a little verbose, but I can type pretty fast so no sweat. I wouldn't be surprised if Crockford's jslint rules are not that relevant anymore... around 2008-2009 when I did more web stuff I used to make sure all my scripts could pass with `browser = true && global jQuery` (or whatever the format for the hint was), but even at that time much of that advice was starting to seem irrelevant.
- tracker1 12y ago`jslint`'s community mindshare was replaced `jshint`, and more recently `eslint`, which are configurable with a lot more options and some pretty sane defaults. Most of it comes down to opinion... I like comma-first and a few other differences from the norm. It's easy enough to change eslint to suit your needs. I'm using BableJS lately also, as even io.js options are still a bit incomplete by comparison. Modern (ES6/7) JavaScript is really nice to use.
- JeremyMorgan 12y agoJavaScript is infinitely easier to use the more you learn it. It's kinda funny that way.
- roneesh 12y agoRecently as an exercise I worked through the examples in Sandi Metz's "Practical Object-Oriented Design in Ruby" using Javascript. To approximate her examples I did have to do a few pretty unintuitive things (for example use .call to invoke parent constructors, whereas in Ruby the native syntax allows it). But it wasn't anything that mind-bending to wrap your head around, and it was learned in just a few minutes (learn is a strong word, remember, realize or connect the dots might be more applicable). That I suppose is the core of the "I hate JS" arguments, to get it to do what you want, it has a slightly unintuitive non-syntactical way of solving it's problems. That of course, is only the case if you intend to replicate the programming styles the syntax of other languages gives you. I don't think you should. And now with ES6, we have those other styles in our syntax, so it's even less of a problem. Hate on JS all you want, but it's probably not so amenable to you because you're using a metal file when you really need a belt sander, close but not quite right.
- tracker1 12y agoHonestly, I'm not a big fan of Class-based design... I really feel that JS lends itself much better to a system of functions with composition. You can create a number of stand-alone functions that take an object that is operated against as a parameter and return a value, or modified object. You can now test these independent functions as modules without a lot of distractions that come from side effects and state. With that in place you can bind those functions into a composed object (state), and use that in the rest of your application. You have composition, encapsulation and testable code that is just plain difficult to reason about when you are using Class-based inheritance and trying to test against it. I actually love JS... it has its' quirks, but I find the flexibility it offers to exceed what most other languages offer for most tasks. Using small function libraries and modules, I find that I can orchestrate much larger operations far more easily than can be done with other systems (usually). All of that said, I also love C#, and use it very differently. People should stop trying to walk in water, and just swim.
- tosh 12y agoTo up the meta-level here: why are all comments on this discussion so far allergic reactions to JavaScript criticism? Reminds me of when I moved from PHP to Ruby & Python reading arguments that people should just shut up about the 'minor' problems PHP has and that it isn't going anywhere. Well JavaScript _really_ isn't going anywhere. It is here to stay. But that doesn't mean one should stop complaining about where JavaScript falls short. There are multiple angles to get out of this mess: * Local optimization (trying to fix the things that can be fixed and not introducing new problems: very hard, very slow process, think quicksand). * Global optimization (Dart, ClojureScript, Elm, GWT. Ambitious compile-to-js languages that give you a ton by moving away from what makes JavaScript JavaScript) * And something in between like compile-to-js languages that stay closer to JavaScript like CoffeeScript, TypeScript that add to it and/or retract stuff. The fascinating thing here imho is that especially the ambitious approaches to getting us out of the mess we're in lead to faster local improvements (here just some of them) … * SIMD support: Dart nudged JavaScript to add SIMD support, John McCutchan of the Dart team even worked on that * Classes: Dart, TypeScript, CoffeeScript * Briefer, more expressive syntax: CoffeeScript, Dart, TypeScript * Optional types: Dart, TypeScript, … * VM Performance: Dart JavaScript got better as a language as well as a compilation target, especially in the last few months. This is great for all of us. It happened and happens because people are not satisfied with the status quo and don't shut up about it and do what they can to go beyond what's 'good enough'. The day it becomes unacceptable to criticise the status quo is the day innovation dies. I hope the JavaScript community at large is far away from that mindset.
- bsimpson 12y agoIf the OP criticized JavaScript, I would have been interested in reading it. He didn't. He merely waved his hands at the strawman "JavaScript sucks" and parrotted back a bunch of already well-known alternatives. I don't take issue with the OP criticizing JavaScript - I take issues with the article for lacking substance and with the 20 upvoters who signaled it would be a good use of time to read.
- tosh 12y agoI hear you, I also was a bit confused with seeing the article on the front page of HN.
- ld00d 12y agoI actually like JavaScript, and weak typing is one of the reasons.
- tosh 12y agoCan you give an example re why you like JavaScript's weak typing (http://en.wikipedia.org/wiki/Strong_and_weak_typing#Definitions_of_.22strong.22_or_.22weak.22 http://en.wikipedia.org/wiki/Strong_and_weak_typing#Definiti...)? Or do you mean dynamic typing?
- ld00d 12y agoNot having type casts everywhere.
- tracker1 12y agoWell, if you are processing CSV or XML data-stream for import operations into a foreign system, JS is a very natural language for this type of work. Being able to translate anything into a 32-bit integer value with ~~ for example, or understanding falsy-truthy operations can make text composition easier as well. The only real gotcha in validation is when you want something that is a numeric-string or a number to be a number, and anything else to be a null. Outside of that case, I find that dealing with data migrations/translations in JS is FAR better in practice than most of the options I've used. Especially when you compare to the likes of say C, C#, Java etc... Yes, you can use strong XML validation, but it tends to produce a lot of errors that are recoverable in JS.
- itsbits 12y agoweak typing is something every javascript programmer likes.