• Advertisement
Sign in to follow this  

Code lines number influenced by formatting style.

This topic is 1419 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by gasto

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.)

Edited by gasto

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

 

Why would you trick your boss?

Do you really think any of us get paid per line of code?

 

The simple answer is that it is a non issue.  The number of lines of code in a project doesn't really matter.  Somedays I delete more lines of code than I add to a project.

Share this post


Link to post
Share on other sites

I often delete code. Do[es] you really believe some boss might see me deleting code, and think of it as negative progress?

Yes. Sorry for applying stereotypes to managers, but they tend to have no clue of what is going on in the code(unless they are technical directors.), they also tend to be cynical, so it wouldn't surprise me that they complain for anything that one does. This includes breathing in a different rhythm than his.

 

 

 

How do you think programming progress is measured?

How do you think the intelligence of a person is measured?
By reading or listening to the arguments they create, and extracting the level of comprehension skills, among other tests.

Why do you assume that I have no idea how the application's programming progress is measured?
Perhaps you do not comprehend the semantic of the original post.

 

 

 

Why would you trick your boss?

Do you really think any of us get paid per line of code?

 

That's a straw-man argument.
It is implicit in the original post that perhaps it shouldn't be so(that lines of could should ever matter.)

You are opposing an argument that I never made, and if any(implicit) it was the opposite of what you report.

Edited by gasto

Share this post


Link to post
Share on other sites

It is implicit in the original post that perhaps it shouldn't be so(that lines of could should ever matter.)

 

No it isn't.

 


You are opposing an argument that I never made, and if any(implicit) it was the opposite of what you report.

 

I'm not opposing anything.  Those strange symbols at the end of my sentences are question marks.

Edited by Buster2000

Share this post


Link to post
Share on other sites

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.

 

There several programs available for counting lines of code and stripping comments is typically an option. E.g. see cloc. I don't know if brace style is taken into account, but as Frob said, any value gained from lines-of-code metrics tends to be from an order of magnitude point of view.

 

-Josh

Share this post


Link to post
Share on other sites

Just to mention: If one wants to use SLOCs as a measure for programmer activity (and I do not recommend so), then comments should IMHO be included. Comments are an important part, and commenting definitely costs time.

Share this post


Link to post
Share on other sites

Just to mention: If one wants to use SLOCs as a measure for programmer activity (and I do not recommend so), then comments should IMHO be included. Comments are an important part, and commenting definitely costs time.

Lines of code deleted per day should also be counted. Often, a negative LOC/day metric is more productive / adds more value than a positive one wink.png

Share this post


Link to post
Share on other sites

imo code-lines counting is quite usable (even more yet more strange 'metrics' (like code section length) are usable imo - I would even get this

line counting per day, built-in in my ide

Share this post


Link to post
Share on other sites

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.

Or write the most inefficient, crappy code imaginable. Unroll your for-loops, replace arrays with variables having actual numbers in their names, and obviously add "hacker protection code" to impress your boss - that's far more enterprisey.

 

You'll become the top programmer in no time.

 

(warning: post contains severe sarcasm)

Edited by TheComet

Share this post


Link to post
Share on other sites

If you want to measure your code more accurately, SourceMonitor is pretty cool. It measures the statements, and the average number of statements per function (to encourage keeping functions smaller), and the average number of nested scopes per function, the average number of functions per class, and other useful things.

 

This still doesn't measure the value of each line of code, so it is still a useless measurement for programmer work performance, but it does help measure function complexity (but not architectural complexity).

Share this post


Link to post
Share on other sites
Not only do most programmers not care about LOC, _smaller_ LOC is often considered better. _Not_ via formatting tricks or writing overly terse lines but because better programmers tend to not need to make 50 classes spread over 30 files to implement your common feature. I'd rather pay a guy who knows how to write 3 lines of Python to automate a task than someone who insists on using C++ to write a massively over-engineered behemoth of a program to do the same thing (with more bugs), for instance.

Most programmers don't care about LOC, period. In the game industry especially, we don't tend to have pointy-haired middle managers that look at irrelevant metrics like LOC (though sometimes we have pointy-haired managers looking at _other_ irrelevant metrics, like number of bugs closed). My experiences have been that most of the people managing engineers in the gaming industry are either highly technically-knowledgeable leads (who know better than to measure LOC) or producers (who couldn't give a rats ass about the code beyond whether it does what it needs to or not).

So far as programmers playing tricks to change LOC, I'd reprimand any programmer wasting company time (and hence money) on actively degrading the quality of the code. Consistency matters 10x more than almost anything else in large projects; follow the official project style, even if you feel it's a non-optimal one. If the company doesn't have any standards, start advocating that it adopts some. Checkins with most SCMs can even be set up with certain tools to warn (or even outright fail) on code that doesn't follow standards.

Share this post


Link to post
Share on other sites


replace arrays with variables having actual numbers in their names

 

Array length known only at runtime? Only one reasonable solution - self-modifying code, and invoking undefined behaviour by assuming the variables are placed contiguously on the stack. Actually, scratch that - lookup is achieved by a sufficiently large switch.. no, that's too readable.. a long list of if/else conditions.. no.. you know what, let's just precompute the program's output for every possible input and just hardcode that. It was throwaway code anyway.

Share this post


Link to post
Share on other sites
LOC isn't a totally useless metric. It can be used a a proxy for how long it would take to find a bug, and the over all complexity of a project. It's just important to remember that it's not an accurate measure. But sometimes, that's ok.

Share this post


Link to post
Share on other sites


Maximum productivity according to LOC goes to this man!

 

Uncountably many lines, for almost all programs cool.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement