Ask HN: Do you try to code "proper" even on the first pass?

7 points by keeptrying ↗ HN
Ask HN: On the first pass of coding something, do you hack it till you get something working or structure it well?

10 comments

[ 3.0 ms ] story [ 32.0 ms ] thread
I write code as cleanly on the first pass as I do on the last (if there ever is a last). The reason being that if I hacked it and then showed the client/my boss that it's working, it would be hard to justify the additional time to clean it up when they want it pushed to production now.
Good point. But I meant working as in "your eyes only"
Gotcha...on my own projects I write very clean code, because there is never a shortage of time.
Is that optimal when feedback is more IMp like early stage startup?
I blast put the most bogus half-witted garbage that could possibly half work, train of thought style. It just embarrassingly bad. I go back and clean it up almost immediately while it's still fresh in the mind.

The upside is that I usually find I need only 1/3 of what I thought I needed. It doesn't feel quite so bad to throw out huge chunks of stuff I know is so bad I wouldn't want anyone to see it anyway. The worst thing in a project is something I think is really clever but just not needed. I become irrationally attached.

(comment deleted)
My code starts and stays embarrassingly bad until I need to refactor it. Eventually, the code improves. Very often, though, it gets thrown out entirely. Only profitable code deserves to be good.

Caveat: The above applies to my own business projets where I am the sole coder. I write better code for clients - it still starts out rough, but I refactor more frequently.

'Properly'.

But yes, otherwise I find I don't have time to fix it later. Occasionally, when I know there's a better way of doing it but am having trouble thinking of it immediately I throw a # TODO in there.

I always try to code cleanly. If there is learning going on, I may not feel it is clean at the end, but it wasn't from lack of trying.
You should not have a second pass it's a huge time waster. I like taking the extra time to optimize everything from the start. Maybe I won't finish my project within an hour, bu extra time helps as more ideas come to mind while coding