People usually have a shock when they start their PhD and find they have to learn to program, fast.
So do a whole host of other people.
Dijkstra would have had a fit.
It was interesting software (finite element analysis) but until it was just about completely rewritten absolutely un-maintainable. Which was a bit of a problem because it was also buggy.
In my experience, the problem rather is that in science, the intention of the code is to be able to run well enough such that one or two papers can be made out of it and after that, it may be forgotten.
For this purpose, this kind of coding is actually decent and (unluckily) investing time in good software engineering practises would mean that you have less time for writing papers.
In this sense, I would be cautious to call this kind of code "bad", but rather say that if you write code for a company, the priorities are very different.
In the end it all worked out and it was a very good lesson in trying to keep the output stable while refactoring the code. This was well before 'TDD'.