"Line Of Code" How do you define what one is?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 6694 Views - Last Post: 21 November 2012 - 12:54 PM

#16 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: "Line Of Code" How do you define what one is?

Posted 17 November 2012 - 07:25 PM

I guess you could.
Was This Post Helpful? 0
  • +
  • -

#17 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: "Line Of Code" How do you define what one is?

Posted 17 November 2012 - 07:47 PM

Separating them out in to there own functions.
Attached Image
Code Metric Viewer see it as 4 lines!? What are the lines?

If we look at a AST / LISP / Scheme like view its more like.
 (Where (numbers) (Lambda (x) (IF (= (% x 2) 0) (true) (false)))


Or as MSIL its a lot more.
Spoiler


So the relationship between Editors Lines, Logical Lines and Executable Lines and what the Debugger sees is complex to say the least.
Was This Post Helpful? 0
  • +
  • -

#18 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: "Line Of Code" How do you define what one is?

Posted 17 November 2012 - 08:31 PM

The 4 lines it sees (i think from the IL) is
 return 
   from x in Program.numbers()
     where x % 2 == 1
     select x;


Why the LINQ Query style? and not the extension method approach?
also notice its not the code I actually wrote.
Was This Post Helpful? 0
  • +
  • -

#19 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,710
  • Joined: 03-August 09

Re: "Line Of Code" How do you define what one is?

Posted 17 November 2012 - 10:35 PM

It seems to me that a line is a straight editor line. breakpoints are being associated with other constructs (looks like statements but not 100% sure; statements make the most sense) that happen to reside on a set of lines. In C, C++, and almost every-other language I've used lines have no meaning in the language other than white space; you could replace all new-lines with spaces and the program would function exactly the same, probably even compile to the same executable.

here is my exact definition:
a line in text ends with a new line character and or a carriage return as displayed by the text editor in question.

I don't see why it isn't just that simple.
Was This Post Helpful? 0
  • +
  • -

#20 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8002
  • View blog
  • Posts: 13,712
  • Joined: 19-March 11

Re: "Line Of Code" How do you define what one is?

Posted 17 November 2012 - 10:49 PM

View Postishkabible, on 18 November 2012 - 12:35 AM, said:

I don't see why it isn't just that simple.


It's totally arbitrary - "a line of code" is exactly what you define it to be - so it's exactly as simple or as complex as you want it to be.
If you specify the purpose you're trying to serve, that is, what sense you're trying to capture, then you can talk about what definition makes sense for that purpose, but until you do that, it's just empty noise.
Was This Post Helpful? 0
  • +
  • -

#21 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 12:22 AM

View Postishkabible, on 18 November 2012 - 06:35 AM, said:

here is my exact definition:
a line in text ends with a new line character and or a carriage return as displayed by the text editor in question.


Here a couple of examples where isn't that simple.

  • I refer you make to my 43 IDE line C# example.
  • XML Literals in vb.net follow the grammar rules of XML, thus has significant whitespace. So replacing newlines with spaces would change the meaning of the code.
    Same for
  • VB.net's Implicit Line-Continuations
  • Verbatim String Literals in Nemerle
    def s10 = @"""Nemerle""                 // comment
    rocks
    !";
    
    

    If you which is three lines of text, so if replace the newlines with spaces. It would highly not compile since the final " would inside the comments.
    "Nemerle"
    rocks
    !
    
    


What about language called Piet?

This post has been edited by AdamSpeight2008: 18 November 2012 - 12:35 AM

Was This Post Helpful? 0
  • +
  • -

#22 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,313
  • Joined: 21-June 11

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 12:42 AM

View PostAdamSpeight2008, on 18 November 2012 - 08:22 AM, said:

Here a couple of examples where isn't that simple.


Yes, it is that simple. It seems to me that you're basically saying "The term 'lines of code' can't refer to actual lines because then it would be a completely meaningless measure of any interesting property of the code". But that's not a contradiction. It is a completely meaningless measure of any interesting property of the code.

Quote

What about language called Piet?


Clearly talking about lines of code in a Piet program is even more meaningless than it is for regular programs.
Was This Post Helpful? 1
  • +
  • -

#23 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 12:53 AM

sepp2k You've taken my reply out of context, it was in reply to if reference to ishkabible definition.

Is a commented out "line of code" a "line of code"?

Isthere a universal definition of "line of code" that apply to all programming languages?

This post has been edited by AdamSpeight2008: 18 November 2012 - 12:58 AM

Was This Post Helpful? 0
  • +
  • -

#24 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8002
  • View blog
  • Posts: 13,712
  • Joined: 19-March 11

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 12:58 AM

Quote

Is a commented out "line of code" a "line of code"?

None, because ice cream has no bones.

This post has been edited by jon.kiparsky: 18 November 2012 - 01:00 AM

Was This Post Helpful? 0
  • +
  • -

#25 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 01:12 AM

If it has no meaning then why is it then often used as metric?

"I inherieted 20K lines of spagethi code"
"My project has X lines of Code"
Linux written in 176,250 Lines of code.
Windows XP written in 40 million lines of code.

How many of those do actual work?
Does more or less lines indicates better coding?
What is the perfect ratio? non executing / executable lines
Was This Post Helpful? 0
  • +
  • -

#26 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,313
  • Joined: 21-June 11

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 01:25 AM

View PostAdamSpeight2008, on 18 November 2012 - 09:12 AM, said:

If it has no meaning then why is it then often used as metric?


Because it's easily measurable and people like numbers. It is a mistake to assume that because a lot of people talk about something, it must actually be meaningful.

Note that if we defined "lines of code" to mean anything other than actual lines, it would no longer be easily measurable. It stands to reason that when someone says "I inherieted 20K lines of spagethi code" he did not in fact count the "logical lines of execution" in the code (because that would have taken a while and no one's that bored), so he can only be talking about the actual lines in the file (which can be easily found out by running wc -l on the code base or using equivalent functionality of your text editor or IDE).

View PostAdamSpeight2008, on 18 November 2012 - 08:53 AM, said:

sepp2k [My reply] was in reply to if reference to ishkabible definition.


I know and I certainly didn't mean to imply anything to the contrary (and I don't think I did). When I said "it is that simple" I meant that ishkabible's definition is in fact a reasonable one.

This post has been edited by sepp2k: 18 November 2012 - 01:25 AM

Was This Post Helpful? 1
  • +
  • -

#27 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8002
  • View blog
  • Posts: 13,712
  • Joined: 19-March 11

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 01:35 AM

It is used as a "metric" by people who don't know what they're talking about - popular writers like to impress their readers with simpleminded figures of that sort - and by programmers who want to give a rough sense of the scope of a project. Clearly 20,000 lines of code is a lot of lines, and you're meant to feel sorry for the poor bastard. Here it means about the same thing as "a shit-ton of code".

Quote

Does more or less lines indicates better coding?


No. Assuming it meets requirements, code is good to the extent that it is clear and can be maintained by some programmer who has never met the original programmer but is reasonably familiar with the language. That's all. If this is achieved by adding lines, add lines. If it is achieved by removing lines, then lines must be removed.

Last week, I removed approximately 500 lines of gratuitous whitespace from a blob of PHP and javascript that's going to be deployed one day, prepatory to refactorings which will probably remove a similar number of lines. However, the important thing about this operation is that cleaning up the style so that the repeated lines would stand out, and can be extracted easily. The refactorings I'll be doing next week are about simplifiyng the code - since this will eliminate repetition, it will shorten it, but it's about simplicity, not concision.
If this had been written by someone else, and they'd rammed a bunch of chained functions together on one line to save vertical space, or otherwise compressed the code at the expense of the reader, the code would have gotten longer instead of shorter. Length is not interesting, unless it serves a purpose. A function should fit on one screen, as a rule, and it's better easier to move your eyes vertically down the screen than to run out to 200 character lines, and it's more often the case that increasing clarity means removing lines than the converse, but the goal is more clarity, not fewer lines.

Again: more clarity, not fewer lines.

Any other rule serves some purpose other than making good and durable code.
Was This Post Helpful? 2
  • +
  • -

#28 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: "Line Of Code" How do you define what one is?

Posted 18 November 2012 - 11:20 AM

SLOC
Was This Post Helpful? 0
  • +
  • -

#29 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: "Line Of Code" How do you define what one is?

Posted 20 November 2012 - 02:23 AM

Clarity how do you define and measure that?
Is there an equation that produce say a clarity score? Where a score of zero in the is no "clarity" Isn't that intangible and subject to whim and fancy?
Was This Post Helpful? 0
  • +
  • -

#30 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: "Line Of Code" How do you define what one is?

Posted 20 November 2012 - 04:32 AM

Clarity is certainly difficult to measure, yet we all recognise clear code when we see it. We certainly appreciate clarity when we have to maintain code! The converse is also true for unclear code.

Although it is difficult to measure, the book Clean Code provides a set of guidelines to help write clean code. It has helped me enormously.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3