This problem is widespread in almost every discipline which uses any form of computation.
I think the best way is for major funding sources like the NIH, NSF etc to build in to the grant terms which coding language, existing libraries be used.
Or how/what/ software will be developed should be used an additional metric for deciding which proposals to accept.
Proposals which are strong otherwise but do not state in clear terms how software will be built should be asked to modify their proposals to include such information.
Pre-existing, well-designed, modular software architectures should be extended rather than building architectures from scratch. This is a waste of funds and time.
Funding organizations must also recognize that developing good software takes time and money and set aside budgets in the grant for hiring dedicated programmers. (Scientists are very often not good software engineers and they are interested rather in trying things out quickly to see if it works at all)
Such programmers can then take hacky research code from the scientists and turn it around into great reusable code.