4 ms·
I’ve never really understood this, because undoing DRY is relatively easy: you either copy the new function/class and rename it or you inline it in the mistaken
by fiddlerwoaroof 7y ago
I’ve never really understood this, because undoing DRY is relatively easy: you either copy the new function/class and rename it or you inline it in the mistaken case and adjust the code to match.
- smichel17 7y agoEasy, but it's still work. As a thought experiment: if it's so easy, would you be interested in doing it for me? (edit: Obviously not, but compare your internal resistance to if I'd asked you to do something trivial like fix a typo in the readme) Here's the file I was referencing (only 100 lines!): https://github.com/LibreShift/red-moon/blob/master/app/src/main/java/com/jmstudios/redmoon/filter/Command.kt https://github.com/LibreShift/red-moon/blob/master/app/src/m... Here's the issue I've been putting off fixing because of it: https://github.com/LibreShift/red-moon/issues/208 https://github.com/LibreShift/red-moon/issues/208 The problem is that right now there is one PAUSE state, which is triggered by both manual pauses (brightness should be restored) and automatic pauses (in secure apps; brightness should not be restored). The problem wasn't exactly DRY, it's the misapplication: I merged bits that had identical code, but turned out not to have identical purpose. And, for posterity, here's what it used to look like way back (DRYing was not the only change, I also split out notification stuff, so it's not a 1:1 length comparison): https://github.com/LibreShift/red-moon/blob/11ae916955ff8c360eb568c3b5632673b50b58d0/app/src/main/java/com/jmstudios/redmoon/presenter/ScreenFilterPresenter.kt https://github.com/LibreShift/red-moon/blob/11ae916955ff8c36... edit: and here's the original file, back mostly before I touched it at all: https://github.com/LibreShift/red-moon/blob/ed2ec4fd1c68611d851a55f3ade141e6738e394c/app/src/main/java/com/jmstudios/redmoon/presenter/ScreenFilterPresenter.java https://github.com/LibreShift/red-moon/blob/ed2ec4fd1c68611d...
- simonh 7y agoI'm not sure what you don't understand - that doing things unnecessarily and then having to undo them is a waste of time? Nobody here is saying DRY is bad, just that it's not universally the right thing to do without consideration.
- greenhatman 7y agoIt can become much more convoluted than just having a function used in many places. It usually takes the form of multiple levels of inheritance. And it's a pain to deal with, and somewhat of a pain to refactor as well.