Skip to main content

Command Palette

Search for a command to run...

Code Smell 138 - Packages Dependency

There's an industry trend to avoid writing code as much as possible. But this is not for free

Published
2 min read
Code Smell 138 - Packages Dependency
M

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.

TL;DR: Write your code unless you need an existing complex solution

Problems

Solutions

  1. Import and implement trivial solutions

  2. Rely on external and mature dependencies

Context

Recently, There's a trend to rely on a hard to trace dependencies.

This introduces coupling into our designs and architectural solutions.

Sample Code

Wrong

$ npm install --save is-odd

// https://www.npmjs.com/package/is-odd
// This package has about 500k weekly downloads
// https://github.com/i-voted-for-trump/is-odd/blob/master/index.js

module.exports = function isOdd(value) {
  const n = Math.abs(value); 
  return (n % 2) === 1;
};

Right

function isOdd(value) {
  const n = Math.abs(value); 
  return (n % 2) === 1;
};

// Just solve it inline

Detection

[X] Automatic

We can check our external dependencies and stick to the minimum.

We can also depend on a certain concrete version to avoid hijacking.

Tags

  • Security

Conclusion

Lazy programmers push reuse to absurd limits.

We need a good balance between code duplication and crazy reuse.

As always, there are rules of thumb but no rigid rules.

Relations

More Info

Credits

Photo by olieman.eth on Unsplash

Thanks to Ramiro Rela for this smell


Complexity kills. It sucks the life out of developers, it makes products difficult to plan, build and test, it introduces security challenges, and it causes end-user and administrator frustration.

Ray Ozzie


This article is part of the CodeSmell Series.

K

HA! When I first read the title I was all but certain I would disagree with you and I am surprised I am in agreement. In University I was told to stand on the shoulders of giants and taught never to reinvent the wheel.

But I cannot imagine ever installing packages for such trivial code. In fact, even a copy/paste would be the true lazy developer method.

What amazes me about this, is that commercial companies didn't even take the time to fork the repositories of their dependencies?

I have been forking repositories I just know I will never have the time to write myself but absolutely need/want to investigate later, and these are for side projects just for paranoia's sake!

All in all a wonderful article, I plan to enjoy your code smell series further!

D

Thanks for article, informative as always 👍

Code Smells

Part 1 of 50

In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.