Recursion

Why Is Recursion Banned by NASA?

The idea that NASA banned recursion comes from a 2006 JPL coding guideline for safety-critical code. It restricts recursion so the code can be analyzed.

On this page
  1. The short answer
  2. Where the rule comes from
  3. What rule 1 says
  4. Why recursion was restricted
  5. What the rule does not mean
  6. How teams work around it
  7. Key takeaways

The short answer

NASA has not banned recursion across the board. The idea traces back to a set of coding rules that Gerard Holzmann, working at the NASA/JPL Laboratory for Reliable Software, published in 2006 as The Power of 10: Rules for Developing Safety-Critical Code. The first rule restricts code to very simple control flow, and that includes a ban on direct and indirect recursion. These rules are guidelines for certain safety-critical JPL software. They are not a policy for every NASA project.

Where the rule comes from

Holzmann’s paper, published in IEEE Computer in 2006, lists ten rules for writing C code that is safe and easy to check. The goal is to remove programming practices that make code hard to review and hard for automated tools to analyze. The rules were meant to complement MISRA C, an existing set of guidelines for C code in safety-critical industries.

What rule 1 says

Rule 1 says to restrict all code to very simple control flow constructs. It bans goto statements, setjmp and longjmp, and direct or indirect recursion. Direct recursion is a function that calls itself. Indirect recursion is a cycle of calls, such as function A calling function B, which calls A again.

Why recursion was restricted

The reasoning centers on analysis. Without recursion, the function call graph has no cycles. That lets analysis tools work out an upper bound on how much stack memory the program can use before it runs. Rule 2 applies the same logic to loops: every loop should have a fixed upper bound that a tool can check.

The rules are about what tools can prove. A recursive function can be correct and efficient. The restriction matters most where memory use must be predictable and a stack overflow is not acceptable.

What the rule does not mean

  • It is not a general claim that recursion is bad. Recursion is used widely in compilers, tree processing and many other kinds of software.
  • It does not cover all NASA software. It is a coding guideline for particular safety-critical JPL projects.
  • It does not apply to most software. Desktop, web and business applications are not held to these rules.

How teams work around it

Projects with this kind of restriction usually rewrite recursive logic as a loop that uses an explicit stack. Tree traversal is the common example: instead of relying on the call stack, the program keeps its own stack data structure, as described in stack operations in data structure. A fixed-size array for that stack has a known maximum size, so memory use can be checked before the program runs.

Key takeaways

  • The claim that NASA banned recursion refers to rule 1 of Holzmann’s 2006 coding guidelines.
  • The guidelines came from NASA’s JPL and target safety-critical C code.
  • The reason is static analysis: without recursion, stack use can be bounded and checked.
  • Recursion remains a useful tool elsewhere; the restriction is about proving properties of specific code.

The complete guide to recursion

Recursive Algorithm Examples
Read the guide

Keep exploring

Guides from other topics

All topics →

AVL Trees in Data Structures

An AVL tree is a self-balancing binary search tree. Learn how balance factors and rotations keep search, insert, and delete at O(log n) in the worst case.

AVL Trees 4 min read