惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

JonahDevs

Building in Public: The ‘Back to It’ VS Code Extension – Part 1 Time, the Silent Exploit: The Unseen Enemy in Every Codebase The Mindful Coder’s Workweek: 5 Themes to Enhance Your Craft and Satisfaction From Dirty Dishes to Clean Code: How Household Chores Mirror Programming Team Dynamics You’re Closer Than You Think: The Only 6 DNS Concepts You Really Need The Wasabi Method: Shocking Your Way Out of Anxiety Attacks Free Software: The New Nicotine? Big Tech’s Playbook Straight Out of Big Tobacco Your Gut is Smarter Than Your Spreadsheet: The Art of Software Estimation ESLint
The Subtract Day: Why Less Code Can Lead to More Success
Jonah · 2024-06-29 · via JonahDevs

Background

Ever feel like your codebase is a hoarder’s paradise? You’re not alone. I’ve recently picked up a habit that’s been a game-changer for my projects: the subtract day. It’s exactly what it sounds like – one day a week (or fortnight) where I focus not on adding features, but on subtracting parts of the code or requirements that have become stale or could be deprioritized.

Why Subtraction Matters

In his book “Subtract: The Untapped Science of Less”, Leidy Klotz argues that our default approach to problem-solving is addition. We’re hardwired to add more features, more code, more complexity. But often, the best solution is to take something away.

Think about it: when was the last time you deleted a chunk of code and felt that sweet, sweet dopamine hit? It’s like decluttering your digital closet – oddly satisfying and surprisingly productive.

How to Implement a Subtract Day

Here’s how I structure my subtract days:

  1. Code Review: Look for unused functions, commented-out code, or overly complex solutions.
  2. Feature Audit: Identify features that aren’t being used or could be simplified.
  3. Dependency Check: Are all those npm packages really necessary?
  4. Requirement Reassessment: Chat with stakeholders about features that could be deprioritized or removed.

The Benefits of Subtraction

1. Improved Performance

 // Before subtraction
function processData(data) {
  let result = [];
  for (let i = 0; i < data.length; i++) {
    if (data[i] % 2 === 0) {
      result.push(data[i] * 2);
    } else {
      result.push(data[i]);
    }
  }
  return result;
}

// After subtraction
const processData = data => data.map(num => num % 2 === 0 ? num * 2 : num);

// Performance test
const largeDataSet = Array.from({ length: 1000000 }, () => Math.floor(Math.random() * 100));

console.time('Before');
processData(largeDataSet);
console.timeEnd('Before');

console.time('After');
processData(largeDataSet);
console.timeEnd('After');

Less code often means faster execution. In the example above, we’ve simplified our processData function, making it more concise and potentially faster for large datasets.

2. Enhanced Maintainability

Fewer lines of code mean fewer places for bugs to hide. It’s like having a smaller house – less to clean, less to maintain.

3. Clearer Purpose

By removing unnecessary features or code, what remains often has a clearer purpose. It’s easier to understand and explain to new team members.

4. Reduced Cognitive Load

Less code means less mental overhead. You’re not juggling unnecessary complexity, allowing you to focus on what really matters.

Overcoming the Addition Bias

Klotz points out in “Subtract” that we have a strong bias towards addition. It feels productive to add new features or write more code. But sometimes, the most productive thing you can do is take something away.

Here are some strategies to overcome this bias:

  1. Set Subtraction Goals: Aim to remove a certain number of lines of code or features each subtract day.
  2. Celebrate Deletions: Make it a team event. Who can safely remove the most unnecessary code?
  3. Question Every Addition: Before adding something new, ask if you can achieve the same goal by removing or simplifying something existing.

The Bottom Line

The subtract day isn’t just about tidying up your codebase (though that’s a nice benefit). It’s about challenging our instinct to always add more. It’s about recognizing that sometimes, less really is more.

So, next time you’re tempted to add a new feature or write more code, pause and ask yourself: “Could I subtract instead?” Your future self, digging through that codebase six months from now, will thank you.

Remember, as Klotz says in “Subtract”, “When we subtract, we often make room for more of something we want.” In the case of our code, that something might just be clarity, performance, and maintainability.

Now, if you’ll excuse me, I’ve got some code to delete. Happy subtracting!