Recent Posts

Javascript

Disclaimer: this is a rant at 1AM. Content subject to change when I wake up in the morning.

Javascript is not a classical OO language.

Here it is again.

Javascript is not a classical OO language.

You can use classes. You can pervert it into things like Dart, or use gobs of inheritance to build a classical structure. By doing so, you're limiting yourself and destroying the flexibility that Javascript provides. Stop thinking of Javascript like Java, because it isn't. Use object instances and build prototypical objects when it makes code cleaner, not as the general rule. These things aren't evil in any way- but they should be used where appropriate. You don't need contracts. I don't even like typing the word 'contract.' It's ugly. It's ugly in Javascript. It's ugly everywhere, really.

Protip: learn Scheme. Try out MIT's free online courses. Then come back and try out Javascript again.

I went through this phase. I learned Javascript, and used it for horrific DOM manipulations. Then I learned C#. I went through a phase where everything was an object, everything was namespaced. Then I learned Scheme, and bounced around in Python and Ruby a bit. Once you've grasped procedural, functional, and classic OO programming, you begin to see that the patterns in Javacript aren't ugly, aren't random and messy; that you don't need obese structure and contracts and type checking. You can elegantly and concisely pass around functions and objects and whatever, because they're all the same thing anyway, more or less.

Structure is overbearing. Javascript is freedom.

I guess the whole point I'm trying to make here is, I hate sauerkraut.

Alchemy Websockets

Alchemy Websockets is a C# .NET library that allows a web browser that supports the WebSockets protocol to connect to a server application using a peristant TCP connection. This means that we can employ real-time, stateful communication between web applications and server applications. WebSockets are supported by current versions of Chrome, FireFox, Safari, and Opera and Opera Mobile with special configuration settings set. IE10 will also have WebSockets. Alchemy can run on Mono (which means EC2 is a go) and supports most versions of the protocol, stretching from hybi-00 to the latest (and final) RFC spec.

We (Drew and I and Olivine Labs) had started considering how to use WebSockets for some of the games we were building and planning. At the time, we were thinking about using them for chat for the now-defunct Chrysellia; and we have plans to build a game that uses WebSockets fully as its transport. Our search took us first to socket.io, a Node.js implementation that gave not only WebSockets, but also fallbacks with Comet and Ajax long-polling and other hackish methods of doing socket-like communication.

However, while I, a javascript developer, originally lobbied for Node.js and Socket.io, we decided to move forward with C#. It isn't the new, sexy language, but it is a language that we both know well; and better, we could take advantage of C#'s amazing microthreading. We built the library around this core threading model so that it could very efficiently handle hundreds of thousands of simultaneous connects, disconnects, and messages on a single server. Drew was able to get around 200k live connections on his dev box before he ran out of memory for the clients.

Alchemy also includes a WebSocket client for server intercommunication that uses the latest protocol version rfc6455 to talk to anything else running WebSockets (whether Alchemy or otherwise.)

We'll be putting it up to a big test with a server infrastructure management API that we've called Tiamat and an API command router called Vocale that will be built over the coming months (we plan to MIT / LGPL these as well).

Ditching Twitter Bootstrap

Until recently, my blog was using a fairly vanilla version of the CSS framework put together by the developers at Twitter, Bootstrap. It's a really full-featured framework that gives grids, headings, links, buttons, and all manner of form elements a clean and consistent design. You can see another example at the Alchemy Websockets site. I used it- as I think many people do- as a way to get a decent site deisgn up in a matter of minutes; one can download or clone the repository, and use as-is or tweak a few LESS variables and compile a new version complete with new colors and gradients.

I put a bit more work into the Alchemy site than I did on my blog; I originally was more concerned about setting up jekyll correctly and getting everything online than learning another layer of abstraction between me and my code. In fact, that's probably Bootstrap's greatest contribution to me - I learned more about LESS while tweaking link colors and gradient styles for Alchemy. I'm still not sold on the concept of CSS preprocessors on a wide-scale team use, but I'm experimenting with it on the new Neflaria site and hope to have a much more substantial recommendation once that project is complete (fingers crossed, June.)

As all bootstrapping frameworks must (or, should), the monotony eventually got to me. I only used about 10% of the features, and the design just didn't feel right if it wasn't either heavily customized or built from the ground-up. It is my blog, after all - and even if it'll take a little work to bring it back up to speed, to homogenize the components and get all the elements lined up correctly, it feels a little more like home now.

Related: subtlepatterns.com is amazing. Also, I'm a happy user of the 1140 grid which provides a fluid-ish responsive grid system.

Vim "Can't Open Errorfile" Issue

tl;dr: put set shell=bash in your .vimrc

I recently had to reinstall OS X after a catastrophic hard drive failure. I had most of my configuration on Github (which is something I highly recommend), luckily, so it was a pretty easy move thanks to that and some well-placed backups.

So, I pulled down my config, loaded the submodules, and threw it all in my ~/.vim directory. Everything went smooth as butter until I tried to run vim-ack. I had originally thought that it was an error with vim-ack, and tried alternate versions of vim-ack. But I still got an error. So I tried five different snapshots of MacVim. I still got the error. Then I tried copying a file with NERDTree, and I got another error. Delete and add worked, but not copy. Mystifying.

vim-ack error:

Searching ...
Error detected while processing function <SNR>21_Ack:
line   23:
E40: Can't open errorfile /var/folders/98/_ymf2wy554n6qrs32ptrwrl40000gn/T/vx96wXC/2
Press ENTER or type command to continue

Error executing vim-ack

NERDTree error:

Cannot execute shell /usr/local/bin/bash
Error detected while processing function <SNR>19_showMenu..30..47..NERDTreeCopyNode..54..112:
line    8:
E484: Can't open file /var/folders/98/_ymf2wy554n6qrs32ptrwrl40000gn/T/vx96wXC/3
Error detected while processing function <SNR>19_showMenu..30..47:
line    6:
E171: Missing :endif
Error detected while processing function <SNR>19_showMenu..30:
line   19:
E171: Missing :endif

Error executing NERDTree copy

I tried chowning the temp files; I tried unsetting TEMPDIR. Nothing worked.

After browsing page after page of non-helpful Google results, I came back to a three-year-old conversation that I had already been to twice. I noticed one little line in there:

set shell=bash

And thought "Well, I've tried everything else."

It worked.

HTML

I have a strong belief in HTML that means something. HTML can be viewed as a vessel for delivering content; however, HTML- and especially more so with HTML5- defines a mechanism with which we can not only deliver content, but describe what the content is. This is what is called semantic markup; it is not an obtuse buzzword, but rather an important design methodology.

It is easy to fall into one of two pitfalls: "just get the thing done" and "write the minimal amount of code possible". One is caused by a developer who does not understand (or does not care to understand) the importance of markup; one is caused by a developer who is foregoing semantics in favor of misguided "efficiency" gains, whether personally (writing less code) or for the server (sending less code.) However, in the long run, this serves only as a barrier to maintainance and usability.

§

There was a large movement towards using div tags for markup, moving away from monolithic table-based markup. This was done in order to reduce the coupling between styles and content, making changes easier, content easier to consume, and code easier to maintain. It also allowed designs to be fluid, flowing around the content rather than constraining content into boxes. Instead of shuffling table cells, we now only have to switch out a class, or in extreme examples, the order of a few div containers in order to update a design. This was an important step forward in the evolution of modern web development. However, while progressive, divs were found to be meaningless. No reasonable heirarchy of data could be constructed; a side-bar was virtually indistinguishable from main content, a site's heading didn't stand out except through primitive h# tags.

HTML5 then gave us elements such as header, footer, time, nav, section, article, aside, and more; new properties and attributes such as input types and input placeholders; and more (which you can read about in the W3C Specs and at the excellent html5 doctor. html5- true html5, not "marketing buzzword" html5- has a rich and beautiful focus on semantic markup that allows for clear consumption and maintainance of content.

It is not only html5 that has semantic meaning, though; looking back through html4 and earlier iterations gives us examples of hr for splitting content sections, table for data, form for form, a for links. Many of these base tags are, however, ignored or forgotten in return for generic div zealotry. Links are built with div tags and javascript onclick events, 'ajax' forms are built using generic elements, and images are simply div tags with background images. We have begun to lose meaning not only to the browsers that consume our content, but also to ourselves, as developers. With semantic elements, one can view an article tag and understand where it begins and ends without following a chain of generic div tags; with a form, one can understand that its contained inputs are part of a collection to be submitted, rather than a random cluster of inputs, any of which might be sent out to a server; with an a, we know it goes somewhere, and with a button, we know it performs an action.

Semantically relevant code is both code and documentation. With consistency, we can reduce the number of one-off styles and the amount of javascript logic we have to write. Instead of coupling our styles to our code, as we may have coupled our content to tables in the past, let us define code that uses elements that can describe what the content is. Style a time element instead of a time class on a span; write javascript based on buttons instead of divs coerced into acting like buttons.

Thus we may reduce our code and provide meaning to our content, while providing a normalized experience to machines who read our content, be they search engines, browsers, or screen readers.

This post is dedicated to my colleague, Tony DeSylva, for whom I wrote this.

<< View Older Posts