Summary: Suspect indentation warning
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-09-23 12:26:40 PDT ---
Unlike Python, Haskell, F# and few other languages, line indentations in D
don't determine the semantics of the program. Yet programmers are humans, they
do make mistakes, and for them indentations have meaning and importance (this
is why good programmers usually indent their code carefully). A badly indented
code doesn't just look sloppy, it may hide semantic problems.

To reduce the noise it's important to minimize false positives, so the D
compiler may issue warnings (errors are too much) only in few specific
situations where a bad indentation is a clue of a possible semantic bug, and
ignore indentations in all other situations.

A situation that may justify a warning, an unexpected positive indentation
after a single-line then/else/for/foreach/while:

if (x > 5)
    a = 1;
    b = 2; // suspect indentation warning

if (y > 2)    
    c = 3;   
    d = 4; 
    e = 5; // suspect indentation warning

for (int i = 0; i < 10; i++)
    g++; // suspect indentation warning

foreach (j; 0 .. 10)
    j++; // suspect indentation warning

while (x < 10)
    x = foo(x);
    y++; // suspect indentation warning

if (x > 5)
    a = 1; b = 2; // no warning here?

if (x > 5)
a = 1;
b = 2; // no warning here

if (x > 5) a = 1; b = 2; // no warning here

This simple warning is able to catch some common bugs (just as requiring {}
instead of just a semicolon avoids other similar bugs).

See also bug 4357

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to