TGViewer
codedump的电报频道 codedump的电报频道 @codedump_notes · 5.5K subscribers
Post #863 2.45K
#编码
#人工智能
我继续用《A Philosophy of Software Design》里的设计理念总结的skill来重构Rockraft的代码,它这一次没有改代码的实现,只是修改了代码的注释(pr),理由是:improve documentation to explain "why" not "what"。


以其中一段代码注释的前后修改为例:

修改前:

/// Write a log entry to the raft cluster
///
/// This function writes a LogEntry to the raft log and waits for it to be applied.
/// It can only be called on the leader node.
///
/// The `time_ms` field of the entry will be set to the current timestamp before writing.
///
/// # Arguments
/// * `entry` - The LogEntry to write
///
/// # Returns
/// * `Ok(AppliedState)` - The result of applying the log entry
/// * `Err(Error)` - If the operation failed or this node is not the leader


修改后:

/// Write a log entry to the raft log (leader-only)
///
/// Appends the entry to the local log and replicates it to followers.
/// Returns after the entry is committed (majority acknowledgment).
///
/// # Leader Requirement
/// This method **must** only be called when this node is the leader.
/// Callers should use `RaftNode::assume_leader()` to verify leadership first.
///
/// # Timestamp
/// The `time_ms` field is automatically set to the current time before writing.


可以看到,修改前的注释,只是简单列举函数的参数和返回值(重复了函数签名(signature)),而修改后增加了行为的解释和函数的前置要求(需要是leader)。

回到最开始做这个注释重构的动机上,注释、文档应该“explain "why" not "what"”这属于更偏代码审美品位的事情了,没有之前大量的代码训练实践,可能不会具备这样的品味。

而现在,如果AI一开始替代了大量手搓代码的实践,还能通过什么方式积累这样的品味?
GitHub GitHub - luoling8192/software-design-philosophy-skill: Claude Code skill: Software design philosophy guide based on A Philosophy… Claude Code skill: Software design philosophy guide based on A Philosophy of Software Design by John Ousterhout - luoling8192/software-design-philosophy-skill
  • ❤ 1
More from @codedump_notes
  1. Sep 27, 2026#系统编程 讲解Go语言并发主题的小书:《Go concurrency distilled》
  2. Sep 22, 2026#开源软件 开源本来承载的主要任务之一就是赢得信任,智谱这一把开源不但没有赢取信任,反而让更多人感到了疑问,比如我。
  3. Sep 22, 2026#开源项目 #Rust #数据库 hawdb:Rust编写的嵌入式图数据库,用于Nowledge产品中管理本地图数据。
  4. Sep 21, 2026#Rust #人工智能 最近看了好几个Rust相关的新闻,比如: * Rust在微软内部升级为一级语言:《Guest Post: Rust Is Tier-1 Language a…
  5. Sep 19, 2026#人工智能 这个翻译可以说是 信达雅 了。
  6. Sep 15, 2026#人工智能 《我不得不把才华埋葬在昨天》,Deepseek 核心开发的文章,也许再过一段时间,他就不用亲手写算子了。
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →