technorthodox

I'm just your average 30-something, web software-writing, dog-loving, bike-riding Orthodox Christian, baritone, family guy.

I'm a Software Architect and User Experience consultant, and founder of Hovercraft Studios. You can check out my resume and portfolio to see the professional and personal projects I've been working on.

OOCSS slides and more from the jQuery Pgh meetup

I hope everyone who attended last night’s jBurgh meetup had as much fun as I did, and enjoyed my talk on OOCSS. I thought it was a great low-key event, and I have to say that the discussion after the presentation and hanging around talking to everyone were the best parts.

My slides are up on slideshare, and if you were at the meetup, I’d really appreciate your taking a minute to rate my talk, and (especially!) leave a comment about how it could be improved.

If you’re interested in getting more background on OOCSS, I encourage you to check out Nicole’s slides and video. I’ve also written a few articles that dig deeper into some of the concepts in last night’s talk, such as OOCSS inheritance, why .css() is bad, and OOCSS Antipatterns:

You can also check out the digital clock demo, including these other versions:

  • Analog – remember this is an antipattern (see above), no matter how cool it seems!
  • JQCon explode – we did this mod live onstage at JQCon
  • Daniel Lamb’s binary clock mod – he points directly to my JS view controller (view source to check it out), and just modded the HTML and CSS. Now that’s separation of concerns FTW.

For more deep diving along with some excellent code examples and comment discussion, I also recommend reading John Hann’s post on OOCSS for Engineers.

At the end of the presentation, I mentioned that I’m working on OOCSS design patterns for web applications. My plan is to post more information soon about the ones mentioned in the slides (with example code), as well as others, so stay tuned.

Thanks to Chris Bannon and Wijmo for organizing and sponsoring, to HackPittsburgh for lending us their space, and to everyone who attended! I had a blast, and I’m already looking forward to the next meetup.

OOCSS at the next jQuery Pgh meetup

I’ll be speaking about OOCSS at the next jQuery Pittsburgh meetup, this Thursday (2/3) at 6:30pm at HackPittsburgh. I’m planning to present some similar material as John Hann and I presented at jQCon in September, but I’ll also be including an expanded section on how to get started with OOCSS, as well as a section on OOCSS antipatterns.

Thanks to Chris Bannon from Wijmo for organizing the meetup, and for inviting me to speak. Hope to see you there!

Simple OOCSS Slideshows

I read this article recently, and decided to solve the problem the author proposes in point #3 using OOCSS techniques.

Here you go: OOCSS Slideshows.

You might be saying, “Good grief, all that CSS is overkill!”, and be tempted to think that just using image.style.display = 'none' is good enough. Try implementing those 3 effects in plain Javascript … you probably wouldn’t get it right—I know I probably wouldn’t.

Or maybe you’re thinking that you’d just use jQuery, Dojo, or your favorite effects library to do it. Putting aside the fact that the original interview question stipulated no libraries, the advantage of an OOCSS approach, as I’ve written about at length before, is separation of concerns, and all its related benefits.

Using an MVC and OOCSS approach puts control of the slideshow transitions into the hands of the designer, and changes to the transitions require zero Javascript changes.

Dojo completion statement parsing

One of the things on my Dojo completion hitlist was handling multiline statements, especially dojo.query chains, since I tend to break them into multiple lines when chaining more than 1 or 2 NodeList function calls (and I’m betting most folks do that, too). While thinking about how to handle this, I came to the conclusion that there were basically three ways I could approach it:

  1. Implement a real Javascript parser that is liberal enough to handle incomplete statements (e.g. it has to handle the statement you’re trying to complete!), or
  2. Integrate an existing parser that is liberal enough to handle incomplete statements (I have no idea if a liberal open source JS parser exists), or
  3. Implement something simpler and easier that covers most or all of what I think of as common cases.

I decided to go with #3. In fact, this is my general rule of thumb for the completion bundle in the short and medium term. I want to make something that is both useful, and something I can actually release since I’m only working on it a few hours each week. An unreleased, vaporware completion bundle is far less cool than a released one that works 80% of the time.

Here are a few shots of the multiline statement parser in action, completing a dojo.querychain. Notice also, in the last shot, it guesses correctly that I am starting a new statement, even though I didn’t end the previous one with a semicolon. However, it’s not perfect, and will almost certainly break under less common conditions. I’ve tried, though, to abstract the parser from the completion code in a way that allows the parser to be improved when I find cases where it breaks.

(download)

 

TextMate Dojo completions: dojo.require and dojo.query

Last week, I started thinking about what features I’d want in the TextMate Dojo completion bundle in order to feel good about calling it releasable. I made a list, and started knocking them down. Here are a few that I managed to tackle over the past week:

  1. It scans and executes dojo.require()s in the current file and adds their symbols to the completion context.
  2. It recognizes when you are typing inside a dojo.require() and completes dojo package names instead of functions and properties.
  3. It recognizes when you are in a dojo.query chain and completes NodeList functions while you’re in the chain.
  4. Because it understands both dojo.require and dojo.query, it will complete functions from NodeList mixins, such as dojo.NodeList-fx, that you’ve dojo.required in the current file.

How does it do that?

In a word: Javascript. I’ll be posting more about this later, once the first release is ready.

A note about performance

Any completion framework has to be fast. I’m ruthless when it comes to development tools, and I’ll bet you are too. If something slows me down, I stop using it. If the pain outweighs the benefits, it’s gone. So, one of my goals is to make sure this bundle is as fast as it can be.

The current performance is very good on my laptop. The completion popup is nearly instantaneous, even with dojo.require scanning, and hundreds of potential completions. That said, I’m using the most recent MacBook Pro rev with 8g RAM and an SSD. I realize that may not be the most common setup, so I will be testing it with other setups to make sure it doesn’t suck.

I can haz it?

A few folks have asked when they can get the bundle. Since it’s a side project, I don’t want to give a date. I’ll release an initial version when I feel it’s at the point that I’d actually use it, and I can tell you that it’s getting close :)

For now, here are a few more teasers that show the new stuff in action.

(download)

Dojo Autocomplete for TextMate

One of the biggest complaints I hear about TextMate is that it doesn't have some sort of native intellisense, and doesn't do code completion.  Those are typically features provided by "bigger" IDEs.  TextMate started life as a text editor, and has had different goals than other IDEs, so even though TextMate has grown closer to full-blown IDE over the past few years (thanks to lots of great community bundle contributions), it's not really hard to understand why it hasn't provide those features natively.

It turns out, though, that TextMate provides some builtin help for rolling your own completions, and a lot of folks have done that for various languages and platforms.  I decided to take a crack at it for Dojo as a part of a new, simplified Dojo bundle I've been working on.  Here are a couple teaser screenshots of what I have so far.

I'm not ready to post the bundle yet, but I'm actively working on it, so I hope to have an initial version ready within the next couple of weeks.

(download)

OOCSS Antipatterns: Analog clock theme using only CSS

You asked for it, and you got it. Several people asked me after the digital clock demo at jQCon if I thought it was possible to create an analog theme for the clock using only CSS. I had wondered this as well, but came to the conclusion that it was impossible, given the current HTML structure. So, that’s the answer I gave at the conference.

The very next day, I thought of a way to do it, so here’s an analog theme (source on github) for the digital clock done entirely in CSS.

First, note a couple things:

  1. The first hour, minute, and second digits are hidden.
  2. The second hour, minute, and second digits have been styled to look like analog clock hands—i.e. long thin rectangles, and have been anchored at the center of the analog clock face.

The key is the use (in fact, abuse, read on!) of the immediate sibling selector to rotate the clock hands to the correct position, using CSS3 transforms. For example, the line above says when the first hour digit is a “0”, and the second hour digit is also a “1” rotate the second digit (remember, it’s been styled to look like an analog clock hand) by 30°. Each hour represents 30° (360 / 12 = 30), so looking at the rest of the hour selectors, you can see how it works.

Similarly, the minutes and seconds are rotated using the immediate sibling selector. The only difference is the degrees, since 360 / 60 = 6° per minute/second.

Ok, neat, it works, but …

How not to build an analog clock

At this point, you’re probably saying to yourself (and if you’re not, you should be) “This is a terrible way to build an analog clock”. You are absolutely right. There are many problems with this, and I’d even go so far as to call the whole thing an antipattern.

From the HTML element hierarchy, to the CSS classnames, to the time computations, most everything tailored to represent an LED-based digital clock.

However, the point of this little exercise was not to find the best way to engineer an analog clock. The point was to answer the question “could it be done?”. But maybe we can learn something about OOCSS anyway.

There is something to be learned here

As the saying goes, “when all you have is a hammer, everything looks like a nail”, and in this case of trying to use only OOCSS to transform the digital clock into analog, there’s certainly some overly-ambitious hammering going on.

If the HTML is poorly-suited to the task at hand, trying to apply OOCSS on top of it will probably just make things worse. In fact, in this example, the HTML and CSS are fighting each other rather than working together.

OOCSS is not just about CSS, it’s about identifying objects in the view first (as John said in our presentation, “ignore the HTML!”), and then structuring HTML and CSS around the containers, content, identity, and states of those objects.

The fact is that the objects in this clock are LED digits, not analog clock hands, and some mildly clever CSS doesn’t change that. Conversely, this bastardization means that the hands of the analog clock have the classes “display-area” and “digit”, as well as “d0” – “d9”, none of which seem like logical choices for the hands of an analog clock!

Antipattern: In any reasonably complex system, writing HTML and CSS first is an antipattern.

What to do?: Break out the wireframes, gather around the whiteboard, and start identifying objects! List their states. Talk about ways to translate them into well-structured HTML containers and content.

One of the results of this object/HTML/CSS mismatch is state explosion, aka combinatorial explosion. There are 72 CSS rules needed just to rotate the clock hands, whereas there are only 10 rules for the original digital clock LED digits. That certainly qualifies as state explosion, and just looking at the analog rules should give you an uneasy feeling that something is wrong.

In fact, modeling any analog clock, not just this bad example of an analog clock, as discrete OOCSS states seems wrong. Consider also the progress bar example John gave during our talk. Progress bars, in most cases, represent a continuous function rather than a discrete function, and therefore can require an infinite number of states to model their possible values—e.g. 30%, 30.1%, 30.15%, and so on.

Antipattern: Trying to model continuous values with OOCSS state is an antipattern.

What to do?: Use a mechanism better suited to continuous values/functions, such as a vector library, or yes, even direct (but well abstracted!) style manipulation.

One other thing that should be bothering you about this analog clock is that nearly half the HTML elements are permanently hidden by the analog theme’s CSS. This can be an indication that you’ve misidentified the view objects. In this case, I think it’s pretty obvious that the objects I originally identified when creating the digital clock, that is, active digits composed of lit or unlit LED bars, simply are not present in the analog clock.

Antipattern: Having sections of permanently hidden HTML is an antipattern.

What to do?: Review your objects and wireframes. You may have misidentified some objects, or your application may have changed significantly enough over time that the objects you had originally, and correctly, identified are no longer present. Either way, it’s time to revisit the wireframes and refactor.

Trying to shoehorn an analog display into the digital clock was fun, but more importantly, I think it helped to identify some OOCSS antipatterns. Hopefully these will help us all avoid some pitfalls!

Font-based digital clock theme using only CSS

Ever since Daniel posted his binary mod of my digital clock, I’ve been thinking about other ways to push the limits of the clock using only CSS. At JQCon, I also talked to a few folks between sessions who had wondered the same thing. So, I’ve decided to give it a go.

One of the first ideas I had was to try to use fonts instead of the LED divs to show the clock digits. So, here you go.

It turned out to be fairly easy, and required zero changes to the Javascript view controller. The view controller simply passes the same messages to the view as it did before. In other words, the view controller relies on a message-passing-based view API to which the OOCSS responds. That API is unchanged in this version. To verify, you can hop on over to Daniel’s binary mod, which references my JS directly, and see that it still works.

It also required only superficial changes to the HTML:

  1. I added the button for the new theme in the row of theme buttons.
  2. I added “hour” and “minute” classes to the digits representing hours and minutes. This change was not necessary to support the new font-based theme, but makes the hours and minutes consistent with the seconds, which already had the class “second”.

The key changes were, of course, in the CSS, and here are some of the most relevant bits.

The comments pretty much say it all, but basically it hides the LEDs and then uses :before content to inject the font-based digits.

One thing I hadn’t thought about before I actually ran it the first time, was that the “1” digit is much thinner than all the others, so I had to forcibly set a specific width for it (in both hours/minutes and the smaller seconds). Without that specialization, the clock looks too sparse when there is a “1” (or several “1"s) being displayed. Yet another win for the OOCSS base and specialization pattern.

I think this theme looks pretty good (although I’m still partial to the LEDs), but if you have suggestions for how to tweak it, I’d love to hear them. Also, if you have an idea for how to push the envelope, feel free to leave a comment, or tweet it up!

Stay tuned for more envelope pushing …

OOCSS for Javascript Pirates at JQCon 2010

I had a lot of fun presenting OOCSS for Javascript Pirates with John Hann at JQCon 2010 in Boston this past weekend.  I came away feeling like the talk was very well received, and that people felt it was helpful.   The slides and the digital clock, including the jqcon-explode mod that we coded live during the talk are all up, as is Daniel Lamb's binary clock mod.

If you want to read even more about OOCSS, you can also check out a few of our blog posts on the subject:

One of my favorite things about the conference was, as Paul Elliot (@p_elliott) put it, the hallway track.  I got to meet and talk with so many cool people between the sessions.  John and I both had quite a few people tell us (in addition to a few good pirate jokes) that they had been thinking and doing some of the things from our talk, and they were glad to hear that other people were thinking many of the same things as validation that these techniques work.  Hearing that was good validation for us as well.

I really appreciate all the feedback so far on the presentation, and on the digital clock as well, on which I have received many compliments.  Thanks, everyone!  If you haven't already rated our talk, John and I both would really appreciate your feedback over at SpeakerRate

I also have to say that overall, the conference showed how much energy there is in not only the jQuery community and the larger Javascript community, but also in front-end engineering as a whole.  It's a great time to be a front-end engineer.

Thanks to the jQuery team and the conference organizers for putting together and running an excellent conference.  I had a blast.  Nice job all around.

The Power of MVC: Binary Clock mod

When I created my digital clock, one of the things I wanted to show was how OOCSS and MVC could be used to provide a clean, clear separation of concerns between the View, i.e. HTML and CSS, and the View Controller, i.e. Javascript. Along those lines, I had always intended for it to be possible to slap a different View onto the clock with no mods to the View Controller, but the proof is in the pudding, right?

Along came Daniel Lamb, who put that to the test, and created his spiffy binary clock mod.

He created a slightly modified View structure for the binary clock display in his HTML, and then cleverly applied OOCSS principles to inherit from my original OOCSS. Most interestingly, though, notice that he didn’t change a single line of code in the JS View Controller. In fact, he referenced my JS View Controller directly in his script tag. Because CSS classes are used as a message passing mechanism, and his View responds to the same messages, the binary clock works perfectly.

I'd like to thank Daniel for creating such a cool mod and perfectly illustrating the powerful separation of concerns that OOCSS and MVC can provide.