Live data from Hacker News

When To Write Bad Code

brandonsavage.net

21–25 of 25 posts

Re: When To Write Bad Code

#21
I don't think this post goes far enough. It's not only ok to write bad code, it's also ok to commit bad code, and to use such programs in anger. Most code is not actually going to be important. It's ok for that code to be crap. What's generally not ok is contaminating already existing high-quality components with quick kludges. Likewise it's not ok for programs that turn out to be important to remain in a crappy state, even if they started out as such.

I write dozens of shell pipelines every day. Some graduate to actually being saved in files and cleaned up a bit. Some of those start needing new features, and end up rewritten as quick and dirty perl scripts. A few of those see constant use in more and more circumstances and end up accumulating an ever larger number of features. Once that program grows large enough, it'll become obvious that it'll become unmaintainable at some point. And you can either evolve that code into a less crappy state when other changes are made, or you can rewrite it from scratch.

And the thing is, you can't really know in advance what kind of a program a given problem really warrants. Is it shell pipeline that'll only ever be run three times, or will it end up as a core component of somebody's workflow. Since you can't predict these things, you have to play the odds. If most programs end up as important tools, it'd be insane to risk the need of multiple rewrites. While if most programs end up just gathering dust somewhere, it'd be insane to polish them to perfection before committing. And even if "nothing lives longer than temporary code" is a nice soundbite, I don't actually believe that for a moment. I'd bet that most temporary code actually dies almost instantly. It's just some kind of observation bias.

Re: When To Write Bad Code

#22
I think this varies per person's development style. If the thing that's blocking is getting momentum, then sometimes writing tests and then code to meet those test is easier (for those of us who are more comfortable with documenting).

In the end it depends whether it's easier to just code or setup scaffolding (ie, TDD tests) to then write the code.

Re: When To Write Bad Code

#23
post #8

"Nothing lives longer than temporary code." Love this quote. I assumed it was an existing quote/idiom, but it looks to be original.

It's not original to me. Not sure where I heard it, but I know it's not mine.

Thus spake the master programmer: "Though a program be but three lines long, someday it will have to be maintained." -- Geoffrey James, "The Tao of Programming"

Re: When To Write Bad Code

#24
post #5

> When the code is working and you’re ready to move onto the next phase, then you can work on making the code pretty, readable, well-documented and tested. While this flies in the face of concepts like test-driven development... I disagree that writing "shit code that still works" and TDD have to be mutually exclusive. In fact, if I'm going to go the "just get it done" route, I will almost (but not always) try to set…

The person I was mentoring (that prompted this blog post) was having trouble getting ANY code down on the screen. Being able to write SOMETHING was the hurdle for this developer to overcome. In most cases though, I agree with you.

I write bad code all the time, I'm writing terrible code right now. I check in good code.

Some people can visualize an entire program in their head and how it will interact. Not me. I hack at the core of the problem I'm trying to solve, until I've solved it. Then I reorganize the code into something that (hopefully) isn't crap. It seems inefficient, but it works for me.

Post reply on HN