LOC should not count lines with only opening or closing brace

Code style should not have an impact on LOC.

Int32 foo(Int32 x) {
return x+1; }

Should have the same LOC as

Int32 foo(Int32 x) 
{
return x+1; 
}

Our coding style have a huge impact on our LOC.

Regards,

Hey there.

Thanks for the feedback.

We aim and have a relatively standardized way of calculating LOC across multiple programming languages and coding styles.

One could argue that this code snippet:

var template = "{a}{b}-{c}{d}";
var myStuff = template
                .replace("{a}", a)
                .replace("{b}", b)
                .replace("{c}", c)
                .replace("{d}", d);

Should only count as 2 line of code because it can also be styled like this:

var template = "{a}{b}-{c}{d}";
myStuff = template.replace("{a}", a).replace("{b}", b).replace("{c}", c).replace("{d}", d)

Similarly, you could also write the code you shared as

int foo(int x) { return x+1; }

We have the draw the line somewhere – and right now we draw that line at not counting empty lines or comments.

2 Likes

Is it possible that an empty line is any line that contain neither letters nor numbers?
Microsoft has a Visual studio plugin to shrink empty lines and they use this description.

There are some languages that are more ‘chatty’ with ‘control characters’. The same code in VB.NET and C#:

Public Sub Test()
  Try
    If _doTest Then
      Select _version
        Case 1:
          ExecuteTest()
        Case Else:
          DoNothing()
      End Select
    End If
  Catch ex As Exception
    Log(ex)
  End Try
End Sub
public void Test()
{
  try
  {
    if (_doTest)
    {
      switch (_version)
      {
        case 1:
        {
          ExecuteTest()
          break;
        }
        default:
        {
          DoNothing();
          break;
        }
      }
    }
  }
  catch (Exception ex)
  {
    Log(ex)
  }
}

Here it’s a difference of 14 to 26 lines, almost double. Counting only lines that contain letters and/or numbers would bring the C# example to 12 lines, much more in line with other languages that don’t contain such control characters.

Developers shouldn’t be punished by the language that they choose to program in.