Archive for May, 2011

Ten Oddities And Secrets About JavaScript

Advertisement in Ten Oddities And Secrets About JavaScript
 in Ten Oddities And Secrets About JavaScript  in Ten Oddities And Secrets About JavaScript  in Ten Oddities And Secrets About JavaScript

JavaScript. At once bizarre and yet beautiful, it is surely the programming language that Pablo Picasso would have invented. Null is apparently an object, an empty array is apparently equal to false, and functions are bandied around as though they were tennis balls.

This article is aimed at intermediate developers who are curious about more advanced JavaScript. It is a collection of JavaScript’s oddities and well-kept secrets. Some sections will hopefully give you insight into how these curiosities can be useful to your code, while other sections are pure WTF material. So, let’s get started.

Data Types And Definitions

1. Null is an Object

Let’s start with everyone’s favorite JavaScript oddity, as well known as it is. Null is apparently an object, which, as far as contradictions go, is right up there with the best of them. Null? An object? “Surely, the definition of null is the total absence of meaningful value,� you say. You’d be right. But that’s the way it is. Here’s the proof:

alert(typeof null); //alerts 'object'

Despite this, null is not considered an instance of an object. (In case you didn’t know, values in JavaScript are instances of base objects. So, every number is an instance of the Number object, every object is an instance of the Object object, and so on.) This brings us back to sanity, because if null is the absence of value, then it obviously can’t be an instance of anything. Hence, the following evaluates to false:

alert(null instanceof Object); //evaluates false

2. NaN is a Number

You thought null being an object was ridiculous? Try dealing with the idea of NaN — “not a numberâ€� — being a number! Moreover, NaN is not considered equal to itself! Does your head hurt yet?

alert(typeof NaN); //alerts 'Number'
alert(NaN === NaN); //evaluates false

In fact NaN is not equal to anything. The only way to confirm that something is NaN is via the function isNaN().

3. An Array With No Keys == False (About Truthy and Falsy)

Here’s another much-loved JavaScript oddity:

alert(new Array() == false); //evaluates true

To understand what’s happening here, you need to understand the concepts of truthy and falsy. These are sort of true/false-lite, which will anger you somewhat if you majored in logic or philosophy.

I’ve read many explanations of what truthy and falsy are, and I feel the easiest one to understand is this: in JavaScript, every non-boolean value has a built-in boolean flag that is called on when the value is asked to behave like a boolean; like, for example, when you compare it to a boolean.

Because apples cannot be compared to pears, when JavaScript is asked to compare values of differing data types, it first “coercesâ€� them into a common data type. False, zero, null, undefined, empty strings and NaN all end up becoming false — not permanently, just for the given expression. An example to the rescue:

var someVar = 0;
alert(someVar == false); //evaluates true

Here, we’re attempting to compare the number 0 to the boolean false. Because these data types are incompatible, JavaScript secretly coerces our variable into its truthy or falsy equivalent, which in the case of 0 (as I said above) is falsy.

You may have noticed that I didn’t include empty arrays in the list of falsies above. Empty arrays are curious things: they actually evaluate to truthy but, when compared against a boolean, behave like a falsy. Confused yet? With good cause. Another example perhaps?

var someVar = []; //empty array
alert(someVar == false); //evaluates true
if (someVar) alert('hello'); //alert runs, so someVar evaluates to true

To avoid coercion, you can use the value and type comparison operator, ===, (as opposed to ==, which compares only by value). So:

var someVar = 0;
alert(someVar == false); //evaluates true – zero is a falsy
alert(someVar === false); //evaluates false – zero is a number, not a boolean

Phew. As you’ve probably gathered, this is a broad topic, and I recommend reading up more on it — particularly on data coercion, which, while not uniquely a JavaScript concept, is nonetheless prominent in JavaScript.

I discuss the concept of truthy and falsy and data coercion more over here. And if you really want to sink your teeth into what happens internally when JavaScript is asked to compare two values, then check out section 11.9.3 of the ECMA-262 document specification.

Regular Expressions

4. replace() Can Accept a Callback Function

This is one of JavaScript’s best-kept secrets and arrived in v1.3. Most usages of replace() look something like this:

alert('10 13 21 48 52'.replace(/\d+/g, '*')); //replace all numbers with *

This is a simple replacement: a string, an asterisk. But what if we wanted more control over how and when our replacements take place? What if we wanted to replace only numbers under 30? This can’t be achieved with regular expressions alone (they’re all about strings, after all, not maths). We need to jump into a callback function to evaluate each match.

alert('10 13 21 48 52'.replace(/\d+/g, function(match) {
	return parseInt(match) < 30 ? '*' : match;
}));

For every match made, JavaScript calls our function, passing the match into our match argument. Then, we return either the asterisk (if the number matched is under 30) or the match itself (i.e. no match should take place).

5. Regular Expressions: More Than Just Match and Replace

Many intermediate JavaScript developers get by just on match and replace with regular expressions. But JavaScript defines more methods than these two.

Of particular interest is test(), which works like match except that it doesn’t return matches: it simply confirms whether a pattern matches. In this sense, it is computationally lighter.

alert(/\w{3,}/.test('Hello')); //alerts 'true'

The above looks for a pattern of three or more alphanumeric characters, and because the string Hello meets that requirement, we get true. We don’t get the actual match, just the result.

Also of note is the RegExp object, by which you can create dynamic regular expressions, as opposed to static ones. The majority of regular expressions are declared using short form (i.e. enclosed in forward slashes, as we did above). That way, though, you can’t reference variables, so making dynamic patterns is impossible. With RegExp(), though, you can.

function findWord(word, string) {
	var instancesOfWord = string.match(new RegExp('\\b'+word+'\\b', 'ig'));
	alert(instancesOfWord);
}
findWord('car', 'Carl went to buy a car but had forgotten his credit card.');

Here, we’re making a dynamic pattern based on the value of the argument word. The function returns the number of times that word appears in string as a word in its own right (i.e. not as a part of other words). So, our example returns car once, ignoring the car tokens in the words Carl and card. It forces this by checking for a word boundary (\b) on either side of the word that we’re looking for.

Because RegExp are specified as strings, not via forward-slash syntax, we can use variables in building the pattern. This also means, however, that we must double-escape any special characters, as we did with our word boundary character.

Functions And Scope

6. You Can Fake Scope

The scope in which something executes defines what variables are accessible. Free-standing JavaScript (i.e. JavaScript that does not run inside a function) operates within the global scope of the window object, to which everything has access; whereas local variables declared inside functions are accessible only within that function, not outside.

var animal = 'dog';
function getAnimal(adjective) { alert(adjective+' '+this.animal); }
getAnimal('lovely'); //alerts 'lovely dog';

Here, our variable and function are both declared in the global scope (i.e. on window). Because this always points to the current scope, in this example it points to window. Therefore, the function looks for window.animal, which it finds. So far, so normal. But we can actually con our function into thinking that it’s running in a different scope, regardless of its own natural scope. We do this by calling its built-in call() method, rather than the function itself:

var animal = 'dog';
function getAnimal(adjective) { alert(adjective+' '+this.animal); };
var myObj = {animal: 'camel'};
getAnimal.call(myObj, 'lovely'); //alerts 'lovely camel'

Here, our function runs not on window but on myObj — specified as the first argument of the call method. Essentially, call() pretends that our function is a method of myObj (if this doesn’t make sense, you might want to read up on JavaScript’s system of prototypal inheritance). Note also that any arguments we pass to call() after the first will be passed on to our function — hence we’re passing in lovely as our adjective argument.

I’ve heard JavaScript developers say that they’ve gone years without ever needing to use this, not least because good code design ensures that you don’t need this smoke and mirrors. Nonetheless, it’s certainly an interesting one.

As an aside, apply() does the same job as call(), except that arguments to the function are specified as an array, rather than as individual arguments. So, the above example using apply() would look like this:

getAnimal.apply(myObj, ['lovely']); //func args sent as array

7. Functions Can Execute Themselves

There’s no denying it:

(function() { alert('hello'); })(); //alerts 'hello'

The syntax is simple enough: we declare a function and immediately call it just as we call other functions, with () syntax. You might wonder why we would do this. It seems like a contradiction in terms: a function normally contains code that we want to execute later, not now, otherwise we wouldn’t have put the code in a function.

One good use of self-executing functions (SEFs) is to bind the current values of variables for use inside delayed code, such as callbacks to events, timeouts and intervals. Here is the problem:

var someVar = 'hello';
setTimeout(function() { alert(someVar); }, 1000);
var someVar = 'goodbye';

Newbies in forums invariably ask why the alert in the timeout says goodbye and not hello. The answer is that the timeout callback function is precisely that — a callback — so it doesn’t evaluate the value of someVar until it runs. And by then, someVar has long since been overwritten by goodbye.

SEFs provide a solution to this problem. Instead of specifying the timeout callback implicitly as we do above, we return it from an SEF, into which we pass the current value of someVar as arguments. Effectively, this means we pass in and isolate the current value of someVar, protecting it from whatever happens to the actual variable someVar thereafter. This is like taking a photo of a car before you respray it; the photo will not update with the resprayed color; it will forever show the color of the car at the time the photo was taken.

var someVar = 'hello';
setTimeout((function(someVar) {
	return function()  { alert(someVar); }
})(someVar), 1000);
var someVar = 'goodbye';

This time, it alerts hello, as desired, because it is alerting the isolated version of someVar (i.e. the function argument, not the outer variable).

The Browser

8. Firefox Reads and Returns Colors in RGB, Not Hex

I’ve never really understood why Mozilla does this. Surely it realizes that anyone interrogating computed colors via JavaScript is interested in hex format and not RGB. To clarify, here’s an example:


Hello, world! <script> var ie = navigator.appVersion.indexOf('MSIE') != -1; var p = document.getElementById('somePara'); alert(ie ? p.currentStyle.color : getComputedStyle(p, null).color); </script>

While most browsers will alert ff9900, Firefox returns rgb(255, 153, 0), the RGB equivalent. Plenty of JavaScript functions are out there for converting RGB to hex.

Note that when I say computed color, I’m referring to the current color, regardless of how it is applied to the element. Compare this to style, which reads only style properties that were implicitly set in an element’s style attribute. Also, as you’ll have noticed in the example above, IE has a different method of detecting computed styles from other browsers.

As an aside, jQuery’s css() method encompasses this sort of computed detection, and it returns styles however they were applied to an element: implicitly or through inheritance or whatever. Therefore, you would relatively rarely need the native getComputedStyle and currentStyle.

Miscellaneous

9. 0.1 + 0.2 !== 0.3

This one is an oddity not just in JavaScript; it’s actually a prevailing problem in computer science, and it affects many languages. The output of this is 0.30000000000000004.

This has to do with an issue called machine precision. When JavaScript tries to execute the line above, it converts the values to their binary equivalents.

This is where the problem starts. 0.1 is not really 0.1 but rather its binary equivalent, which is a near-ish (but not identical) value. In essence, as soon as you write the values, they are doomed to lose their precision. You might have just wanted two simple decimals, but what you get, as Chris Pine notes, is binary floating-point arithmetic. Sort of like wanting your text translated into Russian but getting Belorussian. Similar, but not the same.

More is going on here, but it’s beyond the scope of this article (not to mention the mathematical capabilities of this author).

Workarounds for this problem are a favorite on computer science and developer forums. Your choice, to a point, comes down to the sort of calculations you’re doing. The pros and cons of each are beyond the scope of this article, but the common choice is between the following:

  1. Converting to integers and calculating on those instead, then converting back to decimals afterward; or
  2. Tweaking your logic to allow for a range rather than a specific result.

So, for example, rather than…

var num1 = 0.1, num2 = 0.2, shouldEqual = 0.3;
alert(num1 + num2 == shouldEqual); //false

… we would do this:

alert(num1 + num2 > shouldEqual - 0.001 && num1 + num2 < shouldEqual + 0.001); //true

Translated, this says that because 0.1 + 0.2 is apparently not 0.3, check instead that it’s more or less 0.3 — specifically, within a range of 0.001 on either side of it. The obvious drawback is that, for very precise calculations, this will return inaccurate results.

10. Undefined Can Be Defined

OK, let’s end with a silly, rather inconsequential one. Strange as it might sound, undefined is not actually a reserved word in JavaScript, even though it has a special meaning and is the only way to determine whether a variable is undefined. So:

var someVar;
alert(someVar == undefined); //evaluates true

So far, so normal. But:

undefined = "I'm not undefined!";
var someVar;
alert(someVar == undefined); //evaluates false!

You can also check Mozilla's list of all reserved words in JavaScript for future reference.

Further Resources

(al) (il)


© Mitya for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us
Post tags: , ,


Inspiration Shift: Tilt-Shift Photos and Effects

Advertisement in Inspiration Shift: Tilt-Shift Photos and Effects
 in Inspiration Shift: Tilt-Shift Photos and Effects  in Inspiration Shift: Tilt-Shift Photos and Effects  in Inspiration Shift: Tilt-Shift Photos and Effects

With all of the various techniques and lenses that photographers use to create over the years in the development of their craft, we see many spring to the forefront of the industry to take hold. Of these that are popular with the public, several have been adopted by graphic artists who attempt to replicate the outcome with their own works. One that continues to grow in favor with the masses is tilt-shift photography.

Across the Web there are tutorials and tools that can assist any amatuer shutterbug or graphic artist with applying this technique to their photos after the fact. No longer is this popular style only available to those with the expertise and the proper, high end equipment. And the replication processes are getting even better with each new iteration. In fact, below we have a mix of both real tilt-shift photos and altered photos to make them appear to be tilt-shift. See if you can tell the difference!

Photography Mix

Image38 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift of Commonwealth Stadium by Ainsley Baldwin

Image1 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift train by Josh Mock

Image8 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift by mackenzie

Image31 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt-shift Vôlei by Paulo Guedes

Image41 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift Test 3 by Brian Finifter

Image5 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift by evanrudemi

Image61 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift cemetery by George Foster

Image9 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt-Shift Baseball by Jonathan Assink

Image10 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt-Shift – First attempt by drew_anywhere

Image111 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift Diamond Head by Kyle Nishioka

Image121 in Inspiration Shift: Tilt-Shift Photos and Effects
Fake Tilt-shift by James Turnbull

Image131 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift Test 2 by Brian Finifter

Image142 in Inspiration Shift: Tilt-Shift Photos and Effects
Met tilt-shift by hey tiffany!

Image15 in Inspiration Shift: Tilt-Shift Photos and Effects
Millook beach, Cornwall tilt-shift by Adrian Byrne

Image16 in Inspiration Shift: Tilt-Shift Photos and Effects
Backhoe tilt-shift by Mrs. Gemstone

Image171 in Inspiration Shift: Tilt-Shift Photos and Effects
River Thames tilt-shift by Rob Hawkes

Image18 in Inspiration Shift: Tilt-Shift Photos and Effects
second tilt-shift test: Santa Fe Depot by Chris Radcliff

Image191 in Inspiration Shift: Tilt-Shift Photos and Effects
The tiny bus- tilt-shift by David Rynde

Image71 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift by mackenzie

Image201 in Inspiration Shift: Tilt-Shift Photos and Effects
Gherkin tilt-shift by Rob Hawkes

Image211 in Inspiration Shift: Tilt-Shift Photos and Effects
NY_Tilt_Shift by Daniele Pesaresi

Image22 in Inspiration Shift: Tilt-Shift Photos and Effects
Paradise Point tilt-shift by Robert Simmons

Image23 in Inspiration Shift: Tilt-Shift Photos and Effects
Mercadillo (tilt-shift) by Jose Maria Miñarro Vivancos

Image24 in Inspiration Shift: Tilt-Shift Photos and Effects
dubrovnik tilt-shift by nonanet

Image25 in Inspiration Shift: Tilt-Shift Photos and Effects
My First tilt-shift by Scot Campbell

Image26 in Inspiration Shift: Tilt-Shift Photos and Effects
Frontierland at Dusk (tilt-shift) by Justin Ennis

Image27 in Inspiration Shift: Tilt-Shift Photos and Effects
Sydney Opera House tilt-shift by hey tiffany!

Image28 in Inspiration Shift: Tilt-Shift Photos and Effects
Fake tilt-shift lens effect by Janne Moren

Image29 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt-Shift Zebra Stripe by Jon Mountjoy

Image30 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift by Jim Sher

Image311 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift sofas by Richard-G

Image32 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift Amsterdam by Angelogyn

Image33 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift lens test2 by Jargalsaikhan Dorjnamjil

Image34 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt-Shifted Monaco by bobito

Image21 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift – 2nd attempt by drew_anywhere

Image35 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt&Shift Paris by weckscjo

Image36 in Inspiration Shift: Tilt-Shift Photos and Effects
Tilt-shift, Osaka by jim

Image37 in Inspiration Shift: Tilt-Shift Photos and Effects
tilt-shift of Rexall Place by Ainsley Baldwin

Image39 in Inspiration Shift: Tilt-Shift Photos and Effects
Tokyo + tilt-shift by Leo Lambertini

Image40 in Inspiration Shift: Tilt-Shift Photos and Effects
Manitou Incline by Angie Bowen

< < Tilt-Shift miniature faking is a creative technique whereby a photograph of a life-size location or object is manipulated to give an optical illusion of a photograph of a miniature scale model. Altering the focus of the photography in Photoshop (or similar program) simulates the shallow depth of field normally encountered with macro lenses making the scene seem much smaller than it actually is. In addition to focus manipulation, the tilt-shift photography effect is improved by increasing color saturation and contrast, to simulate the bright paint often found on scale models. >>

Tilt-Shift Resources

If you enjoyed this showcase and would like to try your hand at this technique post photo then take a look at some of the assembled goodies below to get your tilt-shift angling towards something more visually stunning:

Tutorials

Generators

(rb)


Getting Started With Defensive Web Design

Advertisement in Getting Started With Defensive Web Design
 in Getting Started With Defensive Web Design  in Getting Started With Defensive Web Design  in Getting Started With Defensive Web Design

Nothing ruins a great website UI like people using it. At least, it often feels that way. You put in days or weeks building the interface, only to find that a vast majority of visitors abandon it partway through the process that it supports. Most of the time, visitors leave because they’ve hit a roadblock: a problem that lets them go no further. They typed their credit card number wrong or clicked the wrong link or mistyped a URL. And it’s not their fault.

Business-strategy-user-needs-portal-funtionality in Getting Started With Defensive Web Design
What exactly is meant by defensive design? Image by Richard Winchell

A good design assumes that people make mistakes. A bad one leaves visitors stuck at a dead end because they mistyped one character. The best professionals account for this with smart, defensive design strategies (also known as contingency design).

Defensive Design Means…

I’m a simple guy. In the book Defensive Design for the Web, 37Signals defines defensive design as such: “Design for when things go wrong.”

Gets right to the point, doesn’t it? Defensive design anticipates both user and website error. Then, it tries to prevent those errors and provide help to get the user back on track. Defensive design for the Web usually focuses on the most common points of failure: forms, search, the address bar and server problems.

Defensive design:

  • Employs validation to check for mistakes before they frustrate the user,
  • Expands available options based on the user’s implied intent,
  • Protects site visitors from server errors and broken links with informative messages and
  • Assists the user before mistakes happen.

Defensive Design: Business Sense

If you want to grow your online business or just improve your blog, defensive design is one of the easiest upgrades — instead of trying to build audience, defensive design helps you better serve the audience you’ve got. The latter is far, far easier than the former.

What-is-strategy in Getting Started With Defensive Web Design
Self-explanatory. Image by What consumes me

Think about it: You can work on marketing, search engine optimization, community-building, display ads and content strategy, and attract 1,000 new visitors. If 5% of visitors to your online store make a purchase, then those 1,000 new visitors mean 50 new orders. Or, you can practice defensive design. That might increase your current conversion rate from 3% to 3.5%, adding 50 new orders.

The best way to learn defensive design? By example. Here’s a quick overview of best practices, plus some tips for doing it yourself.

Inline And Contextual Help

The best contingency design prevents errors from occurring. Sometimes a simple tip or explanation can prevent error and visitor frustration. Instead of making customers trek to a separate help area, try to assist them with tips and instructions inline or in context.

Inline help offers pointers on specific items on the page. 37Signals provides inline help throughout its applications. For example, I can find out exactly what the 30-day trial of BaseCamp entails without leaving the page:

37signals-inline-help2 in Getting Started With Defensive Web Design
Inline help on 37Signals clarifies the conditions of the free trial.

The inline help box appears the moment I roll over “30-day free trial.� It’s easy to read, well positioned and clearly related to the free trial. And the language is crystal clear. This is important. Defensive design is as much about the message as it is about the circumstances that call for it.

Contextual help provides guidance relevant to the current page or process. Hence, “contextual.� Unlike inline help, contextual help usually relates to the entire page, and it can appear without a click or rollover.

WordPress offers contextual help in the administration area of the application. The “Get help with dashboardâ€� message appears the first time you open the dashboard. The message might be a bit too lengthy, but it’s helpful and it is right for the given context. Note the simple language, plus the option to dig deeper by going to the full documentation or support forum:

Wordpress-contextual-help1 in Getting Started With Defensive Web Design
WordPress contextual help alerts me to helpful instructions.

HootSuite explains every feature of its application and service packages with simple inline help boxes. The boxes answer basic questions at a glance, without pulling users away from the all-important sign-up page:

Hootsuite-inline-help in Getting Started With Defensive Web Design
HootSuite uses inline help to explain individual features.

These websites all anticipate that users might miss certain features and requirements. And then they present those features with clear direction, in context. Make no assumptions! A field, button or feature that makes total sense to you may be nonsense to the typical visitor. Provide help.

Slow Connections

Another, subtler form of defensive design accounts for slow Web connections. Downloads can slow to a crawl on mobile connections. When that happens, visitors may be forced to find their way through your website without images or Flash elements to guide their way.

37Signals makes sure that you can read its entire content, including interactive elements, without images. It does this by relying more on CSS and text than on images. Even if the background and images don’t load, critical navigation, calls to action and rollover elements will still work:

3signals-no-images1 in Getting Started With Defensive Web Design
Even without images, users can use the 37Signals’ website.

A List Apart looks a bit minimal without images, but everything from the articles to the navigation remains in place. Users can easily find and read the articles they want:

Alistapartnoimages in Getting Started With Defensive Web Design
The layout of A List Apart is preserved even without images.

CNN’s home page remains intact without images. Visitors can see all links, search tools, navigation and content in exactly the same position as if images were displayed:

Cnn-no-images in Getting Started With Defensive Web Design
CNN’s website remains 90% intact and navigable without images.

Some designers still want 100% control over type and layout, and they want the freedom to use images, Flash and other slow-loading elements to achieve it. But more and more users are accessing the Web on wireless connections, which are getting faster but are still unreliable. Plan ahead and have a website that still works when bandwidth shrinks.

On-Site Search

On-site search is wonderful, if visitors can actually find what they’re looking for. If your website contains a lot of often misspelled words for products, concepts or services, then your search tool may be an exercise in tooth-gnashing frustration. Anticipate misspellings and typos and turn on-site search into an asset.

Amazon’s on-site search tool automatically recommends close matches. It presents the same kind of “Did you mean?� message that Google does, plus it displays results for the correct spelling of the query:

Amazon-search-typo in Getting Started With Defensive Web Design
Amazon modifies search results to show products that match correct spellings.

Like the others, CNN provides closest-match spelling correction. Then it provides two other sets of options: top stories for the closest match and top general searches on the website for that week. The correction and variety of results get visitors back on track so that they don’t have to perform a second search.

Cnn-search-typo1 in Getting Started With Defensive Web Design
CNN returns the closest match of spelling, plus top stories.

These examples anticipate typographical and spelling errors. Sometimes, though, a visitor submits an unusual query: for example, “java� instead of “coffee,� or “band� instead of “ring.�

Zappos provides a graceful solution by making its search results transparent. The website examines your query and shows categories and concepts to which your search maps. Plus, the user has the option to remove any of the categories from the search result:

Zappos-search1 in Getting Started With Defensive Web Design
Zappos clarifies how it delivers results and lets you correct them.

So, if I submit the wrong query, Zappos might show me the wrong results, but it also shows me why the results are wrong and helps me figure out a better search.

If you’re just running a small website in your spare time, these automated search suggestions and mapping tools may seem out of reach. But they’re not. Tools like Google’s Custom Search give you them from the start. And if you’re feeling nerdy, solutions like Lucene come with entire libraries that do “Did you mean?� matching and let you customize matches. Or you can write your own script to identify common misspellings and handle them exactly the way you want. How fancy you get is up to you.

Form Validation And Error Handling

Forms are the number one cause of customer’s hate. Filling out a form requires a lot of work — it forces you to do the hardest combination of clicking-typing-clicking, and often involves digging through your wallet for credit cards and other information. A typo, missing field or incorrectly formatted phone number can force a visitor into a loop of retype-submit-retype, fixing their errors one at a time. Smart defensive design starts with clear direction (see the section on “Inline Helpâ€� above).

But mistakes happen. So, defensive form design does the following:

  • Preserves visitor data
    When a user is returned to a form to fill in missing data, the website should keep completed fields filled in. The visitor should be able to fix their errors without retyping the entire form.
  • Highlights errors with clear graphics and text
    Fixing and completing entries should be obvious and easy.
  • Doesn’t make the visitor feel like a criminal
    Full-caps messages telling the visitor that “YOU COMPLETED THE FORM INCORRECTLY� aren’t exactly endearing.

Wufoo highlights errors, explains exactly what the user did wrong and preserves the data across refreshes, which makes corrections easy. The only problem with the design is that the message “There was a problem creating your account� doesn’t tell me anything useful. A more descriptive message would be better.

Wufoo-form-validation1 in Getting Started With Defensive Web Design

Wufoo highlights what you did wrong, but a clearer message would help a lot.

FreshBooks keeps it nice and simple. Even better, it doesn’t make users feel like they’ve failed a test:

Freshbooks-form-validation in Getting Started With Defensive Web Design
The form message on FreshBooks is simple and friendly.

Complex and simple form layouts can provide equally great feedback and help users get back on track, as the following screenshots of SEOmoz and MailChimp show.

Seomoz-form-validation in Getting Started With Defensive Web Design
SEOmoz’s form tells you when two fields don’t match.

MailChimp uses JavaScript to validate inline as you type, so you can correct mistakes before submitting the form:

Mailchimp-form-validation-javascript in Getting Started With Defensive Web Design
MailChimp validates before you click “Submit,� saving you even more time.

Another interesting technique for defensive design in Web forms is presented on Mailchimp when a user tries to delete his/her subscriber list from their account. The tool requires a user to manually type “DELETE” to confirm the action. A nice example of making sure that the list will not be deleted by accident. The technique might look a bit annoying at first glance, but it clearly minimizes the error rate for users who delete sensitive data by mistake.

Mailchimp-delete in Getting Started With Defensive Web Design
“Type ‘DELETE’” pattern on Mailchimp. It will save users some headache.

Great contingency design never gets in the way. In all of these examples, each error is highlighted. Also, the description of the error is positioned near the relevant field, so it’s easy for visitors to find and fix the mistake. This keeps the form compact, maintains eye flow and lets the visitor continue with their task uninterrupted.

“Page Not Found� Errors

On the internet, broken links are abundant. A webmaster may have moved a page or mistyped the URL in a link, or a visitor may have left out a forward slash from an address. Whatever the cause, the last thing the user wants to see is this vaguely hostile message:

Bad-404 in Getting Started With Defensive Web Design
A bad 404 page. Somewhat upsetting, isn’t it?

Great websites customize their “Page not found� area (also called a 404 page), by providing options, explaining what happened or even injecting a little humor into what can otherwise be a frustrating experience.

ThinkGeek includes full navigation on its 404 page. It also provides a search form, so if I know what I’m looking for but not the URL, I can submit a query to track it down. (Assuming the Jedi mind trick doesn’t work…)

Thinkgeek-404 in Getting Started With Defensive Web Design
ThinkGeek tries Jedi mind tricks but doesn’t rely solely on them.

Climate Wisconsin keeps it simple, with two options on their 404 page. It’s easy to quickly digest, and the visitor can immediately decide their next action:

Climate-wisconsin-404 in Getting Started With Defensive Web Design
Climate Wisconsin’s 404 error page is simple and to the point. A search functionality could be a useful helper for users, though.

You don’t have to make the 404 page a work of art. Just make sure that if a detour is required, you do the following:

  • Reassure visitors that you’re still there by branding the page.
  • At a minimum, link back to the home page.
  • Ideally, provide concrete options for getting back on track.

Server Errors

Sometimes things just go kerploiee. That’s a technical term for when your server, tired of its humdrum day-to-day existence, stops delivering pages, flips over on its back, lets out a horrid gurgling sound, and utterly fails to deliver content, data, information or anything else.

Normally, this will give the user a message like this:

500-server-error1 in Getting Started With Defensive Web Design
A standard 500 server error. Scary at the best of times.

Imagine you’re the visitor. What does this page tell you? That the apocalypse is at hand? Or that you have to find something called a “server error log”? Which pretty much means the apocalypse is at hand. Either way, you’re going to cross this website off your list.

Great contingency design accounts for everything, including servers going kaput.

Here’s the page on Carsonified. It explains what happened and lets you send a message to its developer, Elliott Kember:

Carsonified-error in Getting Started With Defensive Web Design
Carsonified leaves nothing to chance, and it says a few words about the person who may have caused the error.

The Food Network isn’t as entertaining, but it certainly makes sure that users know it’s still in business. And like any good 404 page, it gives users a few ways to get back on track:

Food-network-500 in Getting Started With Defensive Web Design
Even if the Web server dies, a user knows that the Food Network is still around.

Brushfire Digital explains the error, provides navigation and contact information and, again, makes sure you know it’s still there:

Brushfire-500-error-in-Great-examples-of-defensive-design in Getting Started With Defensive Web Design
Brushfire makes sure you know it’s not you — it’s them.

Again, you don’t need to create a work of art. Just make sure visitors know that the error probably isn’t their fault and that you’re taking care of it.

Detect Holes In Your Defenses

Some defensive design issues are easy to spot: bad forms, error messages and inline help are obvious. But you can spot subtler issues and their solutions using some basic Web analytics.

The Checkout Funnel

You can grow sales in a hurry by getting more of your existing audience to purchase. That’s far easier than getting more visitors. So look at your checkout funnel to see if there are any places where many new customers abandon their shopping cart. In this example, over 70% of visitors who place items in their cart abandon the checkout process. The overall sales conversion rate is 1.7%:

Checkout-funnel-1 in Getting Started With Defensive Web Design
A broken checkout funnel. It’s losing 70% of potential customers at the first step.

This is a true story, by the way. The problem was very clear: customers abandon on the initial checkout page. We thought the cause might be the page’s layout. It gave visitors a strong impression they’d have to register in order to check out. So, we changed the page, adding inline help and a modified layout to make the guest checkout option clearer. Cart abandonment on the first page dropped dramatically, and overall sales conversion rate improved to over 3% (I wish I could show you the resulting data and the pages, but client confidentiality and all that).

The Missing Link (page)

Sometimes, prominent third-party sites link to you. And sometimes they link to you incorrectly. While a good 404 page (see above) can help, you’ll still lose a lot of visitors — they’re clicking a link on a site they trust. When the target site shows a “Page not found” error, the visitor will likely click the “Back” button. In a perfect world, you’d put a custom page at the linked URL, and then use that to gently steer visitors to the right place. Or, you can set up a 301 redirect from the broken URL to the correct one. But how do you find these links? If you’re using a hosted analytics solution like Google Analytics, it won’t report 404 errors out of the box.

A quick look at Google Webmaster Tools, or a little Web server log file analysis, can help you spot these problems. Look for pages that show repeated 404 errors. In the example below, Google Webmaster Tools shows a 404 error from a link placed on 29 different pages. That’s a broken link that begs for redirection or a transition page:

Broken-links-gwt in Getting Started With Defensive Web Design

Broken links in Google Webmaster Tools. 29 pages? This one needs a redirect.

This kind of analysis and fix enables defensive design even when you didn’t cause the problem. And again, it lets you build audience, sales and leads without getting new visitors. You’re just improving the experience of current ones.

Avoid Common Mistakes

Walk a mile in your visitors’ shoes, and you will easily be able to avoid the most common defensive design mistakes.

Mistaken Assumptions

Never, ever assume that visitors will “figure it out.� Nor assume that they have any familiarity with your website. Your visitors have plenty of options — the Web’s a big place. Cater to their needs, and be prepared to handle every imaginable mistake. The fewer assumptions you make, the more bulletproof your design will be.

Fake 404s

When you set up your 404 error page, make sure that the server delivers a 404 error code if a page doesn’t exist. Some developers and Web hosts instead redirect users to the 404 error page with a temporary or permanent redirect.

Fail-Snail in Getting Started With Defensive Web Design
The Fail Snail. Image by Todd Bernard

Those redirects deliver a 302 or 301 code, which usually tells search engines to index your error page at many different URLs. I won’t go into the painful details of canonicalization and why this is bad. Take my word for it: the 404 error code was created for a reason. Use it.

Limited Landing Pages

Visitors will come to your website via links, search results and who knows what else. That makes every page a potential landing page. So, practice good defensive design on all of them.

Lousy Copy

Carefully write and edit your copy for inline help, error messages and other contingencies. Your visitors’ patience will already be strained. This is your chance to fix the problem and maybe even start to build a great relationship with them. Make every word count.

Limited Browser Compatibility

Every contingency must work in all browsers. If visitors need the latest browser to see inline help, then it’s not very helpful, is it? Use progressive enhancement to ensure that everyone benefits from every element on the page.

Good For The Brand, Good For The Business

Almost any brand can benefit from good customer service. Defensive design lets you deliver great service effortlessly when your customers need it most. It builds sales and makes customers love you. So, hope for the best and plan for the worst.

It pays to plan for user mistakes and bugs. If you’ve ever managed a website, then you know you’re guaranteed a few bumps along the way. And while putting all of these defensive design measures in place is extra work, it also means more happy visitors. And that means business growth from the audience you have.

Other Great Defensive Design Resources

  • “Amazon gets even more defensive,â€� Signal vs. Noise.
  • Defensive Design for the Web, 37Signals
    I’m not a 37Signals fanboy, I swear.
  • Bulletproof Web Design, Dan Cederholm
    Another great read.
  • useit.com, Jakob Nielsen
    A treasure trove of all sorts of usability-related wisdom, including defensive design.

(al)


© Ian Lurie for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us
Post tags: ,


Designing the Airwaves: Podcast’s Part in Design

Advertisement in Designing the Airwaves: Podcasts Part in Design
 in Designing the Airwaves: Podcasts Part in Design  in Designing the Airwaves: Podcasts Part in Design  in Designing the Airwaves: Podcasts Part in Design

One powerful outlet that many designers have been turning to over the recent years, which in turn has allowed for a further evolution of the design community and conversation, is podcasting. This completely accessible, and open format for extending the design dialog is proving a viable solution for many seeking to lend their voice to the field in another way altogether. And by actually lending their voice to the process, no longer in just a metaphoric manner.

Radiotower in Designing the Airwaves: Podcasts Part in Design

Image Credit

So how does one go about throwing their proverbial hat into this ring, and just exactly why do they do it? Those are a couple of the questions that we will tackle in this post, which will then end in a showcase of outstanding contributions to the design airwaves. So if you are either a fan of the form or perhaps looking to find your own footing in this continuously burgeoning market for designers then hopefully this post can give some food for thought for the weekend to accompany the new listening material provided.

The Why

There are many reasons that designers have opted for this direction in order to engage the community. However there are three major headers that most design podcasts fall under, when you begin looking into the reasons they cast. It is more than the accessibility it offers, in fact, it tends to be more tied to the community aspect of the field in one way or another.

To Teach

One of the main missions that we see when designers turn to the virtual airwaves, is so that they can educate the masses. So many podcasts are out there to provide the community with another resource that can be tapped when you are working in the field. Whether you are a relative newcomer to the market, or even a seasoned veteran, the design arena is constantly evolving and we have to keep up with those changes. In fact, it is a staple piece of advice within the field, that if you want to make it, then you need to always be learning.

Podcasts have provided yet another means for designers to reach this end, and so we see many moving to this platform in order to teach others what they have learned along the way, techniques that they developed over the years, or even what their guests have to offer. It is one thing to set up a tutorial, but some people learn better with more auditory instruction, and so podcasts can work better for them overall. Not to mention that some lessons that need to be taught are handled better more anecdotally. Just like blogging can achieve this connection and impart these lessons, podcasting can do the same thing in via an auditory presentation.

To Preach

Another powerful motivator that drives designers to the casting side, is to further that engagement that they have through their blogs. They can use this platform to establish themselves as an authority in the field. Be it in a particular niche, or in more general terms , some designers come to these waters because they feel their perspective is a valuable one and they are going to share it. They want to help steer the directions the field might take and they set out on the airwaves to make their mark.

Tworoads in Designing the Airwaves: Podcasts Part in Design

To help guide the community down an alternate path is a mission that brings some to the format. Image Credit

While blogging can help designers to plant their authoritative seeds, podcasting can engage with the community on a much more personal level. With writing it is easy to keep the tone professional and the personality reigned in. However podcasting is a different beast where personality goes a long way. So it does take a slightly different approach than blogging, though the paths are somewhat parallel. And given that both can prove essential with the authority establishing, it is easy to see why many in the field are walking both roads.

To Reach

The third major reason that designers opt for this form, is to help extend their reach with their audience. This needed reach extension could be for helping them to build their following, develop their brand, or simply to offer an added source for revenue. Whatever the purpose they use this reach for, it is often the extra mileage they can attain into the heart of the community that pushes them towards the podcasting outlet. And when they consider how easily one can break into this field it does improve their chances of being found and heard above the horde.

The How

As previously mentioned, podcasting is a very accessible market, which you can dive right into with a small investment of capital or a large one. It really is up to you. Either way you go, the only other investment required on the part of the podcaster is time. This too can vary depending on the style and length of show you are wanting to produce. But one that must be considered nonetheless. And if you have the time to commit, then it can really prove worth your while to try your hand at the casting.

The Gear

First off in order to get started, you are going to need the proper equipment, and again, the amount that you invest in the equipment is really up to you. Most designers already have the computer covered which can be the biggest hurdle on this path. Some sort of microphone is required, as well as some sort of recording software. That is about it. And the great thing is that when it comes to software, there are both free and premium options that rank highly among users. And if your computer is a laptop with a decent built-in microphone, then three of your bases are already covered.

If you plan to add an interview or call in element to your show then naturally things get more complicated, as does the equipment or software necessary to pull it off. Skype is a wonderful free tool for being able to connect with others and have them on the podcast and there are free programs like MP3 Skype Recorder that will do just that. Record your entire call and save it as an .mp3 file. So high priced mixers and attachments are not that necessary for a more modest program. Mac users may find getting started particularly easy if they already have Garageband installed. It even has added sound clips and effects to juice up your program that free apps like Audacity lack.

More Tools and Resources

  • TalkShoe is a web based service that allows you to create calls and have podcast participants join in on the show.
  • Propaganda Podcasting Software is a relatively inexpensive program for windows users for recording their shows.
  • Adobe Audition CS5.5 is Adobe’s premium recording solution.
  • Podcasting Tools is a site that can help point you in the right direction with any of your podcasting needs.

The Grind

Like with anything, there is a fair amount of work involved with putting a podcast together that also needs to be considered in this discussion. The grind is still fairly easy in comparison to most, however there are a couple of areas where you are going to need a little guidance. For example, in order to get started delivering your podcast to your audience, you are going to need to consider, coordinate, and implement a delivery system. The web is full of services to help you connect your podcast with an audience, iTunes, Podcast Alley, and so many more. WordPress users can also take advantage of various plugins that help in this area as well.

Podcasting-plugin-image in Designing the Airwaves: Podcasts Part in Design

One of the most important elements to this delivery system, especially if you intend for users to be able to subscribe to your feed, or to set up that feed through these various sites and services, is to create and manage an .xml file for your podcast. Also when you begin trying to calculate how much time you must invest into the show, you have to account for not only the recording time, but also the time it takes to edit the show together, adjust your .xml file, create a blog entry for the new episode (if applicable), and the time it takes to convert and upload the necessary files. So it can become quite a project depending on the scope you have taken with it.

The Gab

Before when we mentioned the personality that the format carries with it, that was to highlight how important it is you bring some of this to the show yourself. If you want your show to connect with the audience, then the host tends to have to be somewhat personable, relatable, or otherwise bring something vibrant and exciting to the table. The gift of the gab is a common phrase that does apply in this context. In order for your podcast to rise among the rabble then you need to be able to engage your audience, and it tends to take a bit of that gift to make this happen.

The Bar

Below are some active design based podcasts that come highly recommended, and are certainly worth checking out. Especially if you are considering starting a podcast of your own, the bar has been set by these fantastic design related casts that have come before you, so you might want to give them a listen to see what is already being done, and how.

Workers of the Web

Workersofweb in Designing the Airwaves: Podcasts Part in Design

Web Workers, UNITE! Witness the molten glow of pixels as they strike your screen-burned face. Now raise your calloused, carpal tunnel twisted fist into the air and scream, “I. AM. A WEB WORKER!”

TEDTalks

Tedtalks in Designing the Airwaves: Podcasts Part in Design

Each year, the TED (Technology, Entertainment, Design) conference hosts some of the world’s most fascinating people: Trusted voices, and convention-breaking mavericks, icons and geniuses. These podcasts capture the most extraordinary presentations delivered from the TED stage.

SitePoint Podcast

Sitepoint in Designing the Airwaves: Podcasts Part in Design

News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.

Think Vitamin Radio

Thinkvitaminradio in Designing the Airwaves: Podcasts Part in Design

Think Vitamin Radio is a bi-weekly podcast, typically around 20 minutes in length. Topics will include web design, web development, and web applications as well as news and views from host Keir Whitaker with Ryan Carson and Mike Kus.

37signals Podcast

37signals in Designing the Airwaves: Podcasts Part in Design

A look at the world of 37signals, the Chicago-based web application company. Discussions about business, design, experience, simplicity, and more. Featuring Jason Fried and David Heinemeier Hansson.

The Boagworld Show

Boagworldshow in Designing the Airwaves: Podcasts Part in Design

Boagworld is a podcast for all those involved in designing, developing or running a website on a daily basis. The show is divided into seasons consisting of 6 episodes. Each season covers a particular topic and is accompanied by an associated ebook. They also interview leading figures in the world of web design including people like Jeffrey Zeldman, Jeremy Keith and Andy Clarke.

Designer Roundtable Podcast

Designerroundtable in Designing the Airwaves: Podcasts Part in Design

The Designer Roundtable Podcast is a podcast about design, business and freelance. Come chat with us!

Design Matters with Debbie Millman: 2009-2011

Designmatters in Designing the Airwaves: Podcasts Part in Design

Design Matter with debbie Millman is a thought-provoking internet podcast, which profiles industry-leading graphic designers, change agents, artists, writers and educators.

(rb)


Design is Life

Advertisement in Design is Life
 in Design is Life  in Design is Life  in Design is Life

Design is life.
I always liked to believe that I was meant for a lot more than what my societies perception of life thought it should be like. I come from a culture with very little appreciation for passion and the arts, and from a very young age I knew deep down in my heart that [...]


© SM-Network-xheight for Smashing Magazine, 2011. | Permalink | Post a comment | Smashing Shop | Smashing Network | About Us
Post tags:


  •   
  • Copyright © 1996-2010 BlogmyQuery - BMQ. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress