---
title: "If you need more than 3 levels of indentation, you're screwed anyway,… — Linus Torvalds Quote #8 | QuotesBy.net"
description: "If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. — a quote by Linus Torvalds."
image: "https://quotesby.net/wp-content/themes/quotesby-editorial/assets/og-default.png"
---

> # If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

[Linus Torvalds](https://quotesby.net/Linus-Torvalds)\#8

[Design](https://quotesby.net/Linus-Torvalds/design/)[Engineering](https://quotesby.net/Linus-Torvalds/engineering/)[Code](https://quotesby.net/Linus-Torvalds/code/)[Code quality](https://quotesby.net/Linus-Torvalds/code-quality/)[Structure](https://quotesby.net/topics/structure/)

[WhatsApp (opens in a new tab)](https://wa.me/?text=%E2%80%9CIf%20you%20need%20more%20than%203%20levels%20of%20indentation%2C%20you%27re%20screwed%20anyway%2C%20and%20should%20fix%20your%20program.%E2%80%9D%20%E2%80%94%20Linus%20Torvalds%20https%3A%2F%2Fquotesby.net%2FLinus-Torvalds%2F8%2F)[X (opens in a new tab)](https://twitter.com/intent/tweet?text=%E2%80%9CIf%20you%20need%20more%20than%203%20levels%20of%20indentation%2C%20you%27re%20screwed%20anyway%2C%20and%20should%20fix%20your%20program.%E2%80%9D%20%E2%80%94%20Linus%20Torvalds&url=https%3A%2F%2Fquotesby.net%2FLinus-Torvalds%2F8%2F)[Facebook (opens in a new tab)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fquotesby.net%2FLinus-Torvalds%2F8%2F)

## About this quote

What does it mean?Code requiring many indentation levels is usually too complex and needs restructuring.In plain termsIf your code is nested too deeply, rewrite it.What can you take from it?Keep code flat and simple to avoid complexity.

### Where it applies

- writing functions
- refactoring
- debugging

### Putting it to work

- reduce nesting
- extract methods
- simplify logic

### Questions to consider

- When is nesting acceptable?

### Another view

Some contexts legitimately require nested logic.

## More from Linus Torvalds

1. > Your job is being a professor and researcher: That's one hell of a good excuse for some of the brain-damages of Minix.

[Permalink to quote \#7](https://quotesby.net/Linus-Torvalds/7/ "Permalink to quote 7")
2. > You know you're brilliant, but maybe you'd like to understand what you did 2 weeks from now.

[Permalink to quote \#9](https://quotesby.net/Linus-Torvalds/9/ "Permalink to quote 9")
3. > Do you pine for the days when men were men and wrote their own device drivers?

[Permalink to quote \#6](https://quotesby.net/Linus-Torvalds/6/ "Permalink to quote 6")

## Related quotes

1. > I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad …

[Linus Torvalds](https://quotesby.net/Linus-Torvalds)[Linus Torvalds quote \#49](https://quotesby.net/Linus-Torvalds/49/ "Permalink to quote 49")
2. > Though I'll admit readability suffers slightly...

[Larry Wall](https://quotesby.net/Larry-Wall)[Larry Wall quote \#25](https://quotesby.net/Larry-Wall/25/ "Permalink to quote 25")
3. > Man is the animal that draws lines which he himself then stumbles over. In the whole pattern of civilization there have been two tendencies, one toward straigh…

[Piet Hein](https://quotesby.net/Piet-Hein)[Piet Hein quote \#1](https://quotesby.net/Piet-Hein/1/ "Permalink to quote 1")

```json
{
    "@context": "https://schema.org",
    "@type": "Quotation",
    "text": "If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.",
    "url": "https://quotesby.net/Linus-Torvalds/8/",
    "spokenByCharacter": {
        "@type": "Person",
        "name": "Linus Torvalds"
    }
}
{
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
        {
            "@type": "ListItem",
            "position": 1,
            "name": "Home",
            "item": "https://quotesby.net/"
        },
        {
            "@type": "ListItem",
            "position": 2,
            "name": "Authors",
            "item": "https://quotesby.net/authors/"
        },
        {
            "@type": "ListItem",
            "position": 3,
            "name": "Linus Torvalds",
            "item": "https://quotesby.net/Linus-Torvalds"
        },
        {
            "@type": "ListItem",
            "position": 4,
            "name": "Quote #8",
            "item": "https://quotesby.net/Linus-Torvalds/8/"
        }
    ]
}
```
