Make It Better, Stupid

Whenever I write code, I churn out garbage. I do it this way so I can get the general idea down and mess around with the problem. I don’t need a good solution to solve my problem while I’m in development, I need a working solution. Once I get a working solution, I go back and I optimize the code and I eventually write something that doesn’t look like a baby panda threw up on my keyboard.

Today I optimized this:

 tags.each do |tag|
   tag.strip!
   tag_object = Tag.find_by_name(tag)

   tag_object = Tag.create!(:name => tag) if tag_object.nil?

   tag_list << tag_object
 end

into this:

tags.each { |tag| tag_list << Tag.first_or_create(:name => tag.strip) }

The actual refactoring I performed isn’t as important to me as the process. I write a lot of junk. I think it’s okay to write a lot of junk as long as you’re getting working ideas out in the wild, messing around, and making them work. Once you get those ideas working, it’s important to go back and clean them up so that you can maintain your ideas, build on them, and grow them into something bigger and better.

Comments

3 Comments so far. Leave a comment below.
  1. I try to follow a pretty similar set of principles. I go by:
    1. Make it work
    2. Make it work right (correctly if you’re picky about grammar)
    3. Make it work better/faster

    I try to mentor junior devs to do the same. That way you don’t over-think the problem.

  2. Dude, 100 junior devs with a 100 PCs in a room will eventually come up with Window 7.

Add Your Comments

Disclaimer
Your email is never published nor shared.
Required
Required
Tips

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <ol> <ul> <li> <strong> <p>

Ready?

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 401 items have been purified.