Step 7: Beware the Share ~Udi Dahan

Birat Rai
2 min readSep 28, 2017

--

This is the Seventh Step towards gaining the Programming Enlightenment series. If you didn’t learn the sixth step, read it.

“Beware the Copy Paste Programming.”

One thing we all developers are adept is we try to google our solutions through. We all have a graduate degree from the University of Stackoverflow, and have become the Full StackOverflow Developer.

We can unanimously agree copy-paste (ctrl-c ctrl-v) is the greatest invention in the computer world. It has solved immense degree of problems by Code Reuse 😂 😂

What is Code Reuse?

Code Reuse is the use of existing software, or software knowledge, to build new software. As we start reusing components of code, code duplication starts.

What is Code Duplication?

It is a sequence of source code that occurs more than once. As a developer, when we see a duplicated code, we tend to reuse them by consolidating them at a central place.

Why do Code Reuse?

  • DRY “Don’t Repeat Yourself”.
  • It improves the maintenance and bug can be tackled at a single place.
  • It reduces the number of lines of code.
  • Better testing of a single unit.
  • Code will be modular.

Things to Consider before Code Reusing?

  • Apply the Rule of Three before removing Code duplication.
  • Even if the code may seem duplicated, they could co-exist differently in other part of system and well maybe evolve independently.
  • Check whether duplicated code won’t change ever in one context, before removing it.
  • Only remove duplicated code, if you consider it Code Smell.

TL;DR Ponder if Code Reusal is useful because of Code Duplication. It may not be always fruitful to remove code duplication.

Go to the series.

Go to sixth step.

Go to the Eighth path.

References:

--

--

Birat Rai
Birat Rai

No responses yet