Hacker News new | ask | show | jobs
by iMerNibor 3937 days ago
The huge advantage of making reusable code, even if you never reuse it, is that it's clean and decoupled from the other parts of your application. Thus it'll be easier to understand and to deal with - you won't have to look over what dependencies might cause unwanted effects here or there or what might be able to go wrong in case X. With decoupled code you only need to make sure it does it's "one" (main) function properly.

It also prevents code from turning into spaghetti when adding "special" cases

1 comments

Do you write test cases? If not I'd recommend it. The decoupling required for effective tests leads you into modularizing things you may not have otherwise. I have seen myself that after this started code re-use in general has jumped due to the modules already sitting around where previously I may have just written somewhat similar functionality from scratch all over again in a new project.