I think general programming best practices would apply, particularly code review and planning your code and breaking it up into discrete parts. I have seen many scripts for research that are 5k LOC of spaghetti that become impossible to read or adjust.