Comprehension Debt

Functions over 80 lines, deep nesting, too many parameters

infoAI Qualitycomprehension-debt

Why this matters

AI tools generate monolithic functions because they produce code in a single pass. Long functions with deep nesting are hard to read, test, and debug — even for the AI that wrote them.

Bad
export async function handleCheckout(
  userId: string,
  cartId: string,
  couponCode: string | null,
  shippingMethod: string,
  billingAddress: Address,
  shippingAddress: Address,
  paymentMethod: string,
  saveCard: boolean,
  giftMessage: string | null,
  isGift: boolean
) {
  // ... 150 lines of nested logic
}
Good
interface CheckoutParams {
  userId: string;
  cartId: string;
  coupon?: string;
  shipping: ShippingDetails;
  billing: BillingDetails;
  payment: PaymentDetails;
}

export async function handleCheckout(params: CheckoutParams) {
  const cart = await validateCart(params.cartId);
  const totals = await calculateTotals(cart, params.coupon);
  const charge = await processPayment(totals, params.payment);
  return await createOrder(params, cart, charge);
}

How to fix

Break functions over 80 lines into smaller, named functions. Use an options object instead of many parameters. Extract nested logic into helper functions.

All rules