with Imagination: by Dustin Diaz

./with Imagination

A JavaScript, CSS, XHTML web log focusing on usability and accessibility by Dustin Diaz

Stop coding right now!

Wednesday, June 21st, 2006

Whatever it is. Whatever you’re working on. Whatever last piece of code snippet you just wrote. STOP! And ask yourself these questions.

Are you solving any real problem? Is this going to be helpful to real people? Are you advancing something, one thing, anything? Is that last line of code you wrote going to make an impact?

Not sure where to start? Try this exercise:

Word of caution

Before doing this, make sure you have time. If you have a deadline coming up, then don’t read this. This is not for you; right now.

Ok, open up your code editor

That’s right. Fire that puppy up, and open that last file you were just working on. To make this easier on yourself, most text editors come with a open recent document feature so pick one of those that has been the most interesting to you within the last {n} number that are listed.

Now that you have that open, pick a line number between 1 and the total amount shown. Or if you know the document too well and that’s not going to help the random factor, try scrolling up and down the document using your mouse while keeping your eyes closed. After an arbitrary amount of seconds, stop, then point your finger in the middle of the screen to a line of code.

Now, what’s the sole purpose of that line of code? Why did you write it? Did it solve anything? What about the code that is immediately surrounding it? Is that code solving any real problem?

The point?

This is just a friendly reminder to not forget that writing code should have a purpose. Too often as developers and engineers we get caught up in making things superfluous in our code that we lose site of the actual problems we’re trying to solve. That’s it. That’s all. Now have a good day.

47 Responses to “Stop coding right now!”

  1. Pete Boere

    if(nametxt==(”||’ ‘)) nametxt=’zzz’;

    I must have been bored

  2. Jamie Fehr

    " alt="" class="lead-image" />

    Absolutely vital to my new wordpress theme. But thanks for interruption, I will attack this day with renewed purpose.

  3. Thomas Frank

    Object.prototype.states=function(){return stateHandler.returnMe(this)}

    Working on a state/memento handler for JavaScript objects… Because I’m tired of writing undo/redo functions over and over.

  4. Daniel James

    ‘This is just a friendly reminder to not forget that writing code should have a purpose.’

    Why? If someone’s paying you to write it or depending on you in some way, fair enough. But otherwise?

    10 PRINT "Taking pleasure in purposeless coding since 1984."
    20 GOTO 10
  5. kentaromiura

    World.conquer(”less than 5 minutes”);

  6. Sam

    @order = Order.new

    Yup, pretty vital!

  7. Michael Thompson

    @d = @d.line(@graph_left - 10, y, @graph_right, y)

    Tweaking Gruff to better layout. If I ever get some free time, I’m going to rewrite it a bit to enhance the functionality, display, etc. and return the code to its author.

    Not vital, but it’d be nice if Gruff were a bit more, well, “grown-up”.

  8. Rémi

    $this->pagesTable = $this->ffConf["setPagesTable"];

    This line is absolutely necessary, but I shall remember this technique and do it more often :-)

  9. Adam Spooner

    slug = models.SlugField(prepopulate_from=(’title’,))

    100% needed. It’s used to map the url.

    Thanks for the reminder that every bit (no pun intended) of code matters!

  10. Nate

    if ( DataStore::hasResults($allBooks) )

    Definitely important, checks to see if we have books for listing. hehe.

    This is a great post, and should be done more often by developers.

  11. Jesse Skinner

    return PathGenerator.getUserKeyvisualURL(userID) + getFilePrefixBuffer();

    Um, yeah pretty important.

    What about you, Dustin?

  12. Jody

    function is_malicious($input) {

    Yup. Gotta have it. But that was just good timing on my part. I’ll remember this (or put a big posty note on my laptop.) Thanks!

  13. Daniel

    else echo ‘Next ‘ . $len . ‘ Calendar Events:’;

    Is quite necessary I suppose :D Just doing some parsing of my 30Boxes calendar using PHP.

  14. Adriaan

    Now well that’s pretty obvious isn’t it…

    $MyWeb = new Innovation();

  15. Seb

    typo: “site” should be “sight”.

  16. Dustin Diaz

    Wow! What a great turn out. I went ahead and tried it myself following my own instructions exactly. When I opened up a file and scrolled around a bit (my eyes were even closed), I stopped then pointed in the middle of the screen and landed on this of all things!

    var DED = window.DED || {};

    Go figure. Without that, my code is done for.

  17. Joseph Szymbabwe

    I got a question, did you right this after a near-death experience ’cause it sounds like one of those motivational ‘don’t jump’ books for developpers. :p just joking. Good post!

  18. Peter Goodman

    By title, I really thought this article was going somewhere else.. Oh well :P

    It took me a while to find a good file.. there is either not enough code in some files or too many comments..

    $finder = &$this->getFinder(’thread_tags’);
    $tags = &$finder->selectWhere(’COUNT(*) as tag_count’, ”, array(), 1);

    I’m sure you can guess what that does ;)

  19. Wally

    Agreed. There’s a lot of fluff out there that does not enhance the user experience or improve performance. Probably a good exercise in learning, but a useless feature for intended audience: the damn users.

  20. Mike

    // Useless code below to waste time

    Do comments count?

  21. Elliot Swan

    I picked line 40…Turns out, this is what line 40 is:

    
    

    Basically, blank. :P So I go down one line:

    
    var testing = 'target'+opener'.on'+e;
    

    Debugging.

  22. Elliot Swan

    I just thought I should add, that blank line is also quite important. Just as whitespace is a big part of frontend design, I think whitespace is quite important in the actual layout of one’s code. Good spacing makes things 10 times easier to follow.

  23. brian rountree

    Testing to see if product reviews for a given product are available from multiple partner feeds.

    Kinda important, if someone wants to read all the related information and reviews for a tech product

  24. Luke

    @repeats_on

    Line 162 for me! w00t!

    Useful? yes. Frustrating? Yes. Point? Make some $$. hehe.

  25. Luke

    good grief. no html escaping, dustin??

    here’s the code after postable

    @repeats_on << Time.utc((y.to_i e.to_i), months_to_num[n], h).to_i

  26. Timothy Rosenberg


  27. Steve

    rc = fscanf(f, “Drumkit Make:%[^\n]%*c”, dkmake); linecount++;

    Hastily written code to read in drumkit file
    for a drum machine program. Definitely needed,
    though it could certainly be better written.
    (I mean fscanf? Really. What was I thinking?
    Well, I was thinking “I’ll clean this up later,
    right now I just want that drumkit out of that
    file and into RAM, and NOW.)

    I’m trying to think of an example of writing
    code that doesn’t do anything useful. I’m having a hard time imagining the sort of “useless” code… Well, I did add French translations to this program, and I don’t speak French, nor know anybody who does. I let google translate everything, so they are abominable translations to boot. Arguably useless code, LOL. But it’s pretty well cordoned off from the rest, so the whole program isn’t exactly polluted with krufty translation garbage, and arguably the infrastructure could be used to do more translations with trivial effort. Still useless? Probably.

    Then there is at least one faild user-interface experiment. I had no way of knowing it was going to fail without trying it out though.

    The other sort of useless code I write is little toy programs written purely for entertainment, or education, like a little program to try to use an evolutionary algorithm to produce MIDI music. An utter failure, in that the selection process involved listening to loads of random crap. So it was pretty useless, although I did learn not to attempt that path again, and how to write code that talks to MIDI devices (leading to the drum machine program…)

    I don’t think “useless code” is a problem which needs solving any more than “books I find boring” are a problem libraries need to solve.

  28. Rami Kayyali

    Ok, I think this technique can apply to a gigantic print of your current app’s UI: point anywhere with your eyes closed, now ask yourself it those few pixels are doing anything important.

    I just couldn’t figure out why would anybody write a single line of code without a purpose? And no, Microsoft’s feature-bloat doesn’t count.

  29. Sanat Gersappa

    Sums up what I felt yesterday after trying out Java EE 5 (supposedly, an improvement over J2EE). The sheer complexity of the framework (even after simplification) made me ask myself what problem I was trying to solve.

    Now I realize that technology is just a means, not an end. The end is the solution to the problem (if there exists one).

  30. Riddle

    I saw today jQuery library and thought about your post, Dustin. :]

  31. Rami Kayyali

    I think this can apply more to a UI design rather than code. Print a really large banner with your current app UI on it, now close your eyes and point somewhere then ask yourself if that particular icon is conveying anything to the user.

    I’m not sure than anybody would write *any* line of code without a purpose, even the witty comment. //

  32. Nick Fitzsimons

    First go with some Java servlet code:

    // TODO autogenerated stub method

    Hmm, lets try some JS:

    this.postcodeField.value = this.postcode = postcode.trim();

    Yes, we need that bit :-)

  33. Stuart Robertson

    A good excercise — I immediately found something I did the easy/repetitive way, instead of the “good”/efficient way.

  34. Math Code Monkey

    q[igrid]( I1,I2,I3, vc ) = flowParameters.initialData.v;

    Great little piece, though. Reminds me of Richard Hamming’s comments… He was running research at Bell Labs and would roam around the cafeteria and sit with random research groups. In no time he would ask the uncomfortable questions:

    “What are the most important problems in your field? Are you working on one of them? Why not?”

    He’s point was simply that “It is better to solve the right problem the wrong way than to solve the wrong problem the right way.”

    Read his piece on
    “You and your research”

  35. Daniel Kempkens

    Line 52: $_cache[] = (trim_empty($value)) ? ‘true’ : ‘false’;

    A function that check which elements of e.g. the $_POST Array are empty.
    If all elements are really not empty (no whitespaces etc.) the function returns true, otherwise it returns false.

  36. Milos

    Hi there!

    […] A very accosting layout and a interesting discussion topic, do you provide any Web-based services to universities or students. […]

    Greetings Milos

  37. richard m

    line:091, This is for rosary (a Catholic prayer said on beads) widget.
    this.Beads.OF= ”+spaces+’Our Father,Who art in Heaven,hallowed be Thy Name.Thy kingdom come,Thy will be done on earth as it is in Heaven.Give us this day our daily bread, and forgive us our trespasses,as we forgive those who trespass against us.And lead us not into temptation, but deliver us from evil.Amen.’;

  38. Pauly

    Where the questions in this post not rhetorical then?

  39. Rob

    mov ah,09
    lea dx,message
    int 21h

    :)

  40. Magnet

    Crap.. i am done for…

  41. This Week’s Weekly Links of the Week - Week 7 » SOME RANDOM DUDE

    [...] Stop coding right now! - Dustin Diaz [...]

  42. redbaks

    line 584: }

    quite important for me.

  43. Shawna

    ?php the_content(’Continue Reading?’); ?

    I suppose displaying my posts is pretty important, eh?

    Great post, BTW :)

  44. Abba Bryant

    intPageSize = 10

    Well now that’s boring. And needed in this case.
    Thanks for the diversion and chance to get philosophical instead of frustrated.

  45. Ali

    include(’functions.php’);

    It may solve a lot of problem, who knows? ;)

  46. John Hansen

    if (!is_array($aQueryString) || empty($aQueryString))

    Yeah, I need that =)

  47. Graham B

    tree[tree.length]={name:t3,subs:new Array()};

    It might not look much, but I had just realised the vast benefits of using JScript rather than VBScript when my hand is forced to use ASP. Yesterday I was struggling with safeArrays and Dictionary objects, now I’ve a face like a hindu cow in a field of dot notation goodness.

Get "JavaScript Design Patterns"

"As a web developer, you'll already know that JavaScript™ is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked--JavaScript is capable of full object-oriented capabilities, and by applying OOP principles, best practices, and design patterns to your code, you can make it more powerful, more efficient, and easier to work with alone or as part of a team."

Buy JS Design Patterns from Amazon.com Buy JS Design Patterns from Apress

All content copyright © 2003 - 2009 under the Creative Commons License.

Archives | Blog Search