[Issue 4924] New: Suspect indentation warning

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 23 12:27:20 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4924

           Summary: Suspect indentation warning
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 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;   
else
    d = 4; 
    e = 5; // suspect indentation warning

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

foreach (j; 0 .. 10)
    h++;
    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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list