Generalization
Generalization is the process of taking a solution that works for a specific case and expanding it to work for a whole class of similar cases. It is how you go from solving one problem to solving many problems. Instead of figuring things out from scratch every time, you extract the underlying principle and apply it broadly.
What Generalization Is
When you solve a specific problem, you produce a specific solution. When you generalize, you step back and ask: "What is the underlying principle here? What other situations does this apply to?"
Specific: "To get from my house to the airport, turn left on Oak,
right on Main, take Highway 101 south to Exit 14."
General: "To navigate to any destination, identify your starting point,
look up the route, follow the turn-by-turn directions, and
adjust if you encounter unexpected road conditions."
The specific solution works for one trip. The general solution works for any trip. That is the power of generalization.
Everyday Examples
Learning to Drive
When you first learned to drive, everything was specific. You practiced in one car, on specific roads, at specific times. But you were actually learning general skills.
Specific experience:
Drove a 2019 Honda Civic on Elm Street at 2:00 PM
Generalized skills:
- Steering (works in any car)
- Braking (works in any car)
- Checking mirrors (works in any car)
- Reading traffic signals (works on any road)
- Merging into traffic (works on any highway)
- Parallel parking (works in any space)
Result:
You can drive a rental car in a foreign city on your
first try, because the specific skills generalized
into universal driving ability.
You did not learn to drive "a Honda Civic on Elm Street." You learned to drive, period. That is generalization happening naturally.
Cooking Beyond Recipes
A beginner cook follows exact recipes. An experienced cook generalizes from specific recipes to techniques.
Specific recipe:
Sear chicken breast in olive oil at medium-high heat
for 4 minutes per side until golden brown.
Generalized technique:
To sear any protein:
1. Pat dry (moisture prevents browning)
2. Season (salt at minimum)
3. Heat fat in pan until shimmering
4. Place protein, do not move it
5. Wait until it releases naturally from the pan
6. Flip once and finish
This works for chicken, steak, fish, pork chops, tofu.
The specific temperatures and times vary, but the
technique is the same.
A cook who generalizes from "sear chicken" to "sear protein" can handle unfamiliar ingredients because they understand the principle, not just the instance.
First Aid Training
First aid courses teach specific scenarios, but the goal is to produce general skills.
Specific: How to treat a burn from a stove
General: How to treat any burn (cool water, do not pop blisters,
cover loosely, seek help if severe)
Specific: How to help someone choking on food
General: How to clear any airway obstruction
(assess, back blows, abdominal thrusts)
Specific: How to stop bleeding from a kitchen knife cut
General: How to manage any external bleeding
(apply pressure, elevate, bandage)
The trained responder generalizes from practice scenarios to handle real emergencies they have never specifically rehearsed.
Negotiation Skills
Someone who negotiates a good deal on a car has a specific skill. Someone who understands negotiation principles has a general skill.
Specific: "I talked the car dealer down from $25,000 to $22,000
by getting quotes from competing dealers."
Generalized principle: Having alternatives strengthens your position.
- Salary negotiation: Having another job offer
- Buying a house: Having other properties you like
- Vendor selection: Having competing bids
- Freelance pricing: Having a full client roster
Same principle, different domains.
Parenting Across Ages
Parents who generalize adapt better as their children grow.
Specific: "My 3-year-old has tantrums when tired. I avoid
scheduling activities during nap time."
Generalized principle: People of all ages behave poorly when their
basic needs are not met. Address the underlying need, not the behavior.
Applied to a teenager:
Irritable and withdrawn? Check: Are they sleeping enough?
Eating regularly? Getting social interaction? Overwhelmed by school?
Applied to a coworker:
Snapping in meetings? Consider: Are they overloaded?
Under-resourced? Dealing with something personal?
The Generalization Process
Generalization follows a recognizable process:
Step 1: Solve a specific problem
"I fixed this bug by adding input validation."
Step 2: Identify what made the solution work
"The bug happened because the function received unexpected input."
Step 3: Ask "Where else could this apply?"
"Other functions probably have the same vulnerability."
Step 4: Formulate a general principle
"All functions that accept external input should validate
that input before processing it."
Step 5: Apply the principle broadly
Review all external-facing functions and add validation.
This same process works outside of technology:
Step 1: "I slept better after removing my phone from the bedroom."
Step 2: "The phone was causing late-night scrolling and blue light."
Step 3: "Other screens probably have the same effect."
Step 4: "Reducing screen exposure before bed improves sleep."
Step 5: Move all screens out of the bedroom, set a screen cutoff time.
Generalization in Technology
Functions That Work for Any Input
The most direct application of generalization in programming is writing functions that work for any input, not just one specific case.
Specific (only works for one case):
Calculate the tax on a $100 purchase in California:
tax = 100 * 0.0725
total = 100 + tax
General (works for any case):
calculate_total(price, tax_rate):
tax = price * tax_rate
return price + tax
Now works for:
calculate_total(100, 0.0725) California purchase
calculate_total(50, 0.06) Florida purchase
calculate_total(200, 0.20) UK purchase
calculate_total(75, 0.0) Tax-exempt purchase
The specific version solves one problem. The general version solves infinite problems with the same structure.
Design Patterns in Software
Software design patterns are generalizations of solutions that developers encountered repeatedly.
Specific problem:
"My shopping cart needs to notify the inventory system,
the analytics system, and the email system whenever
an order is placed."
Generalized pattern (Observer Pattern):
"When one object changes state, all dependent objects
should be notified automatically."
This same pattern applies to:
- Social media: notify followers when someone posts
- Stock trading: notify traders when a price changes
- IoT: notify the dashboard when a sensor reads a new value
- Chat apps: notify users when a new message arrives
From Script to Product
A common journey in software development is generalizing a one-off script into a reusable product.
Stage 1 - Specific script:
"I wrote a script that converts our company's Excel reports
into PDF format."
Stage 2 - Slightly generalized:
"I made it work with any Excel file, not just our reports."
Stage 3 - More generalized:
"I added support for CSV and Google Sheets too."
Stage 4 - Fully generalized product:
"It converts any tabular data from any source into any
output format. Users configure their source, transformations,
and output through a settings file."
Many successful software products started as specific solutions to one person's problem that were progressively generalized.
General-Purpose Algorithms
Algorithms are generalizations by nature. A sorting algorithm does not sort "employee names" or "product prices." It sorts any comparable list.
Specific: Sort these 5 names alphabetically: Alex, Dana, Bo, Eve, Cal
General: Sort any list of comparable items in ascending order
The same algorithm sorts:
- Names alphabetically
- Prices from low to high
- Dates from earliest to latest
- Scores from lowest to highest
- File sizes from smallest to largest
Levels of Generalization
Generalization exists on a spectrum. More general is not always better. The right level depends on your needs.
Too specific:
"Instructions for making a peanut butter and jelly sandwich
using Skippy brand peanut butter, Smucker's grape jelly,
and Wonder white bread."
Appropriately general:
"Instructions for making a sandwich with a spread, a filling,
and bread of your choice."
Too general:
"Instructions for combining food items."
The middle version is useful. It guides you without being so specific
that it only works in one situation, or so vague that it provides
no practical guidance.
In software, the same spectrum exists:
Too specific:
A function that calculates shipping cost for a 5-pound package
going from New York to Los Angeles via FedEx Ground.
Appropriately general:
A function that calculates shipping cost given weight,
origin, destination, and carrier.
Too general:
A function that "calculates costs" with no clarity about what
kind of cost, what inputs it needs, or what it returns.
When Not to Generalize
Generalization is powerful, but it has limits. Sometimes the specific solution is the right one.
- One-time problems: If you will never encounter this situation again, the overhead of generalizing is wasted effort.
- Highly context-dependent situations: Some problems are so shaped by their specific context that a general solution misses critical nuances.
- Premature generalization: Generalizing from one example is dangerous. You need multiple specific cases to generalize reliably.
- When simplicity matters: A specific solution is often simpler, more readable, and easier to maintain than a general one.
Should you generalize?
Ask: Will I encounter this type of problem again?
Yes -> Generalize
No -> Specific solution is fine
Ask: Do I have enough examples to generalize from?
3+ similar cases -> Safe to generalize
1-2 cases -> Wait for more data
Ask: Is the general solution significantly more complex?
Slightly more complex -> Worth it for reuse
Massively more complex -> Keep it specific for now
Common Pitfalls
Generalizing from too few examples
Seeing one successful sales call and concluding "always start with a joke" is premature generalization. You need multiple examples across different contexts to form a reliable general principle.
Over-generalizing
"All meetings are a waste of time" is an over-generalization. Some meetings are wasteful. Others are essential. The useful generalization is "meetings without a clear agenda and expected outcomes tend to waste time."
Losing important specifics
When you generalize, some details get dropped. Make sure the details you drop are truly irrelevant. "All customers want the cheapest option" loses the important specific that some customers prioritize quality or speed over price.
Generalizing across incompatible domains
A pattern that works in one domain may not transfer to another. Military strategy does not always generalize to business strategy. Parenting techniques do not always generalize to management. Test your generalizations before committing to them.
Confusing abstraction with generalization
Abstraction removes details to focus on what matters. Generalization extends a solution to cover more cases. They are related but different. You can abstract without generalizing (simplify one solution) and generalize without abstracting (extend a detailed solution to more cases).
Key Takeaways
- Generalization transforms a specific solution into one that works across a class of similar problems. It is how you go from solving one problem to solving many.
- Everyday examples include learning to drive (specific car to any car), cooking (specific recipe to general technique), and negotiation (specific deal to universal principles).
- The generalization process is: solve a specific case, identify what made it work, ask where else it applies, formulate a general principle, and apply it broadly.
- In technology, generalization appears in functions that handle any input, design patterns, scripts that become products, and general-purpose algorithms.
- The right level of generalization is a balance. Too specific limits reuse. Too general loses practical guidance. Aim for the level that serves your actual needs.
- Do not generalize from too few examples, across incompatible domains, or when the overhead of generalization exceeds its benefits.