fowler
Martin Fowler Style Guide
Overview
Martin Fowler is a loud advocate for refactoring, microservices, and agile software development. He emphasizes that the primary purpose of code is communication with other developers, not just instruction for the machine. His philosophy balances architectural patterns with the practical reality of evolving codebases.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
Core Principles
- Code for Humans: If it's hard to read, it's bad code, regardless of performance.
- Refactoring: Continuous improvement of the design of existing code. "Three strikes and you refactor."
- Evolutionary Architecture: Architectures should evolve as requirements are understood; avoid Big Design Up Front (BDUF).
- Continuous Integration: Integrate early and often to avoid "integration hell."
- Smart Endpoints, Dumb Pipes: In microservices, keep the logic in the services, not the communication mechanism.
Prompts
Refactoring Advice
"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.,
daysSinceCreationvsd).- Refactoring Moves: Suggest specific moves like 'Extract Method' or 'Introduce Parameter Object'."
Architectural Review
"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'?"
Examples
Refactoring (Extract Method)
Before (Long Method)
public void printOwning(double amount) {
printBanner();
// print details
System.out.println("name: " + _name);
System.out.println("amount: " + amount);
}
After (Clean, Composable)
public void printOwning(double amount) {
printBanner();
printDetails(amount);
}
private void printDetails(double amount) {
System.out.println("name: " + _name);
System.out.println("amount: " + amount);
}
Note: The code is strictly longer, but the intent is clearer. The printDetails method can now be independently tested or reused.
Anemic vs. Rich Domain Model
BAD: Anemic (Data Bags + Service Layer)
// 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
}
}
GOOD: Rich Domain Model
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));
}
}
Anti-Patterns (What NOT to do)
- Feature Branches: Long-lived branches that diverge from
mainfor weeks (violates CI). - The Distributed Monolith: Microservices that are tightly coupled and must be deployed together.
- Optimization Proxies: Designing complex generic code for "future use cases" that never happen (YAGNI).
- Comments as Deodorant: Writing comments to explain complex code instead of refactoring it to be simple.
Resources
More from copyleftdev/sk1llz
google-material-design
Design interfaces following Google's Material Design system, the unified visual language bridging digital and physical worlds. Emphasizes bold graphic design, intentional motion, adaptive layouts, and the material metaphor. Use when building modern, accessible, delightful user interfaces across platforms.
119renaissance-statistical-arbitrage
Build trading systems in the style of Renaissance Technologies, the most successful quantitative hedge fund in history. Emphasizes statistical arbitrage, signal processing, and rigorous scientific methodology. Use when developing alpha research, signal extraction, or systematic trading strategies.
104aqr-factor-investing
Build investment systems in the style of AQR Capital Management, the quantitative investment firm pioneering factor investing. Emphasizes academic rigor, transparent methodology, and systematic factor exposure. Use when building factor models, conducting asset pricing research, or designing systematic portfolios.
103minervini-swing-trading
Trade swing setups in the style of Mark Minervini, 3x US Investing Champion with 220%+ annual returns. Emphasizes SEPA methodology, trend templates, volatility contraction patterns (VCP), and strict risk management. Use when swing trading momentum stocks, identifying breakout setups, or building systematic trend-following strategies.
84de-shaw-computational-finance
Build trading systems in the style of D.E. Shaw, the pioneering computational finance firm. Emphasizes systematic strategies, rigorous quantitative research, and world-class technology infrastructure. Use when building research platforms, systematic trading strategies, or quantitative finance infrastructure.
63jump-trading-fpga-hft
Build trading systems in the style of Jump Trading, the high-frequency trading firm pioneering FPGA-based trading. Emphasizes hardware acceleration, network optimization, and nanosecond-level execution. Use when building FPGA trading systems, network-optimized infrastructure, or ultra-low-latency order execution.
29