

Modern JavaScript - telemachos
http://blog.rebeccamurphey.com/modern-javascript

======
nsfmc
I understand the desire for structured packages, but even in languages like
python that have 'the python way' or what have you, there are still plenty of
packages that don't quite fit. This isn't a problem with python, it's a
largely philosophical/religious issue that has much to do with the idiom or
mindset of the package (or likely the maintainer) at hand. But still, i don't
see this as a problem that _javascript_ has to address rather than say, a
problem that _libraries_ have to address.

You see this all the time in even jquery packages: are they $.pkg.method(elts)
or $(elts).pkgmethod() or is it $(elt).pkgmethod(spec) or .... and so forth.
Part of it is a matter of taste even if sometimes it goes against 'the jquery
way.' Again, this is so religious that it's often not even worth fussing over.

Blaming browser vendors or our ecma overlords for package standards seems like
a bit of a straw dog because _javascript_ isn't a package distribution
mechanism, it's a programming language. If you want to build _apt/npm for
browser js_ via require.js+jquery or your combination _du choix_ , then by all
means, but this isn't a failing of the language just as brew failing to
install mutt is _not_ a failing of ruby.

Certainly, there's bound to be some overlap in packages, but this happens
everywhere and who cares? underscore+jquery seems like a strange example
especially when the two are _complementary._ If the goal is to have a
"lightweight core" with "components that deliver specific, isolated
functionality" i mean, aren't we there _right now?_ And for where we're not,
as mentioned by other commenters, coffeescript and friends certainly seem to
be fighting the good fight.

I'm all for innovation, but i could do without "enterprise javascript" (isn't
that was es4 was and, i mean, i'm not exactly losing sleep over _that_
decision). For proof positive that we're already getting the 'roll your own'
strategy, check out the modernizr 2 beta (or, the less modest jq-ui).

If the point of modern js is that people are working together and optimizing,
then yay!! but if the point of modern js is that we need to abide by some
static discipline where each function only accepts a single spec object and
conforms to some require.js loading protocol then, umm.. thanks but no thanks.

------
jonnycat
Suddenly CoffeeScript makes a lot more sense to me:

"the language itself is held hostage by browser vendors, some of whom have
shown a strong inclination to not give a fuck about owning up to and fixing
their egregious mistakes"

So true. The JavaScript we've got now is the assembly language of the client-
side. We can't easily change it, but we have to start building better tools on
top of it.

~~~
mcantelon
>So true. The JavaScript we've got now is the assembly language of the client-
side.

Huh?

Javascript is a high-level, dynamic language with very nice metaprogramming
capabilites (compared to Ruby:
[http://fingernailsinoatmeal.com/post/292301859/metaprogrammi...](http://fingernailsinoatmeal.com/post/292301859/metaprogramming-
ruby-vs-javascript)). Totally bizarre to compare it to assembly.

~~~
jonnycat
I made the comparison in the sense that if you want to use another language on
the client-side (like CoffeeScript, for example) you end up compiling down to
JavaScript as the low-level implementation.

~~~
rhizome
Machine language, then. Assembler is compiled, too.

------
rimantas
The core message is good but I think Rebecca's obsession with jQuery just
kills here ability to deliver it. jQuery is not a problem. jQuery's popularity
is not a problem. Complex applications are the problem. People not knowing how
to structure complex applications are the problem.

Let's see the context there: jQuery is wildly popular, but it _is_ the right
tool for the job in most cases. Not all web pages jQuery is used on are
webapps. Not all webapps are GMail. Yup, jQuery is "DOM, AJAX and effects"
library which is great for trivial tasks. A lot of tasks _are_ trivial.

But there is no "jQuery divide", like there was no "Prototype divide" some six
years ago. These are just tools that can be misused. Sorry, Rebecca, but if
dojo were as popular as jQuery is the JavaScript land would not be any better
than it is now. It would be just a different tool misused, that's all.

The second point she is way wrong (again, IMHO) is the API. Don't you ever
underestimate the importance of the good API. When you have tools X, Y, Z
which more or less do the same with more or less the same performance, API is
the main differentiating factor it's the think you write and look at the whole
day. jQuery's API is awesome for many reasons. Dojo's is not.

Structuring complex applications is hard, no matter what language you use,
it's not some trouble only JavaScript has. True, JavaScript comes with a
couple more complications in that regard but these are minor in the context of
the problem.

What she is right about it's the lack of good examples going beyond the
basics. But I think the reason for that is that we are just on the way to find
out what works reasonably well. It will come, I hope.

So my point is: stop talking about jQuery and dojo. Talk about the core of the
problem (and any js lib is not the core).

Oh, and I would like to see Rebecca's take on backbone.js.

~~~
rmurphey3
I appreciate your feedback and understand that previous posts of mine have
framed this as a jQuery vs. Dojo debate; I tried particularly hard not to do
so in this post, and I think you'd be rather hard-pressed to say that this
post was a "jQuery vs. Dojo" diatribe. Yes, it linked to my Berlin slides, but
that's simply because a post in response to them is what got this whole post
percolating in my head to begin with.

The fact is, though, jQuery and Dojo are the two libraries with which I am
quite familiar, and so they are the two libraries I am most able to compare.
Having used both, it is easy to see the weaknesses of ... both! I truly
believe there _is_ a "jQuery divide" -- there are people who think jQuery is
what there is to know of JavaScript, and that it can solve all of their
problems; then there are the people who know there is more, either because
they have always known or because, like me, they've discovered it through some
painful mistakes.

What I am asking for, in this post and in my Berlin talk, is for the people
who know there is more to take some responsibility for bringing the others up
to speed, to show people what can be done if you leave behind the "get some
elements, do something with them" mentality.

None of this is to say that jQuery is not a useful tool, and the right tool in
so many situations! I have used it, I have contributed to it, I have taught
it, I have recommended it. Its API is seductive and its API is a huge
contribution it has made to the JS landscape. The point, though, is that it's
_just_ an API -- an API that can be and has been be readily replicated. My
experience has been that other libraries' APIs can have their own elegance,
once you get used to them. The problem is that the appeal of jQuery's API I
think is what can lead people to keep approaching problems in a DOM-centric
way long after it makes sense. I do not fault jQuery for this, but I think as
a wider JavaScript community we do well to discuss -- and not in an us v. them
way! -- other viable approaches that exist.

Finally: Backbone is a viable entry in the field, and I am eager to see more
complex examples (to-do list applications fall far short of this) that use it.
I haven't used it personally, but I mostly like what I see and have heard good
things about it. Unfortunately it had just come out right before my Berlin
talk, and while I may have mentioned it in my actual talk, it isn't in the
slides. (That said, I do cringe a tad that its examples suggest
(<http://documentcloud.github.com/backbone/#Model>) that a "Sidebar" is a
thing that should be a model.)

~~~
jashkenas
Oops -- that's a very good point about the Model example being a bad one -- I
was just trying to use something visible, in order to see the "change" event
binding in action. Perhaps we should swap it out for something more model-y.

These days, if you're looking for complex Backbone examples, there's a bounty
to choose from:

* <http://getflow.com>

* <http://m.soundcloud.com>

* <http://basecamphq.com/mobile>

* <http://getcloudapp.com>

* <http://www.documentcloud.org/public>

~~~
rmurphey3
One other question: are there Backbone examples small enough to digest but
large enough to be more authentic than a to-do list? This is where I struggle
to come up with good teaching examples -- a whole real-world app is simply too
much to take in when one is trying to transition to a JS app mindset (and of
course the code is usually minified/obfuscated), but examples like to-do lists
are _so_ simple that they don't show how a tool addresses actual real-world
problems.

------
spenrose
Excellent stuff. One issue Murphey's slides mention only glancingly is the
Javascript-as-visual-design-aid vs. Javascript-as-programming-medium conflict.
If jQuery is DOM-centric, well, a whole lot of JS jobs are "make it look
professional using HTML, Javascript, Photoshop, and your trained artist's
eye," so why shouldn't it be DOM-centric?

That suggests those who fight the good fight from a software engineering
perspective will not win with a frontal assault. C++ and Perl were both
subject to years intense pressure to rethink their basic assumptions; both
refused* and carried on with more-or-less the same group of folks who loved
them warts-and-all.

In other words, the evidence suggests that it will be easier to move forward
by organizing and strengthening those who agree with Murphey (and Crockford,
etc.) than by converting those who, to use her phrase, "don't know what they
don't know" but can do amazing things with Photoshop.

* I acknowledge there is an argument to be made that Perl 6 contradicts my assessment. My point is that Perl 6 has not brought a bunch of previous Perl critics into the fold.

------
ww520
I wish Javascript has an easy to use unified library/module system. Something
like,

    
    
      require "http://ajax.googleapis.com/js/sha1.1.3.1"
    

In the browser, the browser would download and cache the the library and all
its dependencies. For the server side, the server environment would download
and cache the library and its dependencies in the same way.

Edit: Ha, a reply was deleted so fast that I didn't have a chance to reply to
it. To clarify, Sha1.1.3.1 was meant to be an example of a library, not the
SHA digest of a library, though that would be a nice feature. Also "require"
should be a feature of the language, not using the html <script> tag so be
able to work in the server environment.

~~~
mckoss
If library writers were to use CommonJS Modules (i.e. just use require() and
exports), we'd be most of the way there.

Require.js and AMD still feel like they are not appropriate in all scenarios
(e.g., I really don't want or need a "loader" in simple single page
applications).

This is my suggestion for a very light weight way of using CommonJS Modules in
the browser which is agnostic about how your scripts are loaded.

<http://github.com/mckoss/namespace>

------
DjDarkman
The problem is that browsers don't deal with libraries. You can implement a
module and a script loader system, but in the end of the day you will
concatenate most scripts for faster download and initial page rendering.

The big problem is that we still have: IE6, IE7, IE8 and probably IE9 too They
are too slow, they will not allow you to write nice modularized code.

------
pavel_lishin
Argh, I hate reading slides without the accompanying audio/video, because I
feel like I miss out on 90% of the context.

~~~
rmurphey3
As a speaker, let me just say that I have yet to figure out how to handle
this. When I'm presenting, I want people listening to me, not reading the
slides. When people are consuming the slides online afterwards, they can
quickly get misconstrued without the context of my spoken words. All of that
said, I'll add a link to the video from the blog post :)

~~~
Xurinos
I have come to the conclusion that communicators must present to different
audiences in different formats. Slides used in public speaking are no
different from hand gestures. Slides posted online for the same speech have to
be touched up or completely redone for the new online audience. The audience
who heard my speech _might_ benefit from having a copy of my slides as memory
cues.

