Linked blocks of code

I have code blocks that are the same across multiple files. I would like to keep them in sync/link them together: changing one block leads to changes in blocks across files automatically. I wonder whether there is an add-on that would allow me to do so, or how you would go about that.

(The obvious solution would be to wrap the shared code into a function. However, that does not suit my needs here.)

The difficult thing here is telling the editor that the text in specific sections of multiple files should be the same. It’s a very hard computer science problem to track events happening in text files that aren’t identical to start with, and most languages have inclusion mechanics that are designed to minimize duplicate code, so it’s not a problem that’s usually worth solving. I haven’t seen a package that does what you want, and for the reasons I’ve mentioned I doubt that it exists.