It's bizarre to me how byzantine the scientific community's grasp of programming is. Variables are named things like "namxaqqs" and "stoggs1_r3". 4,000 line monster functions are rampant. If scientific code were a garden, stuff like this would be the weeds:

Ax_1 += Bx_1 + Cx_1 # Add Bx_1 to Cx_1
Ax_2 += Bx_2 + Cx_2 # Same thing, but for Ax_2
Ax_3 += Bx_3 + Cx_3 # "
Ay_1 += By_1 + Cy_1 # "
...

Code with comparable functionality is copied and pasted instead of being factored into a single function. Everything is tightly-coupled: changing one line of code is like pulling the keystone out of a bridge designed by an oyster chef. If there are any functions, then calling one mutates at least 7 global variables and induces 13 side effects that are more unpredictable than eigenstate selection. File formats are non-standard and consist largely of one giant concatenation of every variable in the program (all converted to strings of course).

Not-invented-here-syndrome is a badge of honor (LAPACK? Bah! I'll write my own Gaussian elimination routine for this matrix with a million entries). Libraries are embraced with the exuberance of a picky eater encountering durian (as a rule of thumb, anything that is open source and has been vetted by thousands of users is probably untrustworthy).

It is considered a waste of time to learn basic CS algorithms — efficiency is merely an implementation detail, so problems that could have been solved with a clever algorithm and an iPhone are instead brute-forced using millions of hours of supercomputer time. Complexity classes are the abstract nonsense of computer science — it's much easier to throw more hours at the problem (so what if it's NP-hard? My algorithm probably converges to the global minimum. Why wouldn't it?)

When garbage-collected languages are used, programs spend 99% of their time allocating and deallocating small quantities of memory in tightly nested inner loops (16 of them, no less). "Inlining" means putting comments inside of the code instead of above it (if there even are any comments). "Cache locality" has something to do with GPS systems. "Hashing", "recursion", and "quicksort" are the names of recently-announced smartphones. And doesn't "SIMD" stand for the Society for Inherited Metabolic Disorders?

/rant

It's a mess. Granted, there are researchers who write very high quality code, but they are few and far between. I think the main problem is that a lot of students/professors who get involved in computational research never had a good CS background. Perhaps they had one "Computing for Engineers" class that taught Matlab or Python, but that isn't nearly sufficient for research-quality code. While I had the advantage of taking up programming as a hobby during childhood, most graduate students have never programmed before in their life. They're expected to learn something like C++ in a week (that's not a hypothetical example).

Many researchers are afraid to publish their code alongside their paper because they know the code is low-quality. And that awareness causes a lot of insecurities. If someone finds a bug in their 2-3 year research project, then their entire conclusion might be invalidated. But I don't think that's the biggest worry (most scientists ultimately want to know the truth about their subject of study). I think the biggest fear is of losing prestige, losing a chance for tenure, or having funding revoked.

To fix this problem, there is a crucial and urgent need for the academic community to reduce the penalty associated with making honest mistakes.

Mistakes are simply part of the research process. Humans are fallible — everyone is going to mess up at some point. And instead of propagating this academic "chilling effect", it would be much better for the whole scientific community if everyone quit worrying about messing up and instead published their code in a highly visible location, subjecting it to the highly critical (yet extremely beneficial) scrutiny that it deserves.