In computer science, I have often come across the expression to back out meaning to say that a function is returned from before performing its actual task, as in this imaginary code comment:

double divide(double dividend, double divisor) {
  if (divisor == 0) {
    return 0; //divisor is zero => back out early
  }
  return (dividend / divisor);
}

Now I recently came across the expression to bail out in just the very same context. I know that to bail somebody out generally means to provide funds to get someone out of a difficult financial situation, so I was wondering if the writer confused to back out and to bail out or if to bail out really has this meaning, too.


OP: "I know that to bail somebody out generally means to provide funds to get someone out of a difficult financial situation"

Bail out also means to quit something:
"The actor has bailed out of the film after only three weeks' shooting." - Cambridge Dictionary

The phrase is also often used with the specific meaning of leaving a crashing plane via parachute:
"The pilot barely had time to bail out" - also Cambridge Dictionary.

I'd suggest that the use of the phrase in a coding situation is along these lines.


In computing, "to bail out" is "to exit early", for any reason, such as in your example. "To back out" generally has the meaning "to undo" changes, think ROLLBACK in SQL. ROLLBACK undoes and discards all current changes that have not yet been permanently committed (saved) to the database, returning it to its previous (stable) state.

Backing out should leave the program in a clean state, bailing out can leave the program in either a clean or an unstable state. Backing out is normally done carefully, bailing out is normally done quickly. For example, it might be desirable to restore the value of a changed variable on an error. Backing out will take care to do so, bailing out will exit as quickly as possible, potentially leaving a bad or invalid value in the variable.

Think of a plane on fire as a function about to crash the program. The program survives by bailing out with a parachute, but the function goes down in flames with the plane. (Actually, the function's run time and memory would be cleaned up and made inaccessible, equivalent to the plane being erased from existence before it has the chance to crash.)

Unfortunately, I can't find even bad references for either of these computing meanings, only blogs and the like showing them being used. If you'll forgive the original research:

A Taste of Recursion

By Dan Gookin

For recursion to work, the function must have a bailout condition, just like a loop. Therefore, either the value passed to the recursive function or its return value must be tested. Here’s a better example of a recursive function:

void recursion(int x)
{
    if(x==0)
        return;
    else
    {
        puts("Boop!");
        recursion(--x);
    }
}

The recursion() function accepts the value x. If x is equal to zero, the function bails. Otherwise, the function is called again, but the value of x is reduced. The decrement prefix operator is used so that the value of x is reduced before the call is made.

(emphasis mine)

The meanings are very close to the standard English meanings:

bail out

  • to jump out of an aircraft with a parachute because the aircraft is going to have an accident
  • to stop doing or being involved with something

back out

  • to decide not to do something that you had said you would do
  • to refuse to do something you earlier had agreed to do

In my mind, they mean different but similar things in computing too. I could be wrong about their meanings not being interchangeable. Perhaps "to back out" of a function is acceptable technical English. If one of my colleagues wrote one where I thought they meant the other, I would certainly ask them to clarify it since clarity is one of the most important things in computing. However, others may differ from my viewpoint.