Knowing when the code is good enough, for research My question is in a similar vein to this one.

My research requires code. I can write code and I know some things about writing good code. Both for readability, (e.g. standardised doc string, descriptive variable names, comments that describe the intention) and safety (assertions in the code, unit tests, sensible error messages). Adding these things takes me more time than omitting them.

At present I will typically do a bare minimum on my first attempt. So I will put a one line doc string in; use descriptive, but occasionally inconstant, variable names; and few comments. If the code doesn’t work first time I will go back and add unit tests and generally improve it's quality until it is functional.

If at a later stage part of the code needs altering significantly, (perhaps I realise I need it in parallel), then lots of the "polish" will need redoing. This does not make it enticing to polish more earlier on. Occasionally I will chase my tail over a fault that turns out to be originating in an older section of code, that I might have caught if I have been more thorough first time.

The code I write is almost always only used by myself.

Clearly there is a trade-off between doing things by the book and producing results fast. What would you look at to decide if you had found a good balance between these things?
As the


  code I write is almost always only used by myself


you only have yourself to please. So the only sensible answer is to balance things to minimize the frustration to yourself. Don't do things you see as frustratingly slowing you down until you are more frustrated by the problems caused by not doing them.

However, the more strategic question is whether you want to continue writing code that will only be used and seen by yourself. If you want to advance your career through collaboration with peers, or by building a group of researchers to work on and with your codes, then it will be better to do more earlier.

You then know you've found a good balance when the collaborators you want to work with still want to work with you after they've spent some time with your code.