Live data from Hacker News

Throw away your first draft of your code

ntietz.com

111–120 of 230 posts

Re: Throw away your first draft of your code

#111
I don’t really see the need to commit to throwing my first iteration out. I do refactor pretty aggressively at the outset of a major project or code change though. It often takes me quite a bit of time before things really get off the ground because of this. The result is probably the same—that I’m paying a lot of attention to making sure I’m going down a good path.

Re: Throw away your first draft of your code

#113
post #108

Earlier quoted context omitted.

I don't really feel that attraction to complete rewriting. I wonder if the people who do are very smart, and thus able to hold more state in their head, so ugly code bothers them more even if it's not actively a problem, because they are able to have background tasks in their mind to worry about it? And at the same time, perhaps their code is less encapsulated, because they didn't optimize for abstraction, they optim…

Smart people can ignore ugly code. It's the people who get easily confused that need to see clean and easy to understand code.

Sadly, I think this is true of me — at least of me. I don't think smart people (by this definition) are that common though, so clean code is a sensible default.

Re: Throw away your first draft of your code

#114

Earlier quoted context omitted.

Yeah, this thread is a somewhat strange read. People don't seem to understand what "draft" or "prototype" means. Odd.

Just like management. I can't tell you how many times I've written a "Proof of Concept" that became production code.

I did that today. Rewrote a bash script in to a perl script as Proof of Concept. it's now in UAT... but I like perl, hey ho.

Re: Throw away your first draft of your code

#115
post #10

The temptation to throw away all of your code - be it a prototype or a "grown" code base - arises often. Often it is a bad idea. I get it, though, there is an inherent attractiveness in the idea of starting fresh from a clean slate. Except, more likely than not, you'll soon find yourself in a similar situation to the one you started from. The fundamental problem is that it is easy to underestimate the edge cases. Sur…

> The temptation to throw away all of your code - be it a prototype or a "grown" code base - arises often. I want an editor plugin which allows me to mark sections of code as reviewed or "perfect" (depending on how honest I'm being). Then, when I'm tempted to rewrite everything, I can go through and mark what I think is good, and then focus on refactoring the rest until I think it is good as well. I'm tempted to rewr…

I would think a combination of git, unit tests, and comments would solve this problem?

Unit tests prove the code works as intended, and are basically examples of what the code is doing. Whether the code is actually "good" is a bit more subjective -- but tests give you the freedom to modify it without breaking it.

Checking into git frequently is also a way to give yourself some freedom. Commit at every milestone, like every time the next thing is "working". If you feel like refactoring, go for it -- you can reset back to working state in a few seconds.

And lastly, leave comments in. You can always clean it up before you push. You can even squash or interactively rebase your history so no one else sees the gory details how the hot dog was actually made.

Re: Throw away your first draft of your code

#116
After seeing multiple "first drafts" going into production over years, I've internalised that they shouldn't be even presented as ready to be shipped until and unless a draft passes multiple refractors. If something is unknown, it is better to explore possibilities and prototype in a prior sprint before picking the actual implementation. Take your time to figure out unknowns before writing the code you intend to ship.

Re: Throw away your first draft of your code

#117

After seeing multiple "first drafts" going into production over years, I've internalised that they shouldn't be even presented as ready to be shipped until and unless a draft passes multiple refractors. If something is unknown, it is better to explore possibilities and prototype in a prior sprint before picking the actual implementation. Take your time to figure out unknowns before writing the code you intend to ship…

Management doesn't care about your perfect code. You won't get rewarded either.

Re: Throw away your first draft of your code

#118
post #37

I rewrote a mission critical application. The original app was something else. One function had 1500+ lines of code. It was the ugliest thing I have seen in my life. We wrote cleaner code in early college years. However, that code ran the business for 12 years with almost 0 modifications. People created work around for some stuff. Error handling was poor. But the goal was achieved and business continued to grow. I th…

Code quality isnt that important if you check this code "once a year" and dont have time pressure to change somewhere in there. Or if you are seeing this code daily and know all the quirks.
Post reply on HN