DEV Community

Cover image for Code Smell 16 - Ripple Effect
Maxi Contieri
Maxi Contieri

Posted on • Edited on • Originally published at maximilianocontieri.com

Code Smell 16 - Ripple Effect

Small changes yield unexpected problems.

TL;DR: If small changes have big impact, you need to decouple your system.

Problems

  • Coupling

Solutions

  1. Decouple.
  2. Cover with tests.
  3. Refactor and isolate what is changing.
  4. Depend on interfaces.

Examples

  • Legacy Systems

Sample Code

Wrong

class Time {
   constructor(hour, minute, seconds) {
     this.hour = hour;    
     this.minute = minute;  
     this.seconds = seconds;  
  }
    now(){
      //call operating system
    }  
}

//Adding a TimeZone will have a big Ripple Effect
//Changing now() to consider timezine will also bring the effect
Enter fullscreen mode Exit fullscreen mode

Right

class Time {
   constructor(hour, minute, seconds, timezone) {
     this.hour = hour;    
     this.minute = minute;  
     this.seconds = seconds;  
     this.timezone = timezone;  
  }  
  //Removed now() since is invalid without context
}

class RelativeClock {
   constructor(timezone){
     this.timezone = timezone;
   }
   now(timezone){
     var localSystemTime = this.localSystemTime();
     var localSystemTimezone = this.localSystemTimezone();
     //Do some math translating timezones
     //
     return new Time(..., timezone);     
   }  
}
Enter fullscreen mode Exit fullscreen mode

Detection

Tags

  • Legacy

Conclusion

There are multiple strategies to deal with Legacy and coupled systems. We should deal with this problem before it explodes under our eyes.

Relations

More info

Credits

Photo by Jack Tindall on Unsplash


Architecture is the tension between coupling and cohesion.

Neal Ford


This article is part of the CodeSmell Series.

Last update: 2021/06/24

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay