Code lines number influenced by formatting style.

Started by
22 comments, last by Bacterius 10 years, 1 month ago

The imprecision of a line count is highly influenced by code formatting style:


int
function(int a, int b, int c)
{
    // Burn the  Parthenon here.
    int culprit;
   
}
 
for(unsigned i=0; i<n; i++)
{
    // Clean your room here.
}

As opposed to:


int function(int a, int b, int c){
    int culprit; // Burn the  Parthenon here.}
for(unsigned i=0; i<n; i++){
    // Clean your room here.}

How do developers deal with this issue? It can be the difference between 120,000 lines of code and 40,000 lines of code.

I guess that if you want to trick your boss, then the former is recommended.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.
Advertisement
I prefer the former but mine is :

#include <iostream>
#include <string>

using namespace std;

int triple (int num)
{
for (num = 0; num < 12; num += 2)
{
cout << num;
}

return num;
}

int main ()
{
string name;
int digit = 0;

cout << "Enter your name: ";
getline (cin, name);

cout << "Welcome " << name << endl;

triple (digit);

return 0;
}
I really love spaces because it makes my code clearer.
Depending on the programmer, a program can be 1000,000 lines of code or 100,000 lines of code.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

Don't count empty lines, bracer-only lines, comments, or even code that only contains declarations such as variables or function prototypes. And since you can split expressions over multiple lines, count multi-line statements as one. The options are near endless if you use a syntax-sensitive line counter.


How do developers deal with this issue? It can be the difference between 120,000 lines of code and 40,000 lines of code.

Usually we don't deal with it at all. Who cares? But for those who for some reason care, there are normalized ways of counting the number of lines.


I guess that if you want to trick your boss, then the former is recommended.

If you get paid by the number of lines created, or if your boss even cares about this as some kind of metric, it's time to switch job.

Yep lines of code is irrelevant. Just try to stick to the same code formatting policy agreed by your team (e.g. Google's style guides), don't start inventing your own. Apart from increasing legibility & readability, it stops a huge amount of refactoring-for-the-sake-of-readability, which developers are want to do, and is really a waste of time.

Storm Clouds over the Western Front - 2D aerial combat WIP | DarklightXNA on Twitter | 2DFlightSim on Youtube

if your boss even cares about this as some kind of metric, it's time to switch job.

^^this.
Even if we all used the same formatting, LOC would still be meaningless.
A lot of the time in the professional world, you'll write 10 per day. Sometimes you'll write 1000.
One time a group of us worked overtime for a month to try and solve a mission critical and obscure bug, which in the end took 1 LOC to fix...

I mention it because some programmer blogs insinuate in their posts that it matters. It is common to read:

"My project which is a 70,000 lines of code, was finished in 2007."

"... we were dealing with a huge codebase of 5,000,000 lines of code..."

However according to a study that I heard from Arthur Griffith, it takes roughly the same amount of time to write the same amount of lines of code in different languages by the same programmer. How true that is unverifiable for now(I can't find the study.)

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.
Yes, it is frequently used as a broad metric.

When your boss sends you an email that you are in charge of integrating a large new system to the engine, the line count serves as a quick estimate of how many headaches you will have.

You can also use megabytes if you prefer.

A student typically deals with 500 - 5,000 lines of code, or just a few kilobytes. A pro can usually digest the code in just a few minutes.
A 10 thousand LOC project is maybe 100KB of text. It is something you can glance over and understand in a few minutes, and be comfortable changing in a day or so.
A 5 million LOC project is going to be something on the order of 50MB. That is a lot of text to learn and understand, and it is unlikely one person can master it all.
A 50 million LOC project is going to be on the order of 500MB and span multiple development sites. A small team will be able to maintain a single component, a few individuals may master some slices of the system.

Metrics like lines of code or megabytes of source are useful as far as orders of magnitude are concerned. As an analogue, it gives a simple number that indicates if you are looking at a walking a small hill in a community park, wearing a backpack for a day-hike in foothills, planning a week hike up a mountain, climbing Mt Everest, or preparing for an interplanetary voyage. The precise number is unimportant, but the magnitude is informative.

How do developers deal with this issue? It can be the difference between 120,000 lines of code and 40,000 lines of code.


By not caring.

I guess that if you want to trick your boss, then the former is recommended.


My boss doesn't look at code, and if he did, I doubt he'd be counting lines.

I often delete code. Does you really believe some boss might see me deleting code, and think of it as negative progress? How do you think programming progress is measured?

A more effective way to compare lines of code in a C like language is grep for semicolons.

But really, it doesn't matter, it's a very cude measure anyway.

This topic is closed to new replies.

Advertisement