Avoiding Wet Code

Kelly Scheffler
Jul 30, 2017 · 1 min read

Wet code, which stands for write every time, is code that has duplicate elements. Code that is not wet is called dry code, which stands for don’t repeat yourself. If your code is wet, what could be a simple update can become a headache requiring you to make multiple updates over many files instead of one update in one location.

To avoid wet code when creating classes, you can have one class inherit the methods of another class when the inheriting class has all the same functionality as the inherited class. To do this, you can use Class2 < Class1 where Class2 is the one inheriting the methods.

You are also able to add data to the initialize method of the inheriting class. To prevent the second initialize from overwriting the first, super should be added under the def line of the second one.

In instances where two classes share one method but not the others, you can create a module that would then be referenced by each class. The module allows the method to exist outside of the classes and can therefore be written once.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade