Header Image

Removing Structural Duplication and Refactoring Hidden Loops


Removing Structural Duplication


Structural duplication is a type of code similarity that is difficult to identify. A common example is the similarity in exception handling:



} catch (Exception1 exc1){

     // treat exception1

} catch (Exception2 exc2){

    // treat exception2




} catch(Exception1 exc1){

    // treat exception1

} catch(Exception3 exc3){

    // treat exception3


The structural duplication is obvious – the code has the same structure but calls different things. Refactoring it can prove challenging.

In this session, I will show you how to remove structural duplication from your code and some of the benefits that can result from it.


Refactoring Hidden Loops

This session introduces you to the hidden loops smell and shows an example of refactoring it away.

The hidden loops smell manifests as an operation that is duplicated in various forms in code. The typical example I encounter is a series of if statements:

if(…) doSomething()

if(…) doSomethingElse()

You will learn how to identify hidden loops and how to refactor them to a much shorter version that generalizes the solution and allows flexibility.



May 15 @ 13:40
13:40 — 14:15 (35′)

Alexandru Bolboaca

Leave a Reply