Jan

30

Write better code not bigger code

By ian

One of the hardest things for most programmers and developers to grasp is that being a good programmer is about more than just writing code. Many programmers spend hours upon hours pooring over O’Reilly books hoping to memorize a few more functions or learn a new design pattern. While this knowledge is important, there are a lot of things that are more important.

Over on Coding Horror, Jeff Atwood wrote a great post about becoming a better programmer by not programming. It seems counter-intutive, but he makes a lot of good points. One of the quotes from the Design Observer is particularly relevant.

…the great thing about graphic design is that it is almost always about something else. Corporate law. Professional football. Art. Politics. Robert Wilson. And if I can’t get excited about whatever that something else is, I really have trouble doing a good work as a designer. To me, the conclusion is inexcapable: the more things you’re interested in, the better your work will be.

This quote is equally appropriate for programmers. Its rare that we are programming for other programmers, so why do programmers have a tendency to focus only on code.

Each program is designed to solve a problem. Some programmers don’t care whether the problem is organizing documents, handling a database of employee info or creating an e-commerce site. They treat each project with the same mindset. Chances are they are writing more code than neccesary, creating a bad UI, or otherwise making software that doesn’t solve the problem well. In the end, programming is all about solving problems and code is just a part of the solution.

One of my biggest pet peeves in this area are captcha images. We’ve all seen these horrible images of random and distorted alpha numeric characters that plague almost every forum and many blogs. These images are followed by a little textbox that you’re supposed to type the series of unreadable characters into.

yahoocaptcha5gt.jpgunreadable_image.gifunreadable_captcha1.png

This seems like an absolutely ridiculous solution to the problem. There are a few reasons why this isn’t a good solution:

  1. It’s way more code than neccesary. I doubt your average spam program can analyze graphics at all, nevermind graphics that people can’t even read.
  2. You’re users hate it. Trust me.
  3. Most of these captcha systems hide the value in a hidden field or cookie value, which is actually makes it easier for the value to be seen by code than by people.
  4. The biggest reason. In most cases there is a more viable solution

The assumption that we need an image to display the value isn’t neccesarily bad, but distorting the image is likely unneccesary. I find it funny that most bloggers are convinced that a spam spider can’t figure out ian[at]sundermedia.com but somehow has an advanced algorithm for dectecting text in images. Try to write code to decipher that image, then decide if the precious data on your blog is worth that much time to a spammer when there is so much unprotected data around.

A simple static image with readable text in a non-system font would be sufficient for 90% of systems. I’ve also seen systems where you have to click on a picture of a certain animal or answer simple questions(What color is a banana?). For most sites, these methods solve the problem in a way that both uses less code and provides a better user experience.

So, on your next project when you’re churning out 1,200 lines of code a day, take a minute to make sure that there isn’t a better solution to the problem you’re trying to solve.

2 Responses so far

I have to disagree Ian.

A post on CodingHorror back in October details Jeff’s analysis of CAPTCHA effectiveness: http://www.codinghorror.com/blog/archives/000712.html

Give it a read :P

As for the “better solution”, lets take the Access database I had to read out last night. Since access to Access was not an option, I spent 30 minutes coding a little app to pull out each table and write the resulting dataset as an XML schema and XML document for the data. Yes, there are better solutions out there, but I got to flex my brain for 30 minutes to make a solution.

Sometimes there is a benefit in “rolling your own”, which is why I can understand when pre-sales clients come back to me and say “we’ve decided to do this all internally”. The one company that I did not expect to hear that from was the Software division of Intel… As the saying goes “You’ve gotta kiss a lot of frogs to find a prince.”

Hello! Good Site! Thanks you! ywkstdvffxi

Leave a comment