View on GitHub

Baseball-design

You may only catch and throw.

download .ZIPdownload .TGZ

The Baseball Design Pattern

C++ is known as an expansive, difficult language with many corner cases that trip up beginners and experts alike. The Baseball Design Pattern is a method of reducing the scope of the language, making it easier to learn and reason about.

There is one rule

  1. You may not return. You may only catch and throw.

Praise given to The Baseball Design Pattern

It causes immediate reations:

My eyes... the burning...

It provokes emotions:

Aaaaaah noooo

It is found to be useful:

This approach would be useful when the problem was that your code was running too fast.

It is challenging:

I dare you to use it in a coding interview

Try The Baseball Design Pattern today! Remember, you may only catch and throw.

Examples

Factorial

void factorial(int n, int accum = 1) {
  if (n == 0) throw accum;
  factorial(n - 1, n * accum);
}

More

A full working example can be found in the src/ directory.