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) }