News for hackers. Stuff that matters.
Re:In Defense of Copy and Paste by pjungwir on Friday February 08, 2013 @02:09PM (#5189536)
One rule I try to follow is to avoid refactoring when the shared code is "coincidental." Perhaps this is another way of expressing what the author says about business logic.

I've definitely worked on projects where developers created large, unwieldy, hard-to-grok, buggy abstractions in the name of DRYing code. I'm pretty aggressive about making code DRY, but simplicity and readability are more important.

The effort I'll tolerate in pursuit of DRY also varies by language. I've been doing some Android work lately, and I'm finding that things I would have done DRY in Ruby require too much added complexity to make DRY in Java.

Re:In Defense of Copy and Paste by Jare on Friday February 08, 2013 @06:26PM (#5190757)
I think that's exactly what the author tries to say. I've also joked expressing it as "you don't refactor your twins."

I'm curious (and I think it can be a useful sub-topic) what you think made Java worse for DRYing. The rigid type system? Added verbosity?

Re:In Defense of Copy and Paste by pjungwir on Friday February 08, 2013 @07:25PM (#5190957)
One easy example: no higher-order functions like `map`, `select`, and `inject` because of no lambdas, so I wind up repeating the same looping code all over the place.

I took a look at a few "functional programming in Java" libraries, but their solutions were still pretty verbose, and it didn't seem worth adding a dependency for a tiny smartphone app.

Re:In Defense of Copy and Paste by pjungwir on Saturday February 09, 2013 @06:38PM (#5194598)
EDIT: After thinking about it some more, there are several places where two methods are almost the same except for one line stuck in the middle. I don't know how to turn them inside-out in Java without spawning a bunch of tiny classes, and it's just not worth it. But with Ruby I could turn them into a single method, throw a yield in the middle, and then call it with a block. So again it comes down to no lambdas.

(Hmm, this was supposed to be an edit, but somehow I did a reply instead.)

Re:In Defense of Copy and Paste by KayEss on Saturday February 09, 2013 @02:50AM (#5192041)
I'd been thinking about these things over the last few years and was calling it "accidental duplication", analogously to the term "accidental complexity".