There will be junk

February 18th, 2008. Tagged: misc hackery, writing

Tip #1 for writing better code - edit. With this book I write, I find I'm spending more time editing than writing. The first draft is usually bad. The first draft "works" in the sense that it covers the material, but not necessarily in the best possible way.

Same thing with writing code, it's one thing to have the code working and it's a separate thing to have the code easy to understand, efficient, maintainable, expandable. When you're working on a problem, sometimes you just try different things. One of them works. It's your job not to stop there but to edit this first draft. Don't commit first drafts.

There will be junk. It's up to you to make sure that junk doesn't find its way to the final product, only because "it works". It may work now, but how about tomorrow. Is your code fit for print?

Tell your friends about this post: Facebook, Twitter, Google+

4 Responses

  1. In the Mythical Man Month, Fred Brooks mentions a rule very early on… Plan to throw one away. He says that no matter what you’re working on, your first version is not fit for production. Its purpose is as a learning tool. Look at it as a prototype, look at it as a sample implementation, but throw it away and write something from scratch for production.

  2. Thanks for this comment, Philip. Proves that great man think alike, hehe :D

    Don’t you think it’s a little too harsh though to completely throw away your first draft? Well, I guess it depends on the project. If it has something to do with space satellites or medical equipment and people could die because of your code, then yes.

    I guess pretty much the same goes for every creative process. Code, poetry (“code is poetry” some say), music, painting. The kids like all the “messes and masterpieces” they create, they are fascinated by their works of art and the process of creating them. Because of that, they won’t throw anything. But we should know better.

  3. I should let you read my copy of the book once I have it with me. Nicole is first in line though.

  4. Gruesse zur Weihnachtszeit und die besten Wuensche zum neuen Jahr. Greetings fort he Christmas season and best wishes fort he New Year.

Leave a Reply