Skip to main content
2 of 2
fixed conditional logic
Mathieu Guindon
  • 75.6k
  • 4
  • 99
  • 243

The spirit of Code Review is to get actual code from actual projects you're working on, peer reviewed by a community.

If the entire code in your question is this little snippet:

if(a) {
    if(b) {
        //some statement(s)
    }
} else if(c) {
    //some statement(s) (the same ones as in the other block)
}

Then the question isn't about reviewing your code, it's about ways to write the code for a hypothetical conditional statement, where a hypothetical code block would be duplicated in two branches.

IMHO, the "answer" is something like: if(a && b || !a && c) { /* some statement(s) */ }.

This isn't a code review question, I think it would be more on-topic on Programmers.StackExchange.

On the other hand, if you supplied your actual code, with the actual repeated code blocks, and asked "how bad is duplicating a code block?", answerers could actually review your code, and address the duplication concern.

Just providing a "sample code" snippet to illustrate a hypothetical situation, is off-topic IMHO, because it goes against the spirit, it's too high-level and more on Programmers.StackExchange's grounds.

Mathieu Guindon
  • 75.6k
  • 4
  • 99
  • 243