Skip to main content

deslop-code

clean up code layering and unnecessary abstractions in drive-by fixes

来源信息

仓库
devdotfast/skills
最近来源活动
2026年10月4日 06:14
检测到的 SKILL.md 语言
英语
星标
3
分支
0

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

文件资源管理器
2 个文件

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
deslop-code
description
clean up code layering and unnecessary abstractions in drive-by fixes
disable-model-invocation
true
There are a few great levers when cleaning up code: 1. Cleaning up dead code. Analyze every line of the commit. Your reviewer will nitpick. Ask yourself: did this HAVE to change? If not, revert it. 2. Creating a drive-by fix PR or commit in the code to make it read better overall. Improves code quality and makes it easier to reason about. ## Part 1: Cleaning up dead code Be aggressive when deleting code; question the user if things are ok to delete but perhaps aren't covered in E2E tests or (formal) specifications (may be a missing edge case). Consult git history, trace storage, issue tracking, slack, etc. to autonomously come to a conclusion autonomously if you can; only refer to the human if you can't be sure. ## Part 2: Improving Codebase Quality Think in terms of John Ousterhout's "A Philosophy of Software Design"; specifically, in optimizing for deep modules over shallow ones. You want narrow interfaces which provide deep functionality. These sort of changes work best as no-op cleanup commits or PRs. Do not mix behavior changes with them if at all possible. You are trying to set up some "drive-by fixes" that leave the code better than you found it. It's best to write code like this from the start, but often coding changes leave room for consolidation; imagine a callstack that looks like: ``` handle_checkout() # A -> create_order() # B' -> insert_order() # C ``` where, in the process of feature work, B' has been modified. This is a great opportunity to look at A & C and consider whether those abstractions are shallow. Some rules of thumb: - Consider only the production code from the perspective of a new reader. How many hops do they need to "jump" in a codebase on this callstack to get to the "meat" of the functionality? You are trying to minimize the number of those hops for that person. - Ignore unit tests when thinking about this. Typically unit tests are fragile and tied to implementation. - Small, tiny functions which just call out to each other, unnecessary interfaces to provide "abstraction" are typically smells of this. i.e. it is very painful to read code that requires >1 jump to understand what an abstraction actually *does*. Once you refactor, you can repeat this process recursively (collapsing adjacent shallow layers of abstraction to form deeper modules). Example of a great diff: ```diff def run(args): - return f(args) - -def f(args): a, b = unpack(args) return g(a, b) def g(a, b): # do something ```
在 GitHub 查看