Loading...
Loading...
Compare original and translation side by side
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"任何傻瓜都能写出计算机能理解的代码。优秀的程序员写出人类能理解的代码。"
"Act as Martin Fowler. Review this legacy class.Focus on:
- Code Smells: Long Method, Large Class, Data Clumps.
- Readability: Are variable names descriptive? (e.g.,
vsdaysSinceCreation).d- Refactoring Moves: Suggest specific moves like 'Extract Method' or 'Introduce Parameter Object'."
"扮演Martin Fowler的角色。审查这个遗留类。重点关注:
- 代码异味:过长方法、过大类、数据泥团。
- 可读性:变量名称是否具有描述性?(例如:
vsdaysSinceCreation)。d- 重构手法:建议具体的手法,如'Extract Method'或'Introduce Parameter Object'。"
"Critique this system design from a Fowler perspective.Questions to ask:
- Monolithic vs. Microservices: Is the complexity justified? Are we building a 'Distributed Monolith'?
- Strangler Fig: How can we migrate this legacy system incrementally?
- Domain Model: Is the business logic rich or do we have an 'Anemic Domain Model'?"
"从Fowler的视角批判这个系统设计。需要询问的问题:
- 单体 vs 微服务:复杂度是否合理?我们是否在构建“分布式单体”?
- Strangler Fig模式:如何逐步迁移这个遗留系统?
- 领域模型:业务逻辑是否丰富,还是我们拥有一个“贫血领域模型”?"
public void printOwning(double amount) {
printBanner();
// print details
System.out.println("name: " + _name);
System.out.println("amount: " + amount);
}public void printOwning(double amount) {
printBanner();
// print details
System.out.println("name: " + _name);
System.out.println("amount: " + amount);
}public void printOwning(double amount) {
printBanner();
printDetails(amount);
}
private void printDetails(double amount) {
System.out.println("name: " + _name);
System.out.println("amount: " + amount);
}printDetailspublic void printOwning(double amount) {
printBanner();
printDetails(amount);
}
private void printDetails(double amount) {
System.out.println("name: " + _name);
System.out.println("amount: " + amount);
}printDetails// Just getters/setters
public class Order {
private List<LineItem> items;
// ... getters/setters
}
// Logic separated from data
public class OrderService {
public double calculateTotal(Order order) {
// ... loop and sum
}
}// Just getters/setters
public class Order {
private List<LineItem> items;
// ... getters/setters
}
// Logic separated from data
public class OrderService {
public double calculateTotal(Order order) {
// ... loop and sum
}
}public class Order {
private List<LineItem> items;
// Logic lives with the data
public double total() {
return items.stream()
.mapToDouble(LineItem::total)
.sum();
}
public void add(Product product) {
// Validation logic inside the entity
if (isFreemium() && items.size() >= 5) {
throw new OrderLimitException();
}
items.add(new LineItem(product));
}
}public class Order {
private List<LineItem> items;
// Logic lives with the data
public double total() {
return items.stream()
.mapToDouble(LineItem::total)
.sum();
}
public void add(Product product) {
// Validation logic inside the entity
if (isFreemium() && items.size() >= 5) {
throw new OrderLimitException();
}
items.add(new LineItem(product));
}
}mainmain