Hacker News new | past | comments | ask | show | jobs | submit login
“You’ll never convince me that reusable code isn’t mostly a menace”-Knuth, 2008 (informit.com)
6 points by ohjeez on Dec 29, 2018 | hide | past | favorite | 2 comments



I really agree with the quote, especially after spending some time in a huge enterprise codebase (1mil+ files). Writing reusable code usually means writing an abstraction layer. However, if you always write an abstraction layer, you will end up with a ton of abstract code with only one concrete implementation. Abstract code is harder to read and modify, so you do pay a cost when it comes to maintenance. Also depending on the language you may pay a runtime cost also. So if your goal is always to write reusable code from the start, you pay an investment cost that may never show any returns.

This idea pairs well with another Knuth quote regarding premature optimization being being evil [1]. Code reusability is a form of optimization of developer time. Writing reusable code with only one implementation is like optimizing a function that does not impact performance. You think you are doing something good because programmer dogma says its good, but in the end its not.

Here is another related article that does a great job talking about maintainable software, and some of the contradictory advice you will hear about it [2]. But the main point is that code is transient. We tend to write code with the idea that it may run in production undisturbed for decades, but that is not the case. Refactors are common, and most people will do a better job rewriting code from scratch than trying to modify your code. So do them a favor, and make it easily replaceable instead of easily modifiable, mostly because your opinion of what is easy to modify is just as subjective as your opinion of what is good code.

[1] http://wiki.c2.com/?PrematureOptimization [2] https://programmingisterrible.com/post/139222674273/write-co...


I always thought the idiom of 'reusable code' is in deep conflict with 'ruthless refactoring'

I've come down to keep your interfaces and paradigms stable, architecture flat and couplings low.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: