• Chatter
  • Development
  • Insights
  • Honk.com

Archive for March 8th, 2010

Javascript Design Idiom – Build Wide Not Deep

Posted March 8th, 2010 in Development by Brian

Providing a rich user experience calls for good client side software. Javascript is a powerful language to provide the needed functionality. Like any other tool it has it’s strengths and weaknesses. Successful design in Javascript favors composition, loose coupling, and separation of concerns more so than in most other languages. To see why, let’s look at some of the properties of Javascript.

Javascript is a prototype language with loose and dynamic typing. It is a flexible language. You have anonymous functions. You can alter objects at any time. You can aggregate functions from many sources. It provides closures and dynamic invocation. Also, each web page can be treated as a separate “application”, so you often do not need to have too many interacting pieces.

Javascript can also be a difficult language to use. Javascript does not give you a dependable stack trace. The debuggers often leave much to be desired. The weak type system makes it difficult to discern objects from each other. Inheritance is difficult.

These characteristics make it beneficial to build via composition. It makes sense to have loosely coupled objects. It also makes sense to unit test your Javascript software. It makes sense to craft the code to be scannable.

That being said, I really enjoy developing in Javascript because it encourages (or forces) me to better design my code. Working with a good testing framework leads to a quick, red/green/refactor cycle.

The Maintenance Costs of Complex Objects

Unfortunately, it is difficult to build an example because complexity in Javascript requires complex code. So I’m not really going to show code examples, but talk at a higher level.

Since Javascript does not provide good stack traces it becomes very time consuming to debug complex functions. To combat this problem, you should take advantage of Javascript’s flexibility and make loosely coupled functions that are composable. Good abstractions are important.

A good example of this is jQuery.

$(“.person”).click(function() {$(this).toggleClass(“active”);});

When an element with the ‘person’ class is clicked, the ‘active’ is toggled. Now imagine doing this with the old imperative style of Javascript. I could write the example, but it hurts to write and read, so I will spare you of it.

The more you can express in one line or one thought, the better.

Now these concepts are do not need to be constrained to DOM manipulation and hooking up events. You can add client/server concepts to the mix. Need to handle the case where the user can click on filters, each of which creates an Ajax request to update the search results? Don’t inline the code, create a function to do this. Give it a memorable name, like lastAjaxWins (not that that is the best name ever, but it is a memorable phrase).

The idea is to have consistent levels of abstraction. It may be expedient to have a function that has inconsistent levels of abstraction, but Javascript will not be very forgiving when you need to maintain and debug your code.

Fortunately, if you unit test and have loosely coupled objects and functions, your code will be easier to think about and your will not need to debug as much.

Heuristics to Measuring Complexity

Javascript makes complexity especially bad. When developing Javascript software, it helps to have some heuristics to keep the complexity down.

Talk About It

Whenever I complete a piece of functionality, I try to recreate the mental model of where this piece fits in on the web page. It should be clear, distinct, and easy to talk about. Talk about it with somebody. Is it easy to summarize?

If not, it is probably too complex. Break it apart. Create functions and objects which you can name. Compose these names to describe dependent objects.

Use Your Test Framework

A good javascript test framework (a couple of examples are Screw Unit and Jasmine) allows for nested ‘describe’ blocks and ‘it’ blocks (nested SUT’s, contexts, and test cases). When writing the name of the ‘describe’ block and ‘it’ block, try to capture the system under test, the situation of the test, and what happens. Be descriptive and precise. Don’t be vague. Being vague is cheating.

This is important because the length and complexity of your statements are a good indication of the complexity of the functionality you are testing.

Are the tests very painful to write? Are there repitive paterns? If yes, then that may be an indication that you need to extract something.

Refer to your Mental Model

Think about the client/server interaction. Whenever you add functionality, think about how it fits into the overall picture. Unless you are doing really heavy client side development, it should be easy to think about how that object and/or function fits into the picture. If you are doing heavy client side development, use good abstractions. Talk in the language of your abstractions. Let the concepts permeate through your consciousness. Having an intuitive grasp on your past, present, and future problems and solutions.

What color is your car?

Posted March 8th, 2010 in Chatter by Josh

What does the color of your car say about you? Are you conservative, flashy, adventurous, eco-conscious, funny, or thoughtful?

Colors can serve as an expression of who we are, broadcasting aspects of our personality and our sense of style.  Buyers today have access to an endless array of color options from Wooden Nickel (medium dark gray) to Simple Chaos (blue) to Authentic Replica (dark red).  We’ve come a long way since the automobile was first introduced and Henry Ford famously remarked that Model T customers could have their cars painted in, “any color they want, so long as it’s black.”

So what’s up with all the black, white, and silver cars?

I ran across Dupont’s report on the World’s Most Popular Car Colors and was surprised to find that almost half of the world’s driving population gets into a black or silver vehicle every morning.  Another third of the world’s cars are a shade of gray or white.  Only the final 25% are “real” colors.

Even more interesting than the top 10 global results were the regional differences.  Europeans chose black as their top color.  North Americans and the Japanese chose white.  The booming populations of China and India enjoy silver.  What do you think these color choices say about the cultures they spring from?

The regional data also highlighted some other interesting differences.  In China, for instance, silver and black make up almost 60 percent of all new cars.  In North America, the top two colors (white and black) make up less than 35 percent.

Have the Chinese been taking their inspiration from Henry Ford or is there another reason they’re avoiding brighter hues?

The one thing the data consistently shows is that most people don’t stray far from the traditional colors of our automotive forefathers.  I think it’s a shame that when people have options like Light Intensity Orange, Crystal Crème Beige and Serious Fun Green, they more often than not choose Plain Old Gray.

Next time you’re given that choice, I’d encourage you to step out of the box and go for Running Start Yellow!

Transparency is key to a great deal

Posted March 8th, 2010 in Featured by Matt

It’s no secret that most people hate haggling over the price of a new car.  Fighting with salespeople is awkward and no one wants to drive home and find out that their neighbor got the same car for $500 less.

Why can’t a dealership just tell you how much a car costs and then give you a fair price?  Do they really think that they can get you to pay more by being sneaky?

Results from a 2008 study by Synovate eNation found that most consumers don’t have a problem with dealers making a fair profit – but they do have a major fear of getting stuck with a bad deal.  So the more a dealer tries to hide the truth, the harder most consumers will fight back in negotiations.  This practice is bad for customer satisfaction and bad for profit margins.

At Honk, we figured that if we can show you how much a car really costs, you’ll know whether or not you’re getting a good deal.  So we started with a clean sheet of paper and built a pricing section that skips the gimmicks and shifts the balance of power to you, the consumer:

How do you know if you’re getting a great deal?

Want to know how much a car costs?  Want to know what other people actually paid?

So do we – and that’s exactly why we feature pricing data from TrueCar.  They analyze transactions from around the country and can tell you which deals are good, great, or laughable.

The number you probably want to know most is the TrueCost figure, which estimates how much the vehicle actually cost the dealership.  Once you know this figure you can estimate how much – or how little – a dealer is making on the sale.

The TrueCost is especially handy when you need to know whether or not a salesperson is lying after they shout, “But we’re not making any money on this deal!”

We think that TrueCar rocks because they give you the perspective you need to judge an offer and the details you need to win a great one.

Skip the haggling altogether

Even better, if haggling stinks so much, why not just skip it altogether?

Honk has an auto buying service that can help you skip the haggling on new cars in most major markets.  The prices are pre-negotiated and posted up front.  All you have to do is build the car you want to buy and we’ll show you up to three prices from dealers in your area.  You don’t even have to give up your name or email address until you’ve selected a dealer to work with.

Other car sites will promise you a price and then sell your contact information to multiple dealership as a sales lead.  That means that you won’t get a price until someone from Crazy Joe’s Car Emporium interrupts your dinner the next night with an obnoxious sales call.

Honk’s auto buying service is designed to keep you in charge.  We’ve even integrated TrueCar pricing data so that you can see for yourself how the Honk price stacks up against what you could negotiate on your own.

Long story short: we think we’ve built a better way to research and buy a new car.  Just remember to tell Crazy Joe that Honk sent you.