What is the reason that the layout of the table in the code is considered bad?

My colleagues tell me that tabular formatting of the code is bad, and it is not readable, and I have to follow the conventions. What's wrong with table-based formatting? Why is it forbidden?

I ask, because for me it is much more readable.

Examples (not real code):

if (res == ResultType.Failure)               
  something = ProcessFailure(..);
if (res == ResultType.ScheduledAndMonitored) 
  something = DoSomething(...) && DoSomething3(..);
if (res == ResultType.MoreInfoAvailable)     
  info = GetInfo(..);
if (res == ResultType.OK && someCondition)   
  something = DoSomething2(..);
.... continued

against

if (res == ResultType.Failure)               something = ProcessFailure(..);
if (res == ResultType.ScheduledAndMonitored) something = DoSomething(...) && DoSomething3(..);
if (res == ResultType.MoreInfoAvailable)     info      = GetInfo(..);
if (res == ResultType.OK && someCondition)   something = DoSomething2(..);
.... continued

Why I think the second is better:

  • I don’t need to analyze the text with my eyes - I see the structure of the teams at a glance.
  • I see right away
    • that there are some ifs and assignments
    • that the enumeration used in the conditions is ResultType and no more
    • that only the last condition consists of two expressions

: . . , , - , . ?

+5
18

, "" . , 50- . , , :

  • , diff grep, . , . , grep - if, ifTrue.

    ( , Lisp Emacs, , . # , , # - 1 2 , .)

  • 95 , .. . . ( ) , . . , , , .

. . , .: -)

, , :

  • char 0x09: , , ; .
  • : , , , ,
  • " ": , , ( , - , )
  • StyleCop , : ? . : " "
  • : , ,
  • : , wimpy-? -, , , . . : " "
  • : , ( ), - ; - ( -!), , .

(!)

, , , . , switch IDictionary<ResultType,Action>, - -tuples ( ), , - . , , . , , , , , , if .: -)

+2

, , , ? , . , .

+13

"" :

public string GetMessageFromErrorCode(int code)
{
    switch (code)
    {
        case 1: return "OK";
        case 2: return "Syntax Error";
        case 3: return "Other error";
    }
}

, #, case break. "

. , . , , linq , , .

. :
/ ( )

+5

.

, , , , inline . / .

, , , . 3 , 5, - . , , "" , .

, if, .

if (res == ResultType.Failure)               
{
  something = ProcessFailure(..);
}

if (res == ResultType.ScheduledAndMonitored) 
{
  something = DoSomething(...) && DoSomething3(..);
}

if (res == ResultType.MoreInfoAvailable)     
{
  info = GetInfo(..);
}

if (res == ResultType.OK && someCondition)   
{
  something = DoSomething2(..);
}

, , . , .

+5

, : IDE/, . , , .

- , . , , , .

+3

, , , , , ,

something
something
info
something

, , , , . , , , .

+3

, , . : - , , , , , , , , .

, - .

+2

, , , . , , .

IDE, Visual Studio, , .

, , [StyleCop] [1].

, Stylecop , .

, Nilesh

+2

, . . , .

- . .

+2

- . - , . #, .

, .

if (!HydrogenTankFull())                          FillHydrogenTank();
if (!OxygenTankFull())                            FillOxygenTank();
if (HydrogenTankFull() && OxygenTankFull())       TestGimbals();
if (GimbalsTested() && LaunchButtonPressed())     IgniteEngine(); BlowRestrainingBolts();
if (LaunchPadCleared())                           TransferControlToHouston();

?!

+2

, , , . , , , 4 . #, Python. # vs Python, if, MANY . StyleCop . StyleCop, FxCop, ReSharper - . return? , return - , else if, " " ( switch), :

// This should be in it own function; I am just too lazy to spell out a signature.
{
    if (res == ResultType.Failure)
    {
        return ProcessFailure(..);
    }

    if (res == ResultType.ScheduledAndMonitored)
    {
        bool result = DoSomething(...);
        result = result && DoSomething3(..);
        return result;
    }

    if (res == ResultType.MoreInfoAvailable)
    { 
         info = GetInfo(..);
         // Ok, and then?
    }

    if (res == ResultType.OK && someCondition)
    { 
        return DoSomething2(..);
    }

    // Else ...

    Debug.Assert(false, "Why did we get here? Explanation: ");
}

, , , . - . . , . , StyleCop , , , , / ..

, , .

+1

, . , .

if (res == ResultType.Failure)               
{
  something = ProcessFailure(..);
}
if (res == ResultType.ScheduledAndMonitored) 
{
  something = DoSomething(...) && DoSomething3(..); //Bit-and on the results? huh.
}
if (res == ResultType.MoreInfoAvailable)     
{
  info = GetInfo(..);
}
if (res == ResultType.OK && 
    someCondition)   
{
  something = DoSomething2(..);
}

, , , /. , .:

+1

, () , ,

  • (, , ). , - , , .
  • , , , , , .
  • , , , :)...
+1

, , , . , , , , , , , - , , .

, , .

+1

, " " . , . .

IMO.

+1

. , , . , ? , , , , . , .

, ; , .

0

. , , . , hte . :

void LogMessage(LogLevel lvl, string msg)
{
  if (!this.loggingManager.IsLogging) return;
  if (lvl < this.loggingLevel) return;

  this.loggingManager.Write(this.loggerName, msg);
}

void DrawGeometry(Graphics g, Geometry geom, Layer layer, double scale)
{
  if (geom == null) return;
  if (!layer.IsDisplayed) return;
  if (this.isDisplayByScale && (scale < this.minScale || scale > this.maxScale) return;
  if (this.ColorsToTreatAsTransparent.Contains(layer.Color)) return;

  Geometry xformed = this.Transform(geom);
  using (Pen p = new Pen(layer.Color, layer.Width))
  {
    g.Draw(xformed, p);
  }
}

, . , /.

0

, , , dinky, .

, , , , if if (condition); 4 , , if , , , :

if (condition)
{
    single-line-statement;
}
0

All Articles