CoffeeScript book micro-review

So recently I got the chance to help out a friend with proof-reading his CoffeeScript book. Now before you get all: “but you’re a JavaScript guy, what could you possibly know about CoffeeScript?!!”, just remember, CoffeeScript is really just transcompiled JavaScript with some sugar and stuff.
Initially I was a little sceptical about CoffeeScript, but soon realised it is actually a worthwhile language by itself.
I think Pat says it best himself:

My early reaction to JavaScript was dismissive. Strangely, or not, years later I would be working almost exclusively in it. My early reaction to CoffeeScript was also dismissive. “Here we go,” I thought. “Yet another tool created because people don’t understand JavaScript!” I was wrong about CoffeeScript just like I was wrong about JavaScript.

CoffeeScript is not about avoiding JavaScript—it is about understanding JavaScript. This applies to both people who are already familiar with JavaScript and people who are not familiar with JavaScript. Learning CoffeeScript helps people to understand JavaScript. At the same time, for many people it makes writing JavaScript programs simpler and more enjoyable, which means that it makes sense for them to use CoffeeScript instead of JavaScript.

Anyway, here is a plug for the book: CoffeeScript in Action is 43% off through June 2, 2014 with code pbrcosc at www.manning.com/lee/, you should buy it now, it is excellent, I assure you.

Read on for the micro-review
Read more

jQuery be nice

Getting jQuery to behave with very large queries and DOM manipulation, for when you get “Unresponsive script” errors…

We’ve all been there – a giant page with lots of repeated DOM elements that we need to do … something … with. In my case it was a very large form with 3000+ fields that all needed to be validated; we were using jQuery unobtrusive validation, for the sake of maintainability and a “sane” way to integrate with MVC’s view models, we were sticking with this.
Now before you think the page should be re-factored, there simply wasn’t time in the schedule for this, plus design constraints dictated that the page worked in a certain way.

So anyway, the style in which the unobtrusive validation script is designed I dub “big hammer”, it basically initialises each field one-by-one at startup – this process takes 10+ seconds on the page in question, on a really nice machine in Chrome. On an older XP box with IE7, it could sometimes time out. Clearly something is being done wrong.

Right, so by now you’re thinking “cool story, bro”, but I am getting to the point…
Read more

Augment objects, for when extend is not enough

Don’t you hate it when you have two semi-complex configuration objects, and you need to “mash” them together?
Here is what I mean, is take these objects:

var cfg = {
        plugins: [‘a’, ‘b’],
        config: {
                show: {
                        immediately: true,
                        order: ‘natural’
                }
        }
},
options = {
        plugins: [‘c’],
        config: {
                show: {
                        order: ‘reverse’
                }
        }
};
 

And mash those into:

{
        plugins: [‘a’, ‘b’, ‘c’],
        config: {
                show: {
                        immediately: true,
                        order: ‘reverse’
                }
        }
}
 

If you use jQuery extend, by default the values in cfg are overwritten by those in options.
Read more

Long poll jsonp

UPDATE: Implemented changes to the code as suggested by Akeru, thanks!
UPDATE2: Updated to the newer version of jQuery-jsonp, thanks Julian, the Ugly spinner loading is now gone!

Go straight to the code
or
Download it in a zip file

So, whatever happened to comet? Wasn’t it supposed to save the masses from wasteful ajax polling? I certainly appreciate Alex Russel’s work on the matter, but it really seems as though this very useful technology is falling to the wayside. I think this is mainly due to the difficulty and requirements of a successful implementation on the most popular web server, the main problem is Apache’s use of threading, this post explains the problem eloquently. Of course Apache have a whole project that deals with this issue to a degree, but I don’t think that it is easy to implement, once you dig a little into the documentation, you quickly see that this is not really a thing that just works out of the box… You need to read a book on the subject first. That is a bit of a deal-breaker for me; after all, the technique is not that difficult to understand, so why should you need to read a whole book to implement it? Read more

CSS Formatter

So I created a CSS parser and formatter on the weekend; I think it’s kinda neat as it formats CSS “just the way I like it”.
Why would I do this, when there are so many CSS formatters available? Well, the aim of most formatters is to “optimise” the CSS
(ie: make it as small as possible), whereas the aim of my formatter is to make it as readable as possible. Read more

WSG meeting was fun!

Had a ton of fun presenting, and met some interesting people. Even some that want to help out with PAX which would be great!

Thanks very much to Russ for organising the night!!!

The future of Mozilla

I attended the free Mozilla booze-up Labs event the other month; it was quite interesting; Ben Galbraith spoke about what Mozilla is up to, and what they are planning in the near future… It was interesting because I got the feeling that whilst they have a few interesting projects in the pipeline, they don’t really have anywhere specific to take their browser engine; it has gotten to a point where it performs on par with all the other browsers, and all the other browsers perform on par with it.
So where should Mozilla go from here? I think it is blindingly obvious what they could do, though I don’t think they’re gonna like my suggestion… Before I mention what it is, lets take a closer look at Mozilla. Read more

WSG Nov 11th

I’m speaking at the WSG about my PAXJS framework next month! You can register at the WSG website! I always enjoy the WSG meetings, there is a great mix of people from different areas and backgrounds, and much discussion anout web development in general. Note that the cost is $10 to attend.

Manage your data with the jQuery Collections plugin





Download the script

It’s a classic problem: you have a small set of data records that you want your users to interact with at the same time, usually with a need for ordering of the records. I’ve seen this exact problem pop up in just about every project that I’ve every worked on. The most obvious solution to the problem is an inline-editable datagrid-style widget. Often this provides a “good enough” solution, and many UI designers convince their users to integrate this type of widget, as it is relatively easy to do.
This sometimes leads to dis-joined user experiences, inconsistent look & feel, depending on what solution is employed and how much time you spend on integrating it.

Read more