Modern Alternatives to "Main Calls Subroutines"

Still uses a main() function but makes it clean, injectable, and testable.

def main(
    reader=read_input_file,
    processor=process_data,
    validator=validate_rules,
    saver=save_to_db
):
    raw = reader()
    transformed = processor(raw)
    valid = validator(transformed)
    saver(valid)

Great for medium-sized scripts/tools in Python, Go, etc.

Very popular in enterprise (Clean Architecture, DDD, Vertical Slice).

  • Main becomes thin → just dispatches commands
  • Handlers contain the real logic
  • Excellent testability & decoupling

Pure functions in the middle, side effects only at edges.

// Pure core
fn calculate_total(items: &[Item]) -> Money { ... }

// Shell
fn main() -> Result<()> {
    let input = read_input()?;
    let result = process(&input);
    write_output(&result)?;
    Ok(())
}

No big central main() orchestrating everything.

  • Each feature = own module / bounded context
  • Orchestration via events, API calls, queues
Quality, Reliability & Service
Thank You For Visiting
Brooks Computing Systems - Jacksonville
Visit https://bcs.archman.us