# Duplicated answers for duplicate patterns/subroutines

More duplicates of this pattern from the same user:

If a question duplicates the code...

class BinaryTrees<T> {

private TreesNode<T> root;

public BinaryTrees(List<T> items) {
create(items);
}

private void create (List<T> items) {
root = new TreesNode<T>(items.get(0));
(...)


and

class BinaryTree<T> {

private Node<T> root;

public BinaryTree(Node<T> root) {
this.root = root;
}

public BinaryTree(List<T> items) {
create(items);
}

private void create (List<? extends T> items) {
root = new Node<T>(items.get(0));
(...)


Bug: IndexOutOfBoundsException on empty list in BinaryTree(s).create(List<(? extends )T> items). You don't have a comment stating you need to input a list containing at least something. Consider returning IllegalArgumentException and adding a comment.

(Note: I have referred to the proper names and function signatures in both answers. My answer is not generic.)

Am I allowed to post a duplicate answer? I can come up with a couple of arguments for yes and for no...

• Yes, because each question stands on its own.

• Yes, because I might not have noticed the duplicate.

• What if I did? How are you going to verify this?

• If I add one point that is not duplicated, should I remove my duplicated points? If anyone brings up these (valid) points, should their answer get deleted as a duplicate? How are they supposed to know?
• No, because if you duplicate your answer then editing it requires us to change it in both posts.

Which of these reasons is valid, and why?

If this is allowed, I intend to post my answer on each and every of these questions if the points haven't been made yet.

Update: I have posted answers on the questions where answerers didn't mention this issue yet.

• I have notified JavaDeveloper that his questions are being discussed. – rolfl Sep 17 '14 at 10:34
• Note that your answers are triggering auto-flags in the system: Duplicate Answer(auto) – rolfl Sep 17 '14 at 11:24
• @rolfl I have faith that you'll handle them properly. I'm almost done. – Pimgd Sep 17 '14 at 11:26
• @rolfl I'm also trying to add things other than this when I spot them, so sometimes it's not a total duplicate. – Pimgd Sep 17 '14 at 11:34
• @Pimgd nvm. Wrong place. – bhathiya-perera Sep 23 '14 at 1:03

Yes, and No

Let's be clear here, the code works for the purpose given. The code presented will never be called in a way that exposes that bug, so is it a bug? Not for the asker. That code is not intended for review but is intended to provide background for the actual algorithm/process he wants to accomplish.

The bug is only a bug if you extend the usage of the code beyond its intended requirements, which would be a valid concern in a review,

Is this worth pointing out in a review...? Yes. Is basing a review entirely on part of the code that is 'support' code meaningful? Sure, there's nothing stopping that. You are free to review any, and all aspects of the code.

Are you free to post the same, or substantially the same answer to multiple posts? Yes

You also have other options:

1. just ignore the questions
2. answer that, in combination with other reviews aspects

They serve a purpose, but a weak one. They provide little, or no benefit to JavaDeveloper because he will not see that particular code as central to the question he asks.

The answers will not really satisfy you, personally... it will be boring, and unfulfilling.

On a personal note, I tend to ignore JavaDeveloper questions. I have answered many of them in the past too, and find myself repeating myself again, and again. I find myself repeating myself again, and again. I don't like reading through the same 'boilerplate' code each time just to see the subtle differences one question has compared to another. It does not satisfy me, so I just don't do it. I scan his questions to see if there's something of 'unusual' interest, or to see whether he's learned something significant from previous times. If it looks like something I have seen before, I tend to 'move on'.

I cannot find anything technically wrong, or off-topic, about his questions from a Code Review site perspective, so the questions are not duplicates, or off topic, but at the same time, they have just lost interest for me (mostly).

If you have the energy to go though and provide the same reviews to multiple different questions, then you can do it, but be aware that the value added is probably low, and since you will not, for the most part, be addressing anything central to the asker's main concerns, you will likely not gather much in the way of upvotes or accepts.

• "I have answered many of them in the past too, and find myself repeating myself again, and again. I find myself repeating myself again, and again." Was that intentional? – Pimgd Sep 17 '14 at 11:02
• Additionally: My core point is not "It's a bug!", but rather this: "Supplying empty list gives IndexOutOfBoundsException. You should throw IllegalArgumentException instead". – Pimgd Sep 17 '14 at 11:04
• Of course it was intentional, it was intentional. Your answer starts with: "A minor bug: ..." and my point is that it will never get an empty list. – rolfl Sep 17 '14 at 11:19

For me an answer is related to a question.
Do we have to redirect them to answers of the other questions for that?

That said, I think I would vote to close the second one as duplicate or broken code if the first answer already has the duplicate answer before the posting of the second question.

Why?

• Asked by the same person.
• A lot of duplicated code.(no follow up cause it's a different issue)
• Created same fault as in first topic.
• With the copying of the fault I'm asking myself, do he learn from the answers on previous questions?

In my opinion :

We really want to help users and help them improve themselves.
This is possible if users listen to us.
A user can't improve if they don't take valuable information to new questions/code.

So if most of the code in a second question is copy paste from earlier question => it's duplicated code so duplicated faults and you get duplicated answers.

• The duplicate answers were posted 5 minutes apart. The "duplicate" questions were posted 10 days apart. The answers were posted after both questions had been posted. He hasn't had the time to learn yet. – Pimgd Sep 17 '14 at 9:08
• I agree with the first point: Making canonical answers is a bit silly. However... it turns out there are 25 questions where my answer is valid. Do I get to post on all of them? – Pimgd Sep 17 '14 at 9:33

This started off with a two-way duplicate; That is, two questions contained the same code-pattern.

In that light, I would have said "each question is separate". If a question happens to contain the same code(pattern) as another, it's perfectly valid to post answers on both questions listing the same points. Just make sure your answer is valid (if they say "It only accepts non-empty lists" then the point "it fails on empty list" is not a valid point. "Add a comment that it doesn't accept empty lists" is.).

However... I have found 25 questions with the same code(pattern). 25.

Is it valid to post it on 25 questions?

Legally: Yes. Each question is separate.

The real question is "Do you think that will help anyone?". ... And I'd say yes to that too. It won't help the asker, but it will help anyone who stumbles on the question.

• indeed, when I come up one of those 25 questions, I'm not going to look for same code pattern to search for a valid answer so still valid, how stupid it can sound – chillworld Sep 17 '14 at 9:54