Profile

Cover photo
James McKay
Works at Houses of Parliament
Attended Selwyn College, Cambridge
1,664 views
AboutPostsPhotosVideos

Stream

James McKay

Shared publicly  - 
 
Proposed new programming jargon: Brown M&Ms. Seemingly trivial, easily-missed acceptance criteria that bear little relationship to the rest of the user story but are actually much more important than you think.

From a standard contract rider that was inserted by the rock band Van Halen into their technical specifications. It specified a bowl of M&Ms in the dressing room with all the brown ones removed, on pain of cancellation of the entire concert with full compensation. They used it to check whether their hosts had read the specification correctly.

http://www.snopes.com/music/artists/vanhalen.asp
1
Add a comment...

James McKay

Shared publicly  - 
 
Still very quiet here.

Somebody let me know when it warms up. You'll find me on The Other Place. Or Twitter. Or Github.
1
Add a comment...

James McKay

Shared publicly  - 
 
Proposal: Here on Google+, we start referring to Facebook as "The Other Place."
1
andrew asche's profile photo
 
good one
Add a comment...

James McKay

Shared publicly  - 
 
How good is your JavaScript?

Version 2.0:

0. You avoid it altogether and insist on using Silverlight instead.

1. Your JavaScript skills are limited to searching the web for jQuery plugins and snippets of code to copy and paste.

2. You are able to do simple things with jQuery, such as effects, validation and possibly Ajax, but you have no idea how it works. For example, you don’t know exactly what data structure $('some-selector') returns. You talk about “writing jQuery code” rather than “writing JavaScript code.” Your scripts are either very short and simple or else contain a lot of duplication. You have a vague idea what setTimeout() does but you've never used it.

3. You understand the difference between jQuery and JavaScript and have a reasonable idea of how they relate to each other and the DOM. You are able to say what data structure $('some-selector') returns and what the var keyword does, though you may be a bit hazy about JavaScript’s exact scoping rules. You are able to write somewhat more complex scripts but they are all procedural in nature. You don’t understand the JavaScript object model or concepts such as closures and callbacks. You aren’t sure what the point of the (function() { ... })(); construct is. You believe that setTimeout() is supposed to take a string as its first argument.

4. You understand the JavaScript object model and more complex concepts such as closures, regular expressions, callbacks and exception handling, and are able to use them effectively, though you do not necessarily know how to implement class based inheritance. You know what the (function() { ... })(); construct is for and are aware of ECMAScript 5’s "use strict" directive. You are aware that setTimeout() can take a function instead of a string as its first argument.

5. You have used or investigated JavaScript frameworks such as backbone.js, knockout.js or ember.js; templating engines such as mustache.js; JavaScript unit testing frameworks such as Jasmine, Mocha or QUnit; and asset bundling and minification tools. You are able to implement class-based inheritance in JavaScript. You have a fairly wide-ranging understanding of the quirks of the language such as automatic semicolon insertion or the difference between == and ===. You know that passing a string as the first argument to setTimeout() is a bad practice.

6. You are able to optimise JavaScript for performance or security, and to identify and resolve memory leaks. You have incorporated JavaScript unit tests into your Continuous Integration process and use full-blown test-driven development for your client-side code. You are experienced with CoffeeScript and node.js.

7. You have built complex projects such as compilers, server-side applications or complete frameworks using JavaScript.
1
Add a comment...

James McKay

Shared publicly  - 
 
Just how are you supposed to handle exceptions in a node.js web application???

If you don't do anything, it doesn't just return a 500 error page, it crashes your entire application. To stop it doing that, you need to add an uncaughtException event handler:

process.on('uncaughtException', function (err) {
console.error(err);
console.log("Node NOT Exiting...");
});

But -- and it is a big but -- if you do this, you also need to call end() on your response object. Only one problem there: this event handler doesn't have access to the response object in which the exception was thrown.

The answers I've seen on Stack Overflow suggest that you should return errors as a status code from your event handlers, rather than throwing exceptions:

http://stackoverflow.com/questions/7151487/error-handling-principles-for-nodejs-express-apps
http://stackoverflow.com/questions/5816436/error-handling-in-asynchroneous-node-js-calls

You're kidding me, right? Back to the bad old days of C++ error codes? Not to mention the abomination of having to put Pokemon exception handling in all your callback functions?

One and a half hours into attempting to learn node.js, this leaves me far from impressed. Or am I missing something?
1
David Welch's profile photo
 
If you're working with Node raw (aka no other framework) then yes, this can be pretty ugly.

I'd take take a look at ExpressJS and some of the other popular "middleware" frameworks. Essentially, you'd have your middleware pass any exceptions to the 'next' function parameter which causes the error handler registered to app.error(...) to be invoked.

Unfortunately, uncaught exceptions (such as those caused by logic errors in your own javascript) will bubble all the way to the top of the stack and crash your app (unless, as you said, you register a handler for the process 'uncaughtException' event). The only method I've thought of is to create something similar to Java's ThreadLocal cache for responses that could be accessed by your failsafe handler... but that'll be difficult to create given Node's non-blocking perks.

In the end, it's probably best just not to have exceptions ;)
Add a comment...

James McKay

Shared publicly  - 
 
There's a simple solution to making Google+ more lively. Integration with Twitter.
1
Add a comment...

James McKay changed his profile photo.

Shared publicly  - 
1
Add a comment...
Story
Tagline
Web developer to the rich and famous
Education
  • Selwyn College, Cambridge
    Natural Sciences, 1989 - 1992
Links
Work
Employment
  • Houses of Parliament
    2008 - present
Basic Information
Gender
Male