Designers, Developers, and the x_ Factor 20
Our team is lucky enough to be in a position where we have both designers AND developers working on the same code base in parallel.
Since Ruby on Rails adopts the Model-View-Control pattern for separating business logic from the presentation layer, we’re able to give our designers a lot of breathing room to to design the interface, whether it’s for interaction or aesthetic reasons. However, sometimes this breathing room has resulted in small bugs slipping into the application interface. In general, nothing disastrous, but each bug that slips into the queue, slows down the project and we want to avoid as much of that as possible.
I’d like to share a few issues that we’ve seen occur on various occasions, and then show you what we’ve done to avoid them happening again.
Scenario #1: The case of the changed div id, (victim: designer)
- Designer adds a few HTML elements to the page, defines an
idon a<div>tag and styles it with CSS. - A few days later, a developer needs to make some changes, tests it in their favorite browser and commits.
- Later, the designer doesn’t understand why the styling is all messed up. “It was working fine.”
- ...minutes, hours… go by where the designer tries to track down the issue. “Oh! Someone renamed the
idin this<div>tag. Sigh.” - Developer apologies, but explains that he needed to do it because he needed to make it work with his new RJS code.
Scenario #2: The case of the changed div id, (victim: developer)
- Developer is implementing this cool new Ajax feature into the web application
- The code relies on there being one or many HTML elements in the DOM with specific
idvalues defined.
- The code relies on there being one or many HTML elements in the DOM with specific
Example: <div id="notification_message">
- A few days later, a designer is making some changes to the layout and needs to restyle some of the view that this
<div>tag is defined. Designer decides to change the id to a different value for any variety of reasons. (or perhaps they changed it to use a class instead of styling it by the id). Often times, we don’t know who set the id or class… and many times the developers aren’t savvy enough with HTML and designers end up cleaning things up a bit. - Later, code is checked in and designer didn’t notice that the Ajax was now breaking as they weren’t focusing on just the layout.
- Day or two later, developer sees bug, “Feature X isn’t working, throwing JavaScript error…”
- Developer is confused, “Hey, that was working! What happened?”
- Developer tracks down the problem, discusses with designer, they figure out a solution. Problem solved.
I could outline a few other examples, but I really wanted to highlight these two types of situations, as our team has seen this happen on several occasions. Luckily, we’ve learned through these experiences and have taken some measures to try and avoid them in the future.
Moving forward (together)
Both of the examples above, were essentially the same problem, but resulted in problems for a different role in the design and development cycle. While, I’ve definitely been the victim of #2 several times myself, I know that I’ve also been the guilty of #1. So, what can we do as designers and developers to work with each other without causing these little problems from occurring? (remember: many little problems can add up to a lot of wasted time spent resolving them)
Several months ago, I had a meeting with Chris (User Interface Designer) and Graeme (Lead Architect/Developer) to discuss this very problem. At the time, we were implementing a lot of Ajax into an application and were occasionally running into Scenario #2. We discussed a few possible ways of communicating that, “yes, this div id should NOT be changed (without talking to a developer first)!”
Idea 1: Comment our “special” HTML elements
We discussed using ERb comments in our views to do something like the following.
<% # no seriously, please don't change this id, it's needed for some Ajax stuff %>
<div id="notification_message">
...
We all agreed that, while effective, it was going to clutter up our RHTML code more than any of us desired.
Team Response: Meh.
Idea 2: Reserve id’s for developers
Another idea that came up, was to ask that designers only use classes and ids wold be used by the developers when they needed it.
<div id="developer_terriroty" class="designer_territory">
...
Chris pointed out that this wasn’t an ideal solution as there is a distinct case for when to use ids versus classes.. and he is very strict about adhering to the HTML/CSS standards.
Team Response: Not hot about it…
Idea 3: Naming convention for Ajax-dependent elements
The third idea that was discussed, was specifying a naming convention for any elements that were needed by our Ajax code. We played around on the whiteboard with some ideas and settled on the idea that we’d prefix our id’s with something easy to remember for both designers and developers.
We agreed on… x_ (x underscore), which would make an element id look something like this:
<div id="x_notification_message">
...
x == ajax... get it?
While this adds the strain of typing two more characters to much of our RJS code, we don’t run into Scenario #2 very often anymore.
render :update do |page|
page[:x_notification_message] = 'Something exciting happened... and this is your notification!'
page[:x_notification_message].visual_effect :highlight
end
or in client-side JavaScript (where we also use this)...
$('x_notification_message').do_something
I find that this helps our team keep a clear distinction between what can and shouldn’t be changed in the views by our designers. Sometimes they have a good reason to do so, but they know that if there is x_, then they should ask one of the developers on the team for assistance in renaming it without causing any problems in the application. It also allows our designers to add classes to these elements, or style the id that we’ve defined.
Team Response: Wow, was that all we needed to agree on? Hooray!
This leads me to some other problems that have/may come up, but I’ll discuss that in my next post on this topic, when I’ll show you how we can use RSpec to avoid these sorts of designer versus developer problems.
If you’re working in a similar environment, how are your designers and developers working, together, in perfect harmony?
Until next time, remember to hug your designer. ...and if you’re still having developer design your applications, consider hiring a designer. ;-)
UPDATE: changed examples after a few comments about using div_for as another solution. (see comments for details)
Enjoying the content? Be sure to subscribe to my RSS feed.





Edge Rails (or 1.2.3 with the simply_helpful plugin?) has the div_for method:
<% div_for @post do -%> #post_1 #post_new
<% div_for @post, :comments do -%>As Rick says, idea 3: embrace conventions! If it’s a comment, the list of comments will have a div with id ‘comments’ and class ‘comments’. Each comment inside there will have id ‘comment_[id]’ and class ‘comment’.
So long as both sides of the team understand these conventions and create their own, as a team, for when there’s not already something there (eg for the number of comments returned in our current app, it turns up in a div with id ‘comments_count’), everybody’s happy and there are less of these surprises.
And for bonus points, it makes code everywhere that deals with views much cleaner and tidier. I’ve stopped disliking working on views since I started a couple of new projects on edge…
That would be idea 4, even. :-)
Rick,
Unfortunately (to my best knowledge), using div_for won’t solve this problem for everything that we’re doing with JavaScript. For example, we do write a lot of client-side javascript and update various elements on the page. We follow the same
x_approach for this as well.I should have used a different example than a div for comments. ;-)
@rick/graeme
Made changes to my examples to show for stuff that isn’t directly mapped to an AR model in our views. Agree that the div_for will help for some scenarios, but when we have to define element ids ourselves, we still want an easy to remember convention.
Wow. I’m glad to know that my designer and I aren’t the only ones having this problem. We started to write comments at the top of our views to list any html elements that shouldn’t be renamed. This isn’t a bad compromise and typing extra characters could be resolved with a simple textmate snipper.
Great idea!
Robby,
Wanted to follow up with another comment. What you’ve done is provide a framework agnostic remedy to this problem. I’m not exclusively working with railss right now and have a few freelance projects with a designer. Some are in php, rails, and a few older perl projects. We have been adding some ajax functionality to these older projects and this approach would work well in these other environments. Thanks again for the tip as I plan to get my designers thoughts on this right away. :)
Jon,
I hadn’t thought about that, but knew that we were focusing on something that we would include in our HTML conventions and style guide for both our designers and developers. I’m glag that others are finding it useful.
Good Idea. We’ve been using the comment approach, which does get pretty lame.
I (as a developer) often run into the problem of when to write functional tests that depend on assert selects. Often times I’d like to do test first prototyping but then I get handed HTML with completly different div ids than I was expecting. In a perfect world, I’d start with that HTML first, but that doesn’t always happen.
Also – do your designers run the tests? Wouldn’t they be able to see that they broke functional tests? (Maybe in BDDland this works differently).
Thanks again.
rick, my biggest problem with Rails is that developers keep putting stuff into helpers, which forces me to have to render the page to see what value rails will put in the id value. this adds more time to my process and I don’t see how much this benefits yours. with the div_for approach, I have to read the rails api to figure out how to style it, which seems like a lot of extra steps when you’re just rendering a div tag. on several occasions, I’ve seen helpers take more code than their basic html counterparts. When I’ve mentioned this in the past, developers respond with this is a DRY approach, but clearly we cannot avoid duplication in html as there will surely be more than one div in the web page. correct?
Did you consider writing view specs which validated the existence of the various dom ids? While conventions are great, they aren’t necessarily enforceable. Executable specs with a continuous integration environment will quickly point out when something gets changed.
Josh,
Did you consider reading all of my post? :-p
Heh. I kid…
Yeah, look for my next blog post on this topic. ;-)
Reading is so Web 1.0… Let me know when you’ve transcribed everything into a podcast! :-)
It’s for the issues you described, plus my growing disillusionment that Ajax actually does anything to enhance user experience, that I’m leaning towards idea 4:
Don’t use Ajax.
Tim,
On one hand, I have seen a lot of Ajax used horribly, but I’ve also seen where it has greatly enhanced the user experience. Like all good things… use in moderation.
Yeah, you’re right robby and I didn’t mean to lead us down the path of debating the merits of Ajax, what do I want to briefly mention is that I’ve had some luck with judiciously pruning some of the Ajax in my apps, and I use the kind of issues you describe above as a code smell. The issues you lay out have nothing to do with Ajax itself simply the management of it, and it looks like you’ve found a good way to do it. I like to add an additional option of asking, “what if we just got rid of ajax here?”. Sometimes it helps…
If you use xhtml, you can create a new namespace for developers to mess around with rjs and javascript:
<xhtml xmlns="xhml_ns..." xmlns:rails="my_dev_ns"> <div id="for_css" rails:id="for_developers"></div> </xhtml>But of course you need to adapt prototype to take care of the namespace in $() and $$() but it’s not a big deal.
I’m very wary of back-end developers enforcing ids on elements. TBH, I tend to make sure that on anything dynamic, :id is specificed. The fragilest coupling of all is coupling to things like Rails’ dynamic form id generation. Much better to define your own.
As regarding “straight” html elements that need to have certain ids… yes, i can there’s an issue there, and comments or convention are fine. Personally, I see no problem with ERb comments in moderation.
In an idea world, though, the person who breaks it can fix it. Hopefully, that should be the front-end developers making suitable changes to HTML and fixing up the Ajax/controller code to match.
I’m very wary of back-end developers enforcing ids on elements. TBH, I tend to make sure that on anything dynamic, :id is specificed. The fragilest coupling of all is coupling to things like Rails’ dynamic form id generation. Much better to define your own.
As regarding “straight” html elements that need to have certain ids… yes, i can there’s an issue there, and comments or convention are fine. Personally, I see no problem with ERb comments in moderation.
In an idea world, though, the person who breaks it can fix it. Hopefully, that should be the front-end developers making suitable changes to HTML and fixing up the Ajax/controller code to match.
With a naming convention like this one, One might concider patching RJS so that you can just do
page[:notification_message]and have that translated to operate on the element with idx_notification_message.