Why do people measure code in "lines"

It doesn't mean anything seeing how some people leave more comments than others and other things like

1
2
3
4
5
if(condition)
{
//I output text here.
cout<<"This is just an example."<<endl;
}


vs
if(condition) cout<<"With stuff like this why do people measure thing with lines of code?"<<endl;
second one makes more sense to me, look at how much work you save, 3 whole lines!

its also nicer to look at, as long as the line isn't too long

also, its a good thing it means nothing, c++ has no restriction as to how you format your code, unlike something such as python, which 5s q45te str5ct

s6rry, f6r s60e rea6n the t6- 3eve3 6f 0y 2eyb6ard dec5ded t6 64t-4t n40bers
Last edited on
Because number of lines is simple, easily recognizable, and "as good as anything else". There is no method of measuring code size that isn't depedent on coding style.

Also most professional/group environments have coding standards that each programmer is expected to adhere to. So something like the 2nd section you posted probably wouldn't fly.

And comments are usually considered part of the code because writing them requires effort just like writing code does -- and they're just as important when it comes to maintainability.
Last edited on
Personally, I'd write the same thing as:
1
2
3
if (condition)
   // I don't like "using" namespaces
   std::cout << "This is just an example." << std::endl;


It's all about preference and what's easiest for you to read. If you have to reread your own code more than once, it probably isn't the best way to write it. I hate writing the statements on the same line as the condition since there are times when conditions can be fairly long, and you'd have to make an exception to the rule. I don't need to make exceptions to mine.

And as for your style, including braces for a lone statement after a conditional, I believe it helps beginners understand the code better, but as you become more experienced, the braces just (to me anyways) clutter the code. I let my indentation tell me when things end.
Why don't you like using namespaces?
There has been many topics covering this, but later on down the road, possibly when you're working for a company, you could have conflicting functions. Let's say that you guys have using a third party library and that library happened to constantly "use" the std namespace in their code. Your company had developed a new namespace for all of the functions you guys use and have been told to "use" the namespace since you should only be using your functions.
1
2
using namespace xyz;
xyz::ourFunc()

You have been given permission to use this third party library since you're on a time schedule and their function is much more efficient than what you could have written in the current time frame.

The library you guys are using, third party, also has ourFunc() so when you call ourFunc, the compiler doesn't know which one to use. One compiler might let you slip by and try to guess at which one you meant, while another compiler will throw errors.

This just happened to a friend of mine who writes C# for industries and it took them several hours to track down the bug since the documentation for the library didn't include the function in it. They ended up wrapping the third party library in another namespace so they could explicitly call that function.
Topic archived. No new replies allowed.