LoC is simply not a valuable metric. Instead, look to how much a method does. A method should generally do one thing. IMHO, it is sometimes ok to tack on 1 or 2 very simple operations. For example, calculating the perimeter of a rectangle:
It could be:
public int GetPerimeter(int side1, int side2)
{
totalWidthLength = side1 * 2;
totalHeightLength = side2 * 2;
return totalWidthLength + totalHeightLength;
}
-OR-
public int GetPerimeter(int side1, int side2)
{
return DoubleSide(side1) + DoubleSide(side2);
}
private int DoubleSide(int side)
{
return side * 2;
}
Personally, I prefer the first method, even though it technically performs more than one operation. At the same time, you can also have methods with many lines of code that are simple to read and understand.
public void UpdateCustomer()
{
customer Customer = new Customer();
customer.Name = textboxName.Text;
customer.AddrLine1= textboxName.Text;
customer.AddrLine2 = textboxName.Text;
customer.OfficialName = textboxName.Text;
customer.Age = textboxName.Text;
customer.BirthDay = textboxName.Text;
customer.NickName = textboxName.Text;
customer.LastLocation = textboxName.Text;
customer.... = textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer.... = textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer.... = textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
customer....= textboxName.Text;
db.InsertOnCommit(customer)
db.SubmitChanges();
}
The above example is about 50 lines, but it could even be 200 lines, and would make no difference. Each property assignment on the customer object adds practically no complexity, so the 50 line method remains at the same complexity level as your average 4 line method. In fact, I would go so far as to say that it has basically the same readability as the method below:
public void UpdateCustomer()
{
customer Customer = new Customer();
customer.Name = textboxName.Text;
db.InsertOnCommit(customer)
db.SubmitChanges();
}
The 50 line method could probably be acheived in under 10 lines through the use of reflection and regex, iterating over each of the properties in Customer and searching for a textbox that has a matching LIKE value in its name. Obviously, that would be an example of code that is way too clever and resorts to wacky hacks to acheive an asthetic ideal. The bottom line is that LoC is an extremely unreliable complexity/readability metric. Everyone already knows this (my CRUD example is in no way uncommon), and yet while most people talk about how horrible LoC is at measuring productivity, we constantly hear about this LoC per method rules that are supposed to measure code quality. It really cannot be both ways.