I spent some 16 years in academia, so I understand your context... It's very easy to fall in the "quick hack" trap, and end up with a terrible mess.

On the other hand, much of the code you do while doing research is truly throw-away stuff. What I found helped me (especially when coming back to my code later on), was to use literate programming (in org-mode) to record my thought process along with the (often polyglot) code.