Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So next, they realize they need a different calculation for shipping, and now their beautiful abstraction has a big if isShipping() {...} else {...} block. So much for reducing complexity.

Sometimes it's best to let two identical blocks of code remain intact if there's a reasonable chance that their logic may diverge in the future. If they don't diverge, and you find yourself constantly updating both, then you can factor it out into shared code. It's usually much easier to create a new layer of abstraction in the future, than to remove an unneeded one after a ton of code has grown up around it.

I'm a big fan of WET - write everything twice (stolen from HackerNews), then maybe the third time think about refactoring into shared code, especially in new apps where you don't know how things are going to involve.



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

Search: