Categories
Writing

Learning Node: Well, one Rails aside

Recovered from the Wayback Machine.

After denouncing the use of Ruby and Rails terms to describe Node and Node modules, I must now confess that I did use a Rails resource in the section on MVC in Chapter 6.

The Rails Guide has an absolutely beautifully written overview on MVC and routing, Rails Routing from the Outside In, I used as inspiration for the design of the MVC section in Chapter 6.

However, in my defense I’ll note that most of this overview really doesn’t depend on knowing either Ruby or Rails in order to benefit from the writing. It simply and easily demonstrates a mapping between HTTP verbs, routes, controller actions, and database CRUD (Create-Read-Update-Delete) probably better than anything else I’ve ever read.

Categories
Writing

Learning Node: Concepts and TOC

Recovered from the Wayback Machine.

The Learning Node book is far enough along so that I can publish the Table of Contents for the book and it shouldn’t differ significantly from the TOC for the book when it’s finished. The chapters with an expanded TOC are those already finished—the rest are still in work. Before I print out the TOC, though, I thought I’d write about some of the underlying themes that helped define the book structure and determine the direction of the writing.

The primary theme behind the book is simple: you don’t have to have prior experience working with Ruby or Rails in order to understand this book.

Seems like a silly thing to say when we’re talking about a technology based in JavaScript, but you’d be amazed at how much a Ruby/Rails background assumption flavors interactions in the Node world. One of the real issues I found with Node in the last year is that all too often explanations are given in Ruby or Rail terms. For instance, when a person asked about what framework to use, another answered him that “Express is like Sinatra, while Geddy is more like Rails”. Well, that’s just peachy…if you’ve worked with Ruby, Sinatra, or Rails. If you haven’t then the answer might as well be Martian for all the useful information it provided.

My book assumes you have experience with client-side JavaScript, and you’ve mainly worked with more traditional web/Ajax type of development. There are no references to unknown technologies, and no esoteric Rubyesque or Python asides. Even when I cover how to create an MVC (Model-View-Controller) application using a popular framework, Express, I do it in such a way that you can follow along no matter how much experience you’ve had with MVC.

This doesn’t mean I talk down to my readers, but I happen to believe that Node is actually a lot easier to use than may be first apparent, and one major roadblock to understanding are all the assumptions shared among many of the current practitioners.

Another underlying theme to the book is dealing with a second major roadblock to Node adoption: lack of documentation. Or I should say, uneven documentation. Some of the third-pary modules are nicely documented, others have no documentation, and the Node modules, themselves, fit somewhere in-between. There are tutorials and other reference material—some very good material, in fact— but it’s scattered about and you have to hunt for most of it.

Having said this, the one thing the Node modules all seem to share is really nicely written code. They all seem to make excellent use of white space, good variable naming conventions, and effective use of in-line comments. The objects aren’t bizarrely defined, the coding isn’t excessively cryptic, the methods aren’t overlong, and the purpose of most can be deduced without too much trouble. Once you have a good grounding in how Node works, you can discover what you need to know about how a module works just by looking at the source.

Of course, it would still be nice if Node module developers provided a little more documentation.

(I won’t even get into the odd fascination with light gray text on darker gray backgrounds that seems to be shared by so many Node developers. Pure headache inducing web design.)

The third underlying theme in the book is to focus on providing the tools so that you can build the awesome applications—not try to create awesome applications in the book to impress you with how great I am. My examples are focused, they’re simple, they’re clean, and they show how things work. That’s it. When I want to learn how to do something, I want simple, clear examples that demonstrate exactly what I need—no more, no less. I don’t want fancy and I don’t want something overly complex. I assume most folks feel the same way, and write accordingly.

I’m also not especially creative in my writing—I try to avoid the cutesy, and definitely stay away from the profound. I’m writing a book on computer technology, not Gone with the Node.

I don’t know if all of this leaves you more interested or less, but best to set expectations right from the beginning.

My editor, Simon St. Laurent, has mentioned about the possibility of releasing my book under the Early Release and/or Rough Cuts program. I hesitate doing so, because I’ve seen reviewers who have been extremely critical of a book primarily because it is Early Release and/or a Rough Cut. Seems to me that the early release programs are equivalent to firewalking: may be great when it works, but the consequences when it doesn’t can be unfortunate.

Stay tuned on this one. If I do release early, the book will probably be available in May; otherwise, July.

Now, on with the TOC:

    • Chapter 1: Node.js, Up and Running
      • Setting up a Node Development Environment
        • Installing Node on Linux
        • Partnering Node with WebMatrix on Windows 7
        • Updating Node
      • Node: Jumping In
        • Hello, World in Node
        • Hello World, from the Top
      • Asynchronous Functions and the Node Event Loop
        • Reading a File Asynchronously
        • A Closer Look at Asynchronous Program Flow
      • Summary: Why We Like Node
    • Chapter 2: Interactive Node with REPL
      • REPL: First Looks and Undefined Expressions
      • REPL’s Own Unique Hello World
      • Multiline and More Complex JavaScript
        • REPL Commands
        • REPL and rlwrap
        • Creating Your Own REPL
      • Stuff Happens. Save Often.
    • Chapter 3: The Node Core
      • Globals: Global, Process, and Buffer
        • Global
        • Process
        • Buffer
      • The Timers: setTimeout, setInterval, clearTimeout, setInterval, and clearInterval
      • Servers, Streams, and Sockets
        • TCP Sockets and Servers
        • HTTP
        • UDP/Datagram Socket
        • Streams, Pipes, and Readline
      • Child Processes
        • child_process.spawn
        • child_process.exec and child_process.execFile
        • child_process.fork
        • Running a Child Process Application in Windows>/li>
      • Domain Resolution and URL Processing
      • Utilities and a JavaScript OO Refresher
      • Events and EventEmitter
    • Chapter 4: The Node Module System
      • Loading a Module with Require and Default Paths
      • External Modules and the Node Package Manager
      • Finding Modules
        • The Colors Module: Simple is Best
        • Optimist: Another Short and Simple
        • Exploring JSDOM
        • Underscore
      • Creating Your Own Custom Module
        • Packaging an Entire Directory
        • Preparing Your Module for Publication
        • Publishing the Module
    • Chapter 5: Control Flow, Asynchronous Patterns, and Exception Handling
      • Promises, No Promises, Callbacks Instead
      • Sequential Functionality, Nested Callbacks, and Exception Handling
      • Asynchronous Patterns and Control Flow Modules
        • Step
        • Async
      • Speaking of Node Style
    • Chapter 6: Routing Traffic, Serving Files, and Middleware
      • Building a Simple Static File Server from Scratch
      • Middleware
        • Connect Basics
        • The Connect Middleware
          • connect.static
          • connect.logger
          • connect.parseCookie and connect.cookieSession<.li>
        • Creating a Connect Middleware
      • Routers
      • Proxies
    • Chapter 7: The Express Framework
      • Express: Up and Running
      • The app.js File in More Detail
      • Error Handling
      • A Closer Look at the Express/Connect Handshake
      • Routing
        • Routing Path
        • Routing and HTTP Verbs
      • Cue the MVC
    • Chapter 8: Express, Template Systems, and CSS
      • The Embedded JavaScript (EJS) Template System
        • The Basic Syntax
        • Using EJS with Node
        • Using the EJS for Node Filters
      • Using a Template System (EJS) with Express
        • Restructuring for a Multiple Object Environment
        • Routing to Static Files
        • Processing a New Object Post
        • Widgets Index and Generating a Picklist
        • Showing an Individual Object and Confirming an Object Deletion
        • Providing an Update Form and Processing a PUT Request
      • The Jade Template System
        • The Quick Nickel Tour of the Jade Syntax
        • The Use of Block and Extend to Modularize the View Templates
        • Converting the Widget Views into Jade Templates
      • Incorporating Stylus for Simplified CSS
    • Chapter 9: Structured Data with Node + Redis
      • Getting Started with Node + Redis
      • Building a Game Leaderboard
      • Creating a Message Queue
      • Adding a Stats Middleware to an Express Application
    • Chapter 10: Storing Content with MongoDB
    • Chapter 11: The Node Relational Database Bindings
    • Chapter 12: Graphics, Video, and Audio

(Notes: Creating, streaming Canvas, Working with Imagemagic, Working with image files, multipart upload with progress, livestreaming-js. How connect.static implements ranges, allowing functionality for HTML5 video to work. Discuss ranges.)

    • Chapter 13: Creating a Quick Chat with Sockets.io

(Notes: No, not everyone needs to implement a chat client, but it is the best way to demo websockets, Speaking of which, explain websockets. (socket.io does not have session info))

    • Chapter 14: Testing and Debugging Node Applications
    • Chapter 15: Security (chapter title TBD)

(Notes: connect-auth, EveryAuth, OAuth, crypto, SSL, injection attacks, hardening code, Validating (node-validator), Sandbox (vm))

    • Chapter 16: Scaling and Deploying Node Applications

Using gearman for parallel machine deployment? Benchmarking, Deploying app to one of the clouds, Possibly Azure if I can get to work, Heroku, Joyent, others, Creating and landing a module, nodemon, hook.io?)

  • Appendix A: Git and Github
  • Appendix B: Useful Resources and References
  • Appendix C: A Redis Primer
Categories
Books Technology

Node’s the thing

I just finished my fourth chapter for my newest book for O’Reilly. I never feel a book is solid and real until the fourth chapter. By the fourth chapter, you have a book, not just an idea or outline.

My newest work is titled “Learning Node”, about Node, or Node.js for the purists among you. It’s a good fit with my other JavaScript books, and is focused on an interesting and rather fun technology.

I wasn’t sure about Node when it first came out. My very first JavaScript gig wasn’t client-side development, it was a server application for a company in Portland, Oregon. I can’t remember the name of the company, or even what the application was about (I have done a lot of contract work in the last 25 years) but I remember working with a contractor from Vietnam who is one of the nicest people I have ever worked with.

I also remember that server-side development with JavaScript died quickly, and there went another skill down the toilet. So when Node came around, I didn’t embrace it as profoundly as many people did.

In time, though, Node won me over. I like it—not in the giddy, bubbling-over-with-enthusiasm embrace I may have felt about server-side JavaScript (and Java, and EJB, and the earlier Cloud computing, and DHTML), but I like it. I think it’s useful. I think it is a very solid technology.

What won me over to Node? The fact that it’s based in JavaScript helped. I’m not going to join the effete in condemning JavaScript, because I like JavaScript. I think Dart is dead on arrival, and JavaScript is only going to get better over time. However, there’s also CoffeeScript for those who just can’t embrace JavaScript.

I like that we don’t have to worry about working with threads, that modules are the norm, and that Node doesn’t pretend to be the definitive solution for every problem. I also like the community support and how uncomplicated it is to create complicated applications. I don’t want to use “easy”, but Node doesn’t demand that the developer jump through an extraordinary number of loops to get a job done. For all the new geewhiz quality about Node, it’s a very pragmatic technology.

Node is also mature enough to last—no lost skills with it. The very fact that the creator of Node, Ryan Dahl, decided to step down as gatekeeper for Node, and his decision didn’t cause any earthquakes in the Node community, attests to the maturity of both the technology and the community.

The HTML5 community could learn a lot from the Node community in this regard.

If there’s a problem with Node is that many of the those who work with Node come from a Ruby/Rails/Extreme Programming background, and many of the concepts and explanations about Node reflect assumptions that can actually form a barrier to understanding. In some ways, Node can present itself as more complex than it really is, primarily because much of the terminology reflects a background that not everyone shares.

Another problem is that documentation is an interesting mix of the nonexistent, cryptic, and/or flippant—none of which is generally helpful. Then there’s the oddly peculiar “Node web style”, with web sites in dark gray backgrounds with pale gray writing, (or white background with pale tan/green/gray writing) where the only way you can see the text is by turning up the brightness of your monitor until your head hurts.

Still, times are a changing. Cloud9’s new new Node Manual web site is a solid start in the right direction, and I have high hopes for the official Node.js site, too.

Then there’s my book, which I’m sure you’ll want—if for no other reason in that it’s a nice break from me bitching about HTML5.

Categories
Writing

When last we spoke

When last I posted, I had planned on updating that post with W3C co-chair decisions on my other HTML5 issues. I wasn’t quite expecting to be here, over a month later, still waiting on decisions. Not sure what’s happening with the W3C HTML WG at the moment, other than I think the group is making like an iceberg.

Eventually the decisions will be posted. Since I have a good idea what the decisions will be, no need to continue waiting.

Other than watching pots boil, I’ve been slowly working on my first self-publishing book on HTML5. I say slowly, because I ended up drastically changing the focus of the book, and hence the table of contents.

Though I would love nothing more than to fill 150 pages with details about the various HTML5 exploits, in the end I felt that an exposé on HTML5 isn’t going to be all that useful. Cathartic, maybe, but not useful. On the other hand, I refuse to jump on the “Isn’t HTML5 just peachy keen!” bandwagon, either.

I had to find a delicate balance between HTML5 rant and HTML5 rah-rah. Once found, I then had to dig for actual HTML5 implementation experience, which is a lot more difficult than you would think, given the fooflah about HTML5.

I’m still wrestling with the new TOC, so I don’t have any early peeks, yet. One thing the book won’t have is a discussion about HTML5 the brand. For one, isn’t it time to let the Geolocation folks have a little of the spotlight, all on their own? For another, there’s been enough confusion about HTML5 without conflating a formally defined and delimited specification, with a marketing buzzword.

So in the book, I’ll talk about HTML5…and Web 5.0, and Ajax5, not to mention P2P5, as well as Cloud #5, and throw in a little DHTML5, for good measure.

Categories
Writing

JavaScript Cookbook on way to printers

We just finished the last of the quality control checks on the JavaScript Cookbook, and it is now on its way to the printers. The Table of Contents should be showing soon at the O’Reilly book web site, but I’ll give you a taste of what I covered:

  • The usual suspects, such as String, Date, Math, Function, and so on
  • Creating JavaScript objects, including the new ECMAScript 5 object methods
  • The new HTML5 and WebApps 1.0 material, including drag and drop, worker threads, postMessage, and the local storage options
  • Debugging JavaScript, working with a library framework, such as jQuery, and packaging your libraries for reuse
  • Working with media and graphics options, such as SVG, Canvas, and the new audio and video elements
  • Complex performance functionality, such as currying and memoization
  • JavaScript out of the box, including working with desktop-like applications using client-side file access
  • Working with interesting data formats, such as RDFa, microformats, even ePub
  • Ajax, including working with XML and JSON formatted data
  • Debugging and using JavaScript test tools
  • Working with ARIA (Accessible Rich Internet Applications) and creating accessible dynamic applications

I devoted one chapter to ARIA and integrating accessibility into dynamic solutions. Because we now have access to an open source and freely available screen reader (NVDA), we can easily test our use of ARIA for dynamic applications. In addition, most framework libraries now incorporate ARIA support, so we need to understand how to use this rich and simple-to-use accessibility enabler.

I also covered ARIA because of my interest in semantic web technologies: ARIA is way of recording rendering semantics, which opens the door for interesting possibilities.

The JavaScript Cookbook should be in the stores in less than a month, and is available for pre-order. It’s a largish book—21 chapters and 530+ pages. The format is cookbook style, where I provide “recipes” in a Problem/Solution/Discussion format. All the code bits are included in example files, so you can play along, as you read.

One thing this book does not provide is support for IE6. Now that major sites and companies are no longer providing support for IE6, it’s time to stop wasting book space on an insecure, broken, and badly outdated browser.