Live data from Hacker News

When To Write Bad Code

brandonsavage.net

11–20 of 25 posts

Re: When To Write Bad Code

#11
This is my approach as well. This basically amounts to planning to throw one away anyway (http://c2.com/cgi/wiki?PlanToThrowOneAway) or rapid prototyping (http://c2.com/cgi/wiki?RapidPrototyping).

After coding the first implementation you will always realize things that you didn't anticipate that could improve the design. It's easier to get it working quickly, find the holes in the algorithm/design, then refactor it to be pretty and maintainable.

Re: When To Write Bad Code

#12
While I agree with the underlying point, the title is an argument in semantics (and I would say misleading and wrong - it is never OK to push bad code).

It may be unelegant, it may lack any number of "best practices", but if your code solves a problem, doesn't break other things, and can be refactored effectively, it doesn't count as bad.

Re: When To Write Bad Code

#13
Write prototypes in a language that you don't use in production.

It allows you to get to grips with the problem and prevents you from just copy-and-pasting large chunks of the "i'll rewrite this later" code into production.

I tend to write my prototypes in Perl as I used to use it a lot in the past for hacking things together. It translates well both to Ruby on Rails (front end) and to C (with low level server magic).

Re: When To Write Bad Code

#14
I used to say that "temporary is the state before permanent". Unfortunately, the crappier the initial code base is, the crappier the production code will be, unless you have a lot of free time to rewrite everything, which about nobody has.

Re: When To Write Bad Code

#15
post #13

Write prototypes in a language that you don't use in production. It allows you to get to grips with the problem and prevents you from just copy-and-pasting large chunks of the "i'll rewrite this later" code into production. I tend to write my prototypes in Perl as I used to use it a lot in the past for hacking things together. It translates well both to Ruby on Rails (front end) and to C (with low level server magic)…

That's an interesting tip. I'm going to try that.

Re: When To Write Bad Code

#16
This is why you test from the outside in: You first write an acceptance test where you just specify what goes in and what should come out. The error/failure messages you get when running this test drive your design and tell you which components you should write next.

The RSpec book is a pretty good introduction to this topic.

Re: When To Write Bad Code

#17

I used to say that "temporary is the state before permanent". Unfortunately, the crappier the initial code base is, the crappier the production code will be, unless you have a lot of free time to rewrite everything, which about nobody has.

Having the time to eliminate your technical debt is just like having the money to make your interest payments. You can go into debt for leverage, just don't get caught in a cycle where it gets deeper.

Re: When To Write Bad Code

#18
post #13

Write prototypes in a language that you don't use in production. It allows you to get to grips with the problem and prevents you from just copy-and-pasting large chunks of the "i'll rewrite this later" code into production. I tend to write my prototypes in Perl as I used to use it a lot in the past for hacking things together. It translates well both to Ruby on Rails (front end) and to C (with low level server magic)…

This is a great suggestion. I've done this with PHP (the first language I learned) for work I'm doing in Python. It also helps sometimes when you have to translate code from one language to another to use an intermediary language.

Re: When To Write Bad Code

#19
post #3

There is a similar dilema in the creative writing field: "I don't know the right way to say this idea" or "I have writer's block." The general advice from the workshops and masters is to write something , even if you know it's terrible, so you have a place to start and revise (what we would call refactoring). The theory is that revising words is much easier and can be helped along by someone else moreso than a blank…

> The theory is that revising words is much easier and can be helped along by someone else moreso than a blank page.

Amen. Nothing beats the instructive facility of running code and a usable UI.

> However, I've only seen it work in practice when you do go back and refactor. Too often the smelly code gets left behind, and that is why I usually ask others to think through code before writing.

Well, of course it won't work if you don't refactor. You get results analogous to writing with no revision. There's also the trick of knowing when you've revised enough -- amateurs stop before the pros.

Post reply on HN