Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Source lines of code (SLOC) -- meaningful number?

by kaif (Friar)
on Jun 08, 2005 at 14:21 UTC ( #464710=perlmeditation: print w/replies, xml ) Need Help??

Many of you have probably heard of SLOCCount, a tool used to count the number of source lines of code (SLOC) in a programming project. In addition, it translates this number to "the cost of development by conventional proprietary means," which I sometimes use to motivate me (I have never been paid explicitly to code). You may have even seen some popular measurements:

  • Redhat 7.1 in June 2001: 30 million SLOC and $1.08 billion
  • Debian 2.2 in October 2001: 55 million SLOC and $1.6 billion
  • Mozilla in October 2001: 2 million SLOC and $190 million or so
  • CPAN in July 2004: 15.4 million SLOC and $667 million
  • Linux 2.6 (kernel only) in October 2004: 4.2 million SLOC and somewhere between $176 to 612 million

How big is your largest personal project in SLOC? And what, to you, does SLOC mean? Is it, like XP, just a number? Is it possible to compare the numbers of CPAN and those for, say, Mozilla? I would also appreciate any comments from people actually in industry: have you or your managers ever used SLOCCount? Does it do a good job? Is it at least an appropriate tool for comparing project size (or does "compile time" work equally well)? Thanks in advance.

  • Comment on Source lines of code (SLOC) -- meaningful number?

Replies are listed 'Best First'.
Re: Source lines of code (SLOC) -- meaningful number?
by dbwiz (Curate) on Jun 08, 2005 at 14:31 UTC

      Wow, that is a pretty long discussion. I was a good monk and searched the archives before I posted, but I searched for "SLOC" and not "LOC'. Oops. Thanks.

Re: Source lines of code (SLOC) -- meaningful number?
by BrowserUk (Pope) on Jun 08, 2005 at 15:41 UTC

    See Cyclomatic Complexity of Perl code for another related thread.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Source lines of code (SLOC) -- meaningful number?
by hv (Parson) on Jun 08, 2005 at 16:09 UTC

    The largest application I've written was around 200 KLOC, but that was in 6800-assembler, one instruction per line. My current work application suite consists of around 34K lines of perl code, and is much more complex.

    I'd say LOC can be mildly useful as a very approximate measure of the complexity of an application, but that it is very dependent on the language and on an individual programmer's style.

    As a measure of productivity I'd rate it completely useless - my most productive days are the ones where I reduce the number of lines, while retaining or improving the functionality.


      Many SLOC "propaganda" resources claim that it doesn't matter what language you write in, the same amount of lines takes approximately the same amount of time. Having written large applications in both assembler and Perl, do you think this is true?


        First pass at the code tends to take time according to the number of function points. A line of perl code that I fully understand before I write it takes the same amount of time to think about as the 30 to 40 lines of assembler code it is equivalent to, with which I'm equally familiar. Typing the assembler code takes a bit longer, but they're pretty short lines and keyboard-memory takes over, so back when I was writing the assembler it would probably take me only 5 times as long to write the 30-40 lines of code as it does now to write 1 line of perl code.

        Other features can also have a massive effect - when I started writing that assembler application, the assembler itself was hardwired to print out a full listing and concordance, and for the application I was dealing with that took about 7 hours. Since at that point we were just starting to get hold of hard disks, modifying the assembler to spool the listing to disk reduced the turnaround to around 5 minutes, which had a massive effect on how you could go about writing and debugging programs.

        Similarly, how long it takes to find and fix a bug is in my experience much less dependent on LOC or language, and much more on the problem domain and the tools and techniques available - only the passage of time allows me to look back without shuddering at a stack corruption bug I once had in a keyboard interrupt handler, which took over a month of full time work to resolve.


Re: Source lines of code (SLOC) -- meaningful number?
by TedPride (Priest) on Jun 08, 2005 at 18:16 UTC
    A line of code in Perl is much more powerful than a line of code in any other language I know. Since it's more powerful, it also generally takes a little longer to write, and not as many total lines of code are needed.

    Short version - SLOC is pointless when comparing Perl to other programming languages. SLOC is probably not even that useful when comparing Perl code written by different programmers.

      See my reply to hv above: by your argument, you write less lines in Perl, but each one takes longer. Does that mean that the total line taken per line if the same?

Re: Source lines of code (SLOC) -- meaningful number?
by rinceWind (Monsignor) on Jun 09, 2005 at 09:20 UTC

    See my node Yet another code counter for something that will count lines and handle comments. It also produces a count of 'tokens'.


    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

Re: Source lines of code (SLOC) -- meaningful number?
by wazoox (Prior) on Jun 09, 2005 at 11:14 UTC
    I actually monitor the SLOC count of my various projects, and I find it a good enough tool to approximate the job done. Keep in mind SLOCcount suppose the analysed code to be complete and debugged; it usually isn't that bad as an evaluation (but it can't check for large copy-and-paste in different files).
Re: Source lines of code (SLOC) -- meaningful number?
by samtregar (Abbot) on Jun 09, 2005 at 17:43 UTC

      Out of curiosity, why the large difference between "Perl Modules Lines" and "Perl Module SLOC"? Is the difference because of POD and heredocs?

        POD, whitespace and comments. RTFM for more details.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://464710]
Approved by dbwiz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2020-11-29 13:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found