← Back to list

Code Judo in Code Review

Code Judo is a metaphor borrowed from the martial art — in Judo, you use your opponent’s weight and momentum against them, minimal effort…

AC in Data Folks Indonesia · 2026-06-28 10:22 · 3 claps · 2.6 min read
#software-development #python #code-review #coding-best-practices
Open on Medium ↗
Wiki topics: 💻 · Programming 🥊 · Combat Sports

Code Judo in Code Review

Photo by Joshua Jamias on Unsplash

Photo by Joshua Jamias on Unsplash

Code Judo is a metaphor borrowed from the martial art — in Judo, you use your opponent’s weight and momentum against them, minimal effort for maximum effect.

Basically, you are doing “code judo” in code review when you try to find an alternative of implemented solution to make a change dramatically simpler, rather than adding new complexity to handle it.

Instead of fighting the codebase by bolting on more logic, you redirect it so the problem nearly solves itself.

I found this term when reading a code agent skill from cursor plugins where the document specifically stated “code judo”

Here’s the concrete examples of code judo

  • Instead of adding a 5-branch conditional to handle 5 edge cases, change the data model so all 5 cases become the same case
# 1. Replace multi-branch conditional with a dispatch table
# ❌ Before
def process(action, data):
    if action == "create": return create(data)
    elif action == "update": return update(data)
    elif action == "delete": return delete(data)
    elif action == "archive": return archive(data)

# ✅ After — adding new actions costs zero branches
HANDLERS = {"create": create, "update": update, "delete": delete, "archive": archive}
def process(action, data):
    return HANDLERS[action](data)
  • Instead of handling logic null value, add default value
# 2. Replace scattered None-checks with a Null Object
# ❌ Before — None guards spread across every callsite
def render(user):
    name = user.name if user else "Guest"
    avatar = user.avatar if user else DEFAULT_AVATAR
    role = user.role if user else "viewer"

# ✅ After — callsites become unconditional
@dataclass
class AnonymousUser:
    name = "Guest"
    avatar = DEFAULT_AVATAR
    role = "viewer"

def render(user):
    name, avatar, role = user.name, user.avatar, user.role
  • Instead of a boolean flag that forks the function internally, use a format string that looks up the right function. This is way scalable and maintainable when you want to add more format. So, you don’t add more conditional statements inside the function
# 3. Replace flag arguments with polymorphism
# ❌ Before — boolean flag that forks the entire function body
def export(data, as_csv=False):
    if as_csv:
        return ",".join(str(x) for x in data)
    else:
        return json.dumps(data)

# ✅ After — open for extension, no internal branching
EXPORTERS = {
    "csv": lambda data: ",".join(str(x) for x in data),
    "json": lambda data: json.dumps(data),
}
def export(data, fmt="json"):
    return EXPORTERS[fmt](data)
  • Instead of sequential async calls one by one, use asyncio.gather to run them all at once
# 4. Replace sequential awaits with parallel execution
# ❌ Before — independent I/O serialized for no reason
async def get_dashboard(user_id):
    profile = await fetch_profile(user_id)
    orders  = await fetch_orders(user_id)
    notifs  = await fetch_notifications(user_id)
    return profile, orders, notifs

# ✅ After — 3x faster, same logic
async def get_dashboard(user_id):
    return await asyncio.gather(
        fetch_profile(user_id),
        fetch_orders(user_id),
        fetch_notifications(user_id),
    )
  • Instead of repeated validation, use existing library to automatically checks
# 5. Replace repeated validation conditionals with a declarative schema
# ❌ Before — every field validated ad-hoc, grows with every new field
def validate(data):
    errors = []
    if not data.get("email"): errors.append("email required")
    if not data.get("name"): errors.append("name required")
    if len(data.get("password", "")) < 8: errors.append("password too short")
    return errors

# ✅ After — adding a field = one line in the schema
from pydantic import BaseModel, constr

class UserInput(BaseModel):
    email: str
    name: str
    password: constr(min_length=8)
# validation happens on instantiation; errors are automatic

Sometimes, I is a bit challenging to review code manually (you may need experience and expertise to do so) because you constantly challenging the implementation of the function. However, I find it fun because there are multiple ways to do the same thing and considering the pros and cons, it will be more fun when you are doing pair programming, even if it will take longer time. But, hey it may have better code quality.


메타데이터
post_id
def2c1fdcef6
slug
code-judo-in-code-review-def2c1fdcef6
url
https://medium.com/data-folks-indonesia/code-judo-in-code-review-def2c1fdcef6
canonical_url
https://medium.com/data-folks-indonesia/code-judo-in-code-review-def2c1fdcef6
author_url
https://medium.com/@andreaschandra
status
ok
fetched_at
2026-07-27 00:46:47