Callbacks, callbacks, callbacks!

Waiter,

There’s a promise in my spaghetti.

***

So, dig, I like promises.  People I work with and people I talk to think I don’t but I really, genuinely do. Promises (in a computer science way) are just plain awesome.  Here’s the idea:

Program module: Yo, system, I want to do something and I want it to happen on another thread so I can keep doing stuff.

System: Okay. I’m doing it. Here’s an IOU, let me know when you are ready to collect.

Program module: Okay, I need that stuff now.

System: I’m not ready yet. Please hold.

Program module: okay, I’ll wait.

System: Okay, I’m done now, here’s the stuff you wanted.

Program module: Cool, thanks. Game on!

What happened here?  Basically a promise was issued and the program continued running with an async process continued in the background. When the program was ready for the data, but the data wasn’t ready, the promise became a blocking operation. Once the system was done, it delivered what was needed and the block was released.  This is awesome because you don’t end up with something that blocks up front. This can be annoying when you need something to appear completely transparent and non-blocking.  Such is the way of the world.

Javascript promises are, let’s just say… different. Everyone likes to say “oh they stop callback hell! They are the magic bullet!” Incorrect!

Promises are just syntactic sugar over a callback structure, which basically seems like a big fat lie to me. I don’t like the idea that I am “getting rid of callbacks” and really all I am doing is tucking away functions in a place where I have to do a TON of work to get tests around them. I have seen some of the worst code ever written inside of promise callbacks because “hey, it’s promise. It’s cool, man. You don’t need to test that.”

*cough* yes you do *cough*

Did you notice how I said “promise callback?” Yep, there it is. Promises and callbacks are still the same. You still pass in callbacks. You still have to handle the asynchronous nature of it all. This is where I climb to the mountaintop and proclaim “the cake is a lie!”

Then there is the q.all argument:

“What if you need to do a bunch of things and then call back? That’s like… complicated, man.”

It is. This was one the one concession I make… well, I USED to make. Q.all is pretty cool. Don’t get me wrong, anything that will bundle up a bunch of async calls and then hang out until they are all done, THEN callback is pretty darn nifty.  The problem is you are still introducing this idea of promises into the mix.  Stuff happens, the spell is woven and magic happens… Magic that is basically untestable.

So, let’s stop trying to paint the callback turd with a single layer of abstraction that makes things murkier and more difficult to understand. Promises are magic that have become lingua franca of async spaghetti. Instead, let’s have a look at a handy new library borne of Node and easily pulled into the client: Async

Dear promises, never send to know for whom the bells tolls; it tolls for thee.

Async deals with callbacks differently. Instead of wrapping everything up in a nasty set of promise.then().then().thens, try async.waterfall(). It’s like magic:

async.waterfall([
firstOperation,
secondOperation,
thirdOperation
], finishFunction);

Now your code actually says what it is doing. Callback hell is gone. Promises are eliminated. All is right in the world.

But what if I want to do a bunch of stuff that doesn’t happen in serial? Parallel. Check it, yo:

async.parallel([
anOperation,
anotherOperation,
yetAnotherOperation
], finishFunction);

It’s like magic right?

In closing, all I would ask is, if you are going to write a bunch of async stuff, please give me and everyone else on your team a break. Async is the way to righteousness and the light. Promises are great when you absolutely, positively must have it sometime later, but most work can be done with async. Give it a try and make your code a better place.

Similar posts in Coding, Javascript, Site Architecture

To New Beginnings

Wow! It’s shocking that the last post I wrote here was almost a year and a half ago. I guess it’s been busy!

In that time I worked for an education company, got laid off, found work at a startup and wrote a LOT of code. Am I older? Definitely. Am I wiser? I certainly hope so. If anything I gained a lot of insight and found evidence for my suspicions.  User experience is crucial and the only people who can guarantee a good experience are the people who create the software that users touch.

I spent much of the past 10 years trying to figure out what I wanted to be when I grew up.  I went through phases of user experience, accessibility, project management and research.  All the while I was busy writing software.  What I ultimately discovered is I like writing software.  I like creating things.  There’s a rush that I don’t get anywhere else but there.  That doesn’t get me the answer I was necessarily looking for, but I suppose it gave me something I could hold on to.

Another important thing I discovered along the way is there are a lot of people who have a lot to learn (including me) but I discovered something I didn’t believe before now: I have something to share.  For as much as I don’t know I have been fortunate to learn a lot of lessons and I can share that with people so, maybe… hopefully, they can either grow from what I experienced or, at least, I can help buoy their spirits a little by showing that everyone makes mistakes.

Wisdom is what you get when you don’t get what you want.

I didn’t come up with that phrase, but it sure sums up what I feel to be true.  Just because things didn’t work out the way you originally planned or wanted doesn’t mean that things didn’t turn out at all. Failure is such a better teacher than success that I just can’t imagine why people fear failure so much.  I aim to fail every day. Failing is awesome. Success just means you’re done, but when you fail, that means you went from working on something routine to a fascinating new puzzle. What a great opportunity!

I could go on and on like this for pages, talking in circles and rambling about vague pasts and lessons learned, but that isn’t what I set out to do.  This post marks the beginning of a new era for me and this blog.  I won’t promise that I will never post long diatribes about strange new discoveries I may or may not have uncovered myself.  What I can say is I have a focus today like I never could have imagined when I started writing this blog years ago.

I want to make stuff awesome and make awesome stuff. I want you to do the same.  I still want to make the web a better place, but maybe, somewhere along the way, I, or we, can actually make software better.  Let’s toast to new beginnings and new projects.  Here’s to all the projects that never quite were and the ones that are yet to come. Let’s make software. Let’s make it great. Let’s make it together.

Yo dawg, I heard you like accessibility…

So I put accessibility in your menus so your users can use your site even if they are disabled.

Okay, so I suck at yo, dawg jokes. I did, however make a handy little menu script.  It’s small. It’s functional. It supports accessibility features like roles and keyboard access. It’s easy to turn some plain old HTML into a menu without having to know ANY javascript.  Am I a mad genius? Quite possibly, but I’ll take what I can get.

So, here’s the deal, you can download the alpha release at the following link:

https://github.com/cmstead/ClickBeetleJS/releases/tag/v0.5-alpha

If you want to actually code and help make it better you can fork the project here:

https://github.com/cmstead/ClickBeetleJS

Important things you should know:

ClickBeetleJS requires jQuery.
Pull requests won’t be accepted without passing tests associated.
All my tests are written with QUnit. Please write yours using the same framework.

I hope this is useful for you.

Help me make the web a better place.

Comments Off
Similar posts in Coding, Javascript, User Experience

We Live in a Biosphere

You may or may not be aware of this, but when we are interacting with an application, we are entering a biosphere. People always talk about suites of applications as being an ecosystem, but even within the constraints of single app, we are still interacting with a smaller, but equally important, ecosystem.

About three years ago, I wrote a blog about page-behavior taxonomy or, as I generally refer to it now, behavior taxonomy. This taxonomy is really a mental model the user creates based on previous interactions they have had within your page, site or application.  It’s really crucial to understand that as you present links, behaviors and interactions, you are training your user.  When you break that interaction model, you are breaking rules the user expecting you to follow.

Consider the biosphere projects scientists construct for the purpose of experimentation.  Everything in that tiny ecosystem must work together properly.  If an element is introduced which changes the ecosystem, it could cause a breakdown of the entire experiment. These small changes are what happens when the biological equivalent of microinteractions are not considered.

The key to considering these mental models is to look at the application as a whole and start developing an expectation of what the user will experience throughout their time in your app or site. If you look at the app as a whole early on, then it becomes clear what each interaction should bring.  Think about how people are going to move about.  What kinds of input are they going to give.  Why are they doing it and how would they expect it to work?

Of course you should expect change, but the if the initial behavior taxonomy is sound, new additions will only serve to enhance the experience.  If, on the other hand, care is not taken to develop the rules to which your app should adhere, you will paint yourself into a corner.  You will make decisions early on which will force your hand later on.  If you choose to break from the model, you will also break your users trust If your app is something that is going to be foisted upon users, they will learn to deal with it and resent you.  If your app is something users interact with by choice, they will leave.

In the end, we are all in this little biosphere together.  Let’s live in peace and harmony.  Consider the environment and care for it. Your users will thank you for it. Consider your app’s behavior taxonomy and make the web a better place.

Comments Off

Monetizing the Web

Today I read an article about Irish newspapers plotting to charge for linking to their content. We’ve all heard about this before and people seem to get up in arms about it every single time it is mentioned. I think this frustration and disgust are misplaced.

See, here’s the deal: if you want to make money from people using your site, you have to get them there.

Ultimately, there is a paradigm shift that happened with the web which traditional media is having a hard time wrapping their brains around — links are gold. They are the currency of the web and the word of mouth in the electronic universe.

At one time, it made sense for media outlets to limit the distribution of their content through other media channels. It hurt sales and trimmed valuable advertising money from their pockets. They never said “don’t mention our article to people or we’ll charge you.” That’s foolishness. Big media wanted, and still wants, people to know they got the scoop before anyone else. It keeps them in business.

So why limit linking? It limits the number of page views and, subsequently, the amount of advertiser money that comes in.

I get it. They want you to click around the site looking for that one piece of content you heard about. The problem? News sites pretty much universally stink with regard to user experience and findability. If it isn’t on the front page it may as well have never happened. This is the heart of their problem, really. They are spending so much time trying to milk every penny out of someone’s pocket they can’t see they need some real help.

My message you to, media outlets: Fix your sites. Make them easier to use. Put your reader first instead of your pocketbook. The advertising money will come. If you want to erect paywalls, fine, but don’t kill the one thing which might save you. Protect your links. Treat them like someone handed you free money. Encourage people to share. If you don’t, I won’t be angry, I’ll just never know you existed. Do us all a favor and make the web a better place.

Comments Off

Stop Worrying About Your Followers

Yeah, I said it. Knock it off. Stop worrying about how many people are following you on Twitter. Forget about how many friends you have on Facebook. Quit fussing over whether someone stopped following you or decided they didn’t want to be your “friend.” They don’t know you any more than you know them. It’s nothing personal, they just stopped.

Social strategists say that every follower counts. Each person who is on that magical list is a potential lead waiting to be tapped. Honestly, that’s likely untrue. Of all the people who have friended, followed, liked, thumbs-upped, uprated, upvoted, kudos-gave or otherwise gave you two seconds of their attention, there is only a small percent which are actually in the market to buy something.

Some of the people liked that little one-liner you rattled off one day when you were feeling smug. That guy over there thought your opinion matched his own. Those three women who started following you are actually men and they are just goofing off.

In the end, follower or friend counts are much like the stock market. If you watch them daily to see whether you’re trending up or down, it will make you neurotic. Trust me, I know a thing or two about being neurotic. If you really need to keep an eye on things, do a weekly report. Look at last week’s numbers and compare them to the numbers you gathered today. Was there growth? Was there attrition? How bad was the attrition? How good was the growth?

In the end, people are slaves to their whim. What might engage them today could drive them off tomorrow. If you are seeing small wiggles in your count, consider it normal human behavior. If you see large, sweeping sinusoidal trends, maybe there’s something to gain from the behavior.

In the end, the follower or friend count is a small part of a much bigger story. When you start assembling your data, keep that in mind and don’t use that single statistic to drive your online behavior. If you can just do that, you’ll help alleviate your own stress and make the web a better place.

Comments Off

Plan Your Device Strategy

As mobile gains ever more ground and mobile first continues to be knocked around as the design strategy for the web, I encourage people to look at their use statistics.  Although mobile first is a great strategy if you don’t have statistics to draw upon for your site, or your reorganization needs a mobile injection, nothing will serve you better than the statistics regarding what your user does on your site.

Instead of simply adopting an oversimplified “mobile first” strategy, I decided it would be best to figure out what the user is doing in each mobile context.  For the simple sake of reason, I generally say we have three platforms and four positions to deal with.  Either your user is on a small-profile device like a phone or palm-top computing device, they are on a tablet, or they are on a standard computing device.

This gives us something really easy to work with.  There are three devices, two of which have two orientations.  It might seem like this translates to 5 total designs to commit to.  Fortunately, the phone in landscape is just about the same width as the tablet in portrait.  We are left with four design contexts to worry about.  Realistically, though, we can start with just three pieces of the puzzle and extrapolate the intermediate fourth.

My latest project, for which I am leading a team, needs two key items to make sense of the high-priority items on the site: device used and pages accessed.  After a bit of careful fiddling, I uncovered the following chart:

Device to Traffic Chart

Device to Traffic Chart

This chart helped me to figure out what our device strategy would be.  Clearly our visitors from mobile devices have much more limited interests than those visiting from a standard computer interface.  Mobile first means we should guess at what should go on a site and what the user will want to do on a smaller device.  By analyzing the data, we can clearly define interactions on mobile devices which may, actually, not be important to highlight on the desktop.

Instead of working with mobile as a pared down version of a complete site, we should aim to understand what a user wants to accomplish in a different context.  This is not a cut and dried rule of thumb but something we can produce through a little bit of careful reflection on what users are doing right now.

For your next project, instead of taking a mobile-first design stance, review your user data and serve users in each platform according to their needs.  Provide clear signposts for your users.  Develop a device strategy and make the web a better place.

Comments Off

Herding Cats or Looking at Curated Search

You know what makes Google awesome? Their search algorithm is pretty darn smart. You know what makes DOMZ awesome? Every stinking link on there has been verified by a real, honest-to-goodness human being. You know what sucks about site search on most websites, even when they’re running a Google custom search? The only time a human ever looks at the search is when they are actually using it to find something.

This is where a curated site search comes in.

When I say curated, I mean it in much the same way a museum curator takes care of the displays, carefully selecting the pieces to display and updating things as new events and collections are integrated or moved out of public display. Think about it, if you went to a site looking for glasses for your cat and did a search saying “Siamese cat glasses,” wouldn’t it be awesome if, right above all the standard mediocre search results, you got a little bit of content saying “we’ve got glasses that will look great on your Siamese cat?”

Of course it would.

The benefit of this is that you have a better understanding of what a person is looking for than a computer ever will. Why? Two reasons, really. First is because you are a person and, I suspect, you have done searches for things before. Second, no matter how good the crawler is that indexes your site, you have access to your analytics, which means you know what people are searching for. (You’re running analytics, right?)

An example of how this works can be found on the HP site. Below is a screencap of what their search looks like if you search for TouchSmart. (I picked that term because it is their current ad and I knew I would get something good. Color me sneaky.) You’ll note they have a list of search results on the screen, but the very first thing to come up is a link straight to the TouchSmart product information.

HP Curated Search Content

Pretty sweet, right?

Okay, maybe looking at a computer search page doesn’t get you all revved up and ready for action, but imagine if that image were your Siamese cat in need of glasses. Now we’re talking turkey, right?

That cat needs some glasses

This doesn’t do anyone any good if it doesn’t do anyone any good, right?

Absolutely.

What?

The long and short of it all is, by curating content for commonly searched items on your site, you make the information/product/widget/catglasses more findable. This means you are more likely to have conversions from site visitor to customer. Benefit to your customer: ease of use. Benefit to you: more business. Stick that in your ROI pipe and smoke it, Mr. Executive.

In the end, everyone wins when things are easier to find. Since so many users are search-centric, you can serve them well by anticipating the searches they are going to perform and give them the info you know they want up front. This front-loading of work helps to provide a clear signpost for users to do what they were at your site to do: make with the business with you. In short, if you are running a site search for your users you should consider curated content to provide for common searches and make the web a better place.

Comments Off

Moving Pieces: Organizing for a Website Overhaul

I’ve read several different books and articles about web projects and how to make sense of what needs to happen when. Everyone has their own slant and it flavors how the entire process should go. Meanwhile they hope the “magic” in another group is happening.

It’s really important to have a list of the things you need to accomplish. I am not going to tell you who does what. That depends on your team and how you dole things out. I will tell you that each of these pieces needs to be addressed or you’ll have a tough time moving to the next step.

Without anyere’s my core list of stuff to check off:

  1. Analysis
    • Business and user needs
    • Content Inventory and analysis
    • Site analytics (Look at search terms. This is your user talking TO YOU)
    • Personas
    • Brand, voice and message
  2. Collect moving pieces
    • Curated existing content (text, images, documents, etc.)
    • New content (Get it early or you’ll hate yourself later)
    • Process functions (search, dynamic functions for displaying content, etc.)
  3. Design and prepare
    • Information Architecture (Hierarchy, page layout, workflow, wireframes, etc.)
    • Build structured documents containing all raw copy for the site
    • Colors, designs, images, flow, implemented voice and message
    • Get info about servers, technical needs, etc.
    • Prepare SEO deployment plan
  4. Build
    • Prepare comps using design specs and wireframes
    • Build templates to house content based on wireframes
    • Implement design via styles as comps are completed
    • Edit content to match voice and message and begin inserting into CMS
    • Prepare SEO: descriptions, titles, friendly URLs, etc.
    • Prepare 301 redirects for old pages being replaced or moved (I feel this SEO technique is important enough it needs to be stated separately)
    • Ensure servers are online, technical needs are met and everything is ready for launch
  5. Launch
    • Stage site out of the public eye and QA completely
    • Deploy site (Post-QA)
    • QA for sanity (All pieces are behaving like they were on staging, nothing is broken)
    • Celebrate!
  6. Postmortem
    • Review analytics and compare to pre-release stats
    • Inventory new site (include all new copy, new images, etc.)
    • Review conversions

Build your core list of needs and lead your team to the promised land. One project at a time, make the web a better place.

Comments Off

Project Kickoff: Prepare to Deliver the Goods

We’ve all been there at some point or another. A new project is just about to start. Everyone in the know is bracing for impact and the people who are going to contribute are blissfully unaware of the monster lurking around the corner.

Generally the kickoff goes like this:

“Hey, everyone, our client needs an update to their website. You know what you need to do, so let’s hit it. Peace out.”

Do they know what they need to do? At a high level, maybe? Probably not, really.

Stakeholders don’t know what’s coming. The client doesn’t know what they need. The design and development units are waiting until the other one is done with “their part.” In the end, everyone scrambles at the 11th hour and the project comes together. Barely.

Let’s hit rewind and do this kickoff the right way. If you are a team lead, figure out what you need. Sort out who your users are and what business needs are being addressed on your site. Contact stakeholders early, share what you need and the listen to what they want. Use this to sort out your priorities. Organize the moving parts, call your team together and give them the rundown.

Once people have their marching orders, collect everyone for happy hour. This is the first step in a long journey, start it with a cheers instead of a fizzle. Kick off your projects right and make the web a better place.

Comments Off