

Four Solutions to the JavaScript Problem - johan_larson
http://short-sharp.blogspot.com/2015/03/four-types-of-solutions-to-javascript.html

======
bsimpson
Enough.

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
I 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"!?

~~~
rsuelzer
Some of the very reasons he lists as to why Javascript sucks are reasons I
actually love the language. ¯\\_(ツ)_/¯

~~~
tosh
Which reasons?

------
bcg1
> 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
`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.

------
xtrumanx
Is 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
Yes, 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.

~~~
bcg1
Woah! We're playing the Java 1.0 card??? Java is my language of choice most of
the time so I'm not hating, but seriously, Java 1.0?

I think you might be nitpicking... JavaScript is perfectly usable as is. They
even ship a js interpreter with OpenJDK since 1.6... why bother if Java is so
much better and easier to use? And also conflating a bug in Chrome with a
language deficiency seems fallacious.

~~~
lmm
> They even ship a js interpreter with OpenJDK since 1.6... why bother if Java
> is so much better and easier to use?

Because

> And also conflating a bug in Chrome with a language deficiency seems
> fallacious.

It's not a Chrome bug, it's a missing feature in every existing Javascript
implementation that only Chrome is bothering to add (though hopefully other
implementers will follow suit shortly)

~~~
lmm
First was meant to be: because there's real value in using the same language
on the server and the client (if only for parts of the code), and on the
client it has to be javascript.

(Also because certain libraries, in particular for async, simply don't exist
for Java because the sync version is "good enough")

------
izolate
If you're still whining about the "JavaScript Problem" in 2015 without trying
ES6, it's going to be hard to take you seriously.

~~~
steveklabnik
ES6 doesn't exist anymore, it's ES2015 now.

~~~
angersock
Really?

That's...silly, I guess?

~~~
steveklabnik
Eh. 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.

------
dmarg
The 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.

------
tosh
To 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
If 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
I hear you, I also was a bit confused with seeing the article on the front
page of HN.

------
roneesh
Recently 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
Honestly, 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.

------
AlexeyBrin
It 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_.

------
JeremyMorgan
JavaScript is infinitely easier to use the more you learn it. It's kinda funny
that way.

------
ld00d
I actually like JavaScript, and weak typing is one of the reasons.

~~~
tosh
Can you give an example re why you like JavaScript's weak typing
([http://en.wikipedia.org/wiki/Strong_and_weak_typing#Definiti...](http://en.wikipedia.org/wiki/Strong_and_weak_typing#Definitions_of_.22strong.22_or_.22weak.22))?

Or do you mean dynamic typing?

~~~
tracker1
Well, 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.

------
aberatiu
Problem? What problem?

------
itsbits
weak typing is something every javascript programmer likes.

------
codesuela
Solution 5: Use ES6

