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
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.
So, what you’re saying is that you use an army of junior devs to refactor your crappy code into good code under the guise of teaching them something? That’s clever.
Dude, 100 junior devs with a 100 PCs in a room will eventually come up with Window 7.