There will be junk

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?

Bookmark and Share

Somewhat related posts

3 Responses to “There will be junk”

  1. Philip Tellis Says:

    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. Stoyan Says:

    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. Philip Tellis Says:

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

Leave a Reply