I was taught by an old-time programmer who called this nested code

    <b>text <u>text</u></b><br/>
} else {

as opposed to this code which was considered to be not nested

} else {log();}

When I started reading tutorials I found early on that I had the wrong definition to nested.

Messy vs clean is not sufficient for this because messy code encompasses other problems that I am not talking about, for example confusing flow of logic, using static initializers inappropriately, poor use of variable names, using twice the code to get the job done in a more confusing manner, etc.

What is the right word for this, where the first example is ... and the second example is not ...?

  • 3
    The real question is where is your <tbody>?
    – WuHoUnited
    Sep 29, 2011 at 0:22
  • 1
    TBH, I think the correct word is actually nested. You could say indented, but nesting is more correct, since it implies indent/outdent-ing that follows the structure of commands/elements.
    – ocodo
    Sep 29, 2011 at 1:40

5 Answers 5


Nesting is related to the enclosing of control structures one into another, and this is usually indicated through different indentation levels within the source code.

You can say the first example is Nested Source Code, and the second is not, you would be correct. If you said it was simply indented, you don't provide any additional information with regard to why it's indented.

  • I guess Properly Nested would be the word. Sep 29, 2011 at 14:11

"Indented / indentation" may be the word you're looking for ?

... indent style is a convention governing the indentation of blocks of code to convey the program's structure... Indent style is just one aspect of programming style.

Indentation is not a requirement of most programming languages, where it is used as secondary notation. Rather, programmers indent to better convey the structure of their programs to human readers. In particular, indentation is used to show the relationship between control flow constructs such as conditions or loops and code contained within and outside them...

  • 2
    Might be worthwhile adding that "nesting" is used in a more logically structural sense than the cosmetic "indentation" term. Sep 29, 2011 at 0:10
  • Agreed, nesting/nested is a better word for this than simply indenting.
    – ocodo
    Sep 29, 2011 at 1:41

I would say well formatted html or clean code. Like most computer languages formatting is not that important for the computer. However, for mortals like me proper formatting makes it much easier to understand. It doesn't take a lot of time to write clean code, but it will save you a lot of time in the long run. If I needed to debug the second example, the first thing I would do is reformat it.

There are various tools which will reformat the text so it is much more readable. Unfortunately, the results may show how poor the original code is. Many code generators produce pretty poor HTML, which may be the cause of or result from failing to properly format the code.


The following code is nested:

if (someCondition) { /*doSomething*/ } else { while (someOtherCondition) { if (someSubCondition) { /*doSomethingElse*/ } else { /*doSomethingCompletelyDifferent*/ }}}

Nested means, that some inner statements are nested within some outer statements. In fact, in most common programming languages, virtually all code is nested, because your code is nested with in functions, which are nested within modules. And in fact almost every statement nests other statements within itself.

Now the following code is indented:


On it's own, indenting only means, that you add horizontal whitespaces (usually space or tab) after linebreaks.

Now proper indenting as a part of proper formatting is the process of giving code a visual structure, that makes it's (nested) structure apparent (which is definitely not the case for the first code example). So let's properly indent it (without wanting to restart the religious war on the different indenting styles):

if (someCondition) { 
else { 
    while (someOtherCondition) {
        if (someSubCondition) {
        else {

Now the visual structure of the code represents it's nesting. By the number of tabs preceding a statement, you can directly see how deeply it is nested. You can easily distinguish inner from outer statements, and see where statements start and end.

So to summarize, code formatting (which includes indenting) is the technique of using (mostly) non-significant characters to give source code a visual structure. Proper code formatting means applying this technique to give the code a visual structure, that communicates it's semantic structure.


I would say "formatted" or "well-formatted". I disagree with "clean code" and "tight code" which other posters have suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.