Jump to content

  • Log In with Google      Sign In   
  • Create Account


Code lines number influenced by formatting style.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#1 gasto   Members   -  Reputation: 257

Like
0Likes
Like

Posted 02 March 2014 - 03:25 PM

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, 02 March 2014 - 03:26 PM.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

Sponsor:

#2 Nathan2222_old   Members   -  Reputation: -400

Like
-2Likes
Like

Posted 02 March 2014 - 03:41 PM

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
smile.png
--
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


#3 Brother Bob   Moderators   -  Reputation: 7774

Like
0Likes
Like

Posted 02 March 2014 - 03:42 PM

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.



#4 wack   Members   -  Reputation: 1223

Like
22Likes
Like

Posted 02 March 2014 - 03:43 PM


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.



#5 xbattlestation   Members   -  Reputation: 307

Like
5Likes
Like

Posted 02 March 2014 - 03:54 PM

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

#6 Hodgman   Moderators   -  Reputation: 27518

Like
12Likes
Like

Posted 02 March 2014 - 04:50 PM

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

#7 gasto   Members   -  Reputation: 257

Like
0Likes
Like

Posted 02 March 2014 - 05:31 PM

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, 02 March 2014 - 05:32 PM.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

#8 frob   Moderators   -  Reputation: 18831

Like
7Likes
Like

Posted 02 March 2014 - 06:06 PM

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.
Check out my personal indie blog at bryanwagstaff.com.

#9 Pink Horror   Members   -  Reputation: 1082

Like
1Likes
Like

Posted 02 March 2014 - 06:50 PM

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?

#10 King Mir   Members   -  Reputation: 1892

Like
0Likes
Like

Posted 02 March 2014 - 10:26 PM

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.



#11 Buster2000   Members   -  Reputation: 1415

Like
0Likes
Like

Posted 03 March 2014 - 07:34 AM


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.



#12 gasto   Members   -  Reputation: 257

Like
0Likes
Like

Posted 03 March 2014 - 07:50 AM


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, 03 March 2014 - 07:51 AM.

Intel Core 2 Quad CPU Q6600, 2.4 GHz. 3GB RAM. ATI Radeon HD 3400.

#13 Buster2000   Members   -  Reputation: 1415

Like
0Likes
Like

Posted 04 March 2014 - 02:39 AM


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, 04 March 2014 - 02:41 AM.


#14 jjd   Crossbones+   -  Reputation: 2066

Like
0Likes
Like

Posted 04 March 2014 - 03:37 AM

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


--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet


#15 haegarr   Crossbones+   -  Reputation: 3723

Like
2Likes
Like

Posted 04 March 2014 - 03:44 AM

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.



#16 Hodgman   Moderators   -  Reputation: 27518

Like
4Likes
Like

Posted 04 March 2014 - 04:18 AM

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



#17 fir   Members   -  Reputation: -444

Like
0Likes
Like

Posted 04 March 2014 - 05:43 AM

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



#18 TheComet   Members   -  Reputation: 1382

Like
2Likes
Like

Posted 04 March 2014 - 07:06 AM


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, 04 March 2014 - 07:58 AM.

YOUR_OPINION >/dev/null


#19 Servant of the Lord   Crossbones+   -  Reputation: 17046

Like
1Likes
Like

Posted 04 March 2014 - 12:23 PM

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


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

[Fly with me on Twitter] [Google+] [My broken website]

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#20 SeanMiddleditch   Members   -  Reputation: 3857

Like
2Likes
Like

Posted 05 March 2014 - 11:50 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS