Source lines of code: Difference between revisions

Content deleted Content added
m Usage of SLOC measures: citation provided
Link suggestions feature: 2 links added.
 
(58 intermediate revisions by 43 users not shown)
Line 1:
{{short description|Software metric used to measure the size of a computer program}}
{{Multiple issues|
{{lead too short|date=April 2012}}
{{RefimproveMore citations needed|date=February 2010}}
{{Example farm|date=May 2012}}
}}
Line 8 ⟶ 9:
 
==Measurement methods==
ManyMultiple useful comparisons involve only the [[order of magnitude]] of lines of code in a project. Using lines of code to compare a 10,000-line project to a 100,000-line project is far more useful than when comparing a 20,000-line project with a 21,000-line project. While it is debatable exactly how to measure lines of code, discrepancies of an order of magnitude can be clear indicators of software complexity or [[man-hour]]s.
 
There are two major types of SLOC measures: physical SLOC (LOC) and logical SLOC (LLOC). Specific definitions of these two measures vary, but the most common definition of physical SLOC is a count of lines in the text of the program's source code excluding comment lines.<ref>{{citation |url=http://sunset.usc.edu/csse/TECHRPTS/2007/usc-csse-2007-737/usc-csse-2007-737.pdf |title=A SLOC Counting Standard |author1=Vu Nguyen |author2=Sophia Deeds-Rubin |author3=Thomas Tan |author4=Barry Boehm |publisher=Center for Systems and Software Engineering, University of Southern California |year=2007 }}</ref>
 
Logical SLOC attempts to measure the number of executable "statements", but their specific definitions are tied to specific computer languages (one simple logical SLOC measure for [[C (programming language)|C]]-like [[programming language]]s is the number of statement-terminating semicolons). It is much easier to create tools that measure physical SLOC, and physical SLOC definitions are easier to explain. However, physical SLOC measures are more sensitive to logically irrelevant formatting and style conventions, whilethan logical SLOC is less sensitive to formatting and style conventions. However, SLOC measures are often stated without giving their definition, and logical SLOC can often be significantly different from physical SLOC.
 
Consider this snippet of C code as an example of the ambiguity encountered when determining SLOC:
<sourcesyntaxhighlight lang="c">
for (i = 0; i < 100; i++) printf("hello"); /* How many lines of code is this? */
</syntaxhighlight>
</source>
 
In this example we have:
Line 24 ⟶ 25:
* 1 comment line.
 
Depending on the programmer and coding standards, the above "line" of code" could be written on manymultiple separate lines:
<sourcesyntaxhighlight lang="c">
/* Now how many lines of code is this? */
for (i = 0; i < 100; i++)
Line 31 ⟶ 32:
printf("hello");
}
</syntaxhighlight>
</source>
 
In this example we have:
Line 41 ⟶ 42:
 
==Origins==
At the time thatwhen peopleSLOC beganwas using SLOCintroduced as a metric, the most commonly used languages, such as [[FORTRAN]] and [[assembly language]], were line-oriented languages. These languages were developed at the time when [[punched cards]] were the main form of data entry for programming. One punched card usually represented one line of code. It was one discrete object that was easily counted. It was the visible output of the programmer, so it made sense to managers to count lines of code as a measurement of a programmer's productivity, even referring to such as "[[card image]]s". Today, the most commonly used computer languages allow a lot more leeway for formatting. Text lines are no longer limited to 80 or 96 columns, and one line of text no longer necessarily corresponds to one line of code.
 
==Usage of SLOC measures==
{{weasel words|date=September 2013}}
SLOC measures are somewhat controversial, particularly in the way that they are sometimes misused. Experiments have repeatedly confirmed that effort is highly correlated with SLOC{{Citation needed|date=July 2009}}, that is, programs with larger SLOC values take more time to develop. Thus, SLOC can be effective in estimating effort. However, functionality is less well correlated with SLOC: skilled developers may be able to develop the same functionality with far less code, so one program with fewer SLOC may exhibit more functionality than another similar program. Counting SLOC as productivity measure has its caveats, since a developer can develop only a few lines and yet be far more productive in terms of functionality than a developer who ends up creating more lines (and generally spending more effort). Good developers may merge multiple code modules into a single module, improving the system yet appearing to have negative productivity because they remove code. Also, especially skilled developers tend to be assigned the most difficult tasks, and thus may sometimes appear less "productive" than other developers on a task by this measure. Furthermore, inexperienced developers often resort to [[Duplicate code|code duplication]], which is highly discouraged as it is more bug-prone and costly to maintain, but it results in higher SLOC.
 
SLOC counting exhibits further accuracy issues at comparing programs written in different languages unless adjustment factors are applied to normalize languages. Various [[computer language]]s balance brevity and clarity in different ways; as an extreme example, most [[assembly language]]s would require hundreds of lines of code to perform the same task as a few characters in [[APL programming language|APL]]. The following example shows a comparison of a [[Hello world program|"hello world" program]] written in [[BASIC]], [[C (programming language)|C]], and the same program written in [[COBOL]] - (a language known for being particularly verbose).
 
{| class="wikitable" style="margin: 1em auto 1em auto"
|-
! BASIC || C || COBOL
|-
|
<sourcesyntaxhighlight lang="cBASIC">
 
 
# include <stdio.h>
 
PRINT "hello, world"
 
 
 
</syntaxhighlight>
||
<syntaxhighlight lang="c">
 
# include <stdio.h>
 
int main() {
printf("\nHellohello, world\n");
}
 
</syntaxhighlight>
</source>
||
<sourcesyntaxhighlight lang="textcobol">
identification division.
program-id. hello .
procedure division.
display "hello, world"
goback .
end program hello .
</syntaxhighlight>
</source>
|-
|Lines of code: 1<br />(no whitespace)||Lines of code: 4<br />(excluding whitespace) || Lines of code: 6<br />(excluding whitespace)
|}
 
Another increasingly common problem in comparing SLOC metrics is the difference between auto-generated and hand-written code. Modern software tools often have the capability to auto-generate enormous amounts of code with a few clicks of a mouse. For instance, [[graphical user interface builder]]s automatically generate all the source code for a [[Graphical control element (software)|graphical control elements]] simply by dragging an icon onto a workspace. The work involved in creating this code cannot reasonably be compared to the work necessary to write a [[device driver]], for instance. By the same token, a hand-coded custom GUI class could easily be more demanding than a simple device driver; hence the shortcoming of this metric.
 
There are several cost, schedule, and effort estimation models which use SLOC as an input parameter, including the widely used Constructive Cost Model ([[COCOMO]]) series of models by [[Barry Boehm]] et al., [[PRICE Systems]] [[True S]] and Galorath's [[SEER-SEM]]. While these models have shown good predictive power, they are only as good as the estimates (particularly the SLOC estimates) fed to them. Many<ref>IFPUG [http://www.qpmg.com/pdf/articles/Quantifying_the_Benefits_Using_Function_Points.pdf "Quantifying the Benefits of Using Function Points"]</ref> have advocated the use of [[function point]]s instead of SLOC as a measure of functionality, but since function points are highly correlated to SLOC (and cannot be automatically measured) this is not a universally held view.
Line 92 ⟶ 103:
|publisher=Knowing.NET
|date=December 6, 2005
|accessdateaccess-date=2010-08-30
|format=<sup>[https://scholar.google.co.uk/scholar?hl=en&lr=&q=intitle%3AHow+Many+Lines+of+Code+in+Windows%3F&as_publication=&as_ylo=&as_yhi=&btnG=Search Scholar search]</sup>
}}<br />This in turn cites Vincent Maraia's ''The Build Master'' as the source of the information.</ref>
|-
Line 104 ⟶ 115:
| 2001 || Windows XP || 45<ref>{{cite web
|url=https://www.facebook.com/windows/posts/155741344475532
|archive-url=https://ghostarchive.org/iarchive/facebook/30968512668/155741344475532 |archive-date=2022-02-26 |url-access=limited|title=How Many Lines of Code in Windows XP?
|publisher=Microsoft
|date=January 11, 2011
}}{{cbignore}}</ref><ref>{{Cite web|date=2012-09-21|title=A history of Windows - Microsoft Windows|url=http://windows.microsoft.com/en-AU/windows/history#T1=era6|access-date=2021-03-26|archive-url=https://web.archive.org/web/20120921002229/http://windows.microsoft.com/en-AU/windows/history#T1=era6|archive-date=2012-09-21}}</ref>
}}</ref><ref>{{cite web
|url=http://windows.microsoft.com/en-AU/windows/history#T1=era6
|title=A history of Windows
|publisher=Microsoft
}}</ref>
|-
| 2003 || Windows Server 2003 || 50<ref name = "Knowing.NET"/>
|}
 
David A. Wheeler studied the [[Red Hat]] distribution of the [[Linux|Linux operating system]], and reported that [[Red Hat Linux]] version 7.1<ref name = "Wheeler-RH7.1">{{cite web |date=2001-06-30 |url=http://www.dwheeler.com/sloc/redhat71-v1/redhat71sloc.html |author=David A. Wheeler |title=More Than a Gigabuck: Estimating GNU/Linux's Size }}</ref> (released April 2001) contained over 30 million physical SLOC. He also extrapolated that, had it been developed by conventional proprietary means, it would have required about 8,000 person-years of development effort and would have cost over $1 billion (in year 2000 U.S. dollars).
 
A similar study was later made of [[Debian GNU/Linux]] version 2.2 (also known as "Potato"); this operating system was originally released in August 2000. This study found that Debian GNU/Linux 2.2 included over 55 million SLOC, and if developed in a conventional proprietary way would have required 14,005 person-years and cost 1.9 billion USD to develop. Later runs of the tools used report that the following release of Debian had 104 million SLOC, and {{As of|2005|alt=as of year 2005}}, the newest release is going to include over 213 million SLOC.
 
A similar study was later made of [[Debian GNU/Linux]] version 2.2 (also known as "Potato"); this operating system was originally released in August 2000. This study found that Debian GNU/Linux 2.2 included over 55 million SLOC, and if developed in a conventional proprietary way would have required 14,005 person-years and cost US$1.9 billion USD to develop. Later runs of the tools used report that the following release of Debian had 104 million SLOC, and {{As of|2005|alt=as of year 2005}}, the newest release is going to include over 213 million SLOC.
 
{| class="wikitable" summary="Operating Systems SLOC Sizes"
Line 125 ⟶ 131:
! Year || Operating system || SLOC (million)
|-
| 2000 || Debian 2.2 || 55–59<ref>{{cite web | author = González-Barahona, Jesús M., |author2=Miguel A. Ortuño Pérez, |author3=Pedro de las Heras Quirós, |author4=José Centeno González, and |author5=Vicente Matellán Olivera | title = Counting potatoes: the size of Debian 2.2 | url = http://people.debian.org/~jgb/debian-counting/counting-potatoes/ | work = debian.org | accessdateaccess-date = 2003-08-12 |archiveurlarchive-url = https://web.archive.org/web/20080503001817/http://people.debian.org/~jgb/debian-counting/counting-potatoes/ |archivedatearchive-date = 2008-05-03}}</ref><ref name="debian-sloc">{{cite web | last = Robles | first = Gregorio | title = Debian Counting | url = http://debian-counting.libresoft.es/ | accessdateaccess-date = 2007-02-16 | deadurlurl-status = yesdead | archiveurlarchive-url = https://web.archive.org/web/20130314230249/http://debian-counting.libresoft.es/ | archivedatearchive-date = 2013-03-14 | df = }}</ref>
|-
| 2002 || Debian 3.0 || 104<ref name="debian-sloc"/>
Line 135 ⟶ 141:
| 2009 || Debian 5.0 || 324<ref name="debian-sloc"/>
|-
| 2012 || Debian 7.0 || 419<ref>Debian 7.0 was released in May 2013. The number is an estimate published on 2012-02-13, using the code base which would become Debian 7.0, using the same software method as for the data published by David A. Wheeler. {{cite web|author=James Bromberger |title=Debian Wheezy: US$19 Billion. Your price…price... FREE! |url=http://blog.james.rcpt.to/2012/02/13/debian-wheezy-us19-billion-your-price-free/ |work= |accessdateaccess-date=2014-02-07 |deadurlurl-status=yesdead |archiveurlarchive-url=https://web.archive.org/web/20140223013701/http://blog.james.rcpt.to/2012/02/13/debian-wheezy-us19-billion-your-price-free/ |archivedatearchive-date=2014-02-23 |df= }}</ref>
|-
| 2009 || [[Opensolaris|OpenSolaris]] || 9.7
Line 141 ⟶ 147:
| || [[FreeBSD]] || 8.8
|-
| 2005 || [[Mac OS X]] 10.4 || 86<ref>{{cite web | last = Jobs | first = Steve | title = Live from WWDC 2006: Steve Jobs Keynote | url = https://www.engadget.com/2006/08/07/live-from-wwdc-2006-steve-jobs-keynote/ |date=August 2006 | accessdateaccess-date = 2007-02-16 | quote = 86 million lines of source code that was ported to run on an entirely new architecture with zero hiccups.}}</ref><ref group="n">Possibly including the whole iLife suite, not just the operating system and usually bundled applications.</ref>
|-
| 1991 || [[Linux (kernel)|Linux kernel]] 0.01 || 0.010239
|-
| 2001 || [[Linux (kernel)|Linux kernel]] 2.4.2 || 2.4<ref name = "Wheeler-RH7.1"/>
|-
| 2003 || [[Linux (kernel)|Linux kernel]] 2.6.0 || 5.2
|-
| 2009 || [[Linux (kernel)|Linux kernel]] 2.6.29 || 11.0
|-
| 2009 || [[Linux (kernel)|Linux kernel]] 2.6.32 || 12.6<ref>{{cite web|url=http://www.h-online.com/open/features/What-s-new-in-Linux-2-6-32-872271.html?view=print |title=What's new in Linux 2.6.32 |accessdateaccess-date=2009-12-24 |deadurl=bot: unknown |archiveurlarchive-url=https://web.archive.org/web/20131219054613/http://www.h-online.com/open/features/What-s-new-in-Linux-2-6-32-872271.html?view=print |archivedatearchive-date=2013-12-19 |dfurl-status=live |date=2009-12-03 |author=Thorsten Leemhuis}}</ref>
|-
| 2010 || [[Linux (kernel)|Linux kernel]] 2.6.35 || 13.5<ref>{{cite web| url=http://go.linuxfoundation.org/who-writes-linux-2012 | title=Linux Kernel Development: How Fast it is Going, Who is Doing It, What They are Doing, and Who is Sponsoring It | date = April 2012 |author1=Greg Kroah-Hartman |author2=Jonathan Corbet |author3=Amanda McPherson | publisher=[[The Linux Foundation]] | accessdateaccess-date=2012-04-10}}</ref>
|-
| 2012 || [[Linux (kernel)|Linux kernel]] 3.6 || 15.9<ref>{{cite web|url=http://www.h-online.com/open/features/What-s-new-in-Linux-3-6-1714690.html?page%3Fpage=3 |title=Summary, Outlook, Statistics - The H Open: News and Features |accessdate=2012archive-10-08 |deadurl=bot: unknown |archiveurlurl=https://web.archive.org/web/20131219054847/http://www.h-online.com/open/features/What-s-new-in-Linux-3-6-1714690.html?page=3 |archivedatearchive-date=2013-12-19 |dfurl-status=live }}. Retrieved on 2014|date=2012-0510-13.01 |author=Thorsten Leemhuis}}</ref>
|-
| 2015-06-30 || [[Linux (kernel)|Linux kernel]] pre-4.2 || 20.2<ref>{{cite web | url=http://heise.de/-2730780 | title=Linux-Kernel durchbricht die 20-Millionen-Zeilen-Marke | date=30 June 2015 }}</ref>
|}
 
Line 166 ⟶ 172:
# Scope for automation of counting: since line of code is a physical entity, manual counting effort can be easily eliminated by automating the counting process. Small utilities may be developed for counting the LOC in a program. However, a logical code counting utility developed for a specific language cannot be used for other languages due to the syntactical and structural differences among languages. Physical LOC counters, however, have been produced which count dozens of languages.
# An intuitive metric: line of code serves as an intuitive metric for measuring the size of software because it can be seen, and the effect of it can be visualized. [[Function points]] are said to be more of an objective metric which cannot be imagined as being a physical entity, it exists only in the logical space. This way, LOC comes in handy to express the size of software among programmers with low levels of experience.
# Ubiquitous measure: LOC measures have been around since the earliest days of software.{{citation<ref>IFPUG needed|date=November[https://www.ifpug.org/content/documents/Jones-LinesofCodeMetricV6.pdf 2014}}"a short history of lines of code (loc) metrics"]</ref> As such, it is arguable that more LOC data is available than any other size measure.
 
=== Disadvantages ===
Line 172 ⟶ 178:
# Lack of cohesion with functionality: though experiments {{By whom|date=April 2010}} have repeatedly confirmed that while effort is highly correlated with LOC, functionality is less well correlated with LOC. That is, skilled developers may be able to develop the same functionality with far less code, so one program with less LOC may exhibit more functionality than another similar program. In particular, LOC is a poor productivity measure of individuals, because a developer who develops only a few lines may still be more productive than a developer creating more lines of code – even more: some good refactoring like "extract method" to get rid of [[redundant code]] and keep it clean will mostly reduce the lines of code.
# Adverse impact on estimation: because of the fact presented under point #1, estimates based on lines of code can adversely go wrong, in all possibility.
# Developer’sDeveloper's experience: implementation of a specific logic differs based on the level of experience of the developer. Hence, number of lines of code differs from person to person. An experienced developer may implement certain functionality in fewer lines of code than another developer of relatively less experience does, though they use the same language.
# Difference in languages: consider two applications that provide the same functionality (screens, reports, databases). One of the applications is written in C++ and the other application written in a language like COBOL. The number of function points would be exactly the same, but aspects of the application would be different. The lines of code needed to develop the application would certainly not be the same. As a consequence, the amount of effort required to develop the application would be different (hours per function point). Unlike lines of code, the number of function points will remain constant.
# Advent of [[Graphical user interface|GUI]] tools: with the advent of GUI-based programming languages and tools such as [[Visual Basic (classic)|Visual Basic]], programmers can write relatively little code and achieve high levels of functionality. For example, instead of writing a program to create a window and draw a button, a user with a GUI tool can use drag-and-drop and other mouse operations to place components on a workspace. Code that is automatically generated by a GUI tool is not usually taken into consideration when using LOC methods of measurement. This results in variation between languages; the same task that can be done in a single line of code (or no code at all) in one language may require several lines of code in another.
# Problems with multiple languages: in today’stoday's software scenario, software is often developed in more than one language. Very often, a number of languages are employed depending on the complexity and requirements. Tracking and reporting of productivity and defect rates poses a serious problem in this case, since defects cannot be attributed to a particular language subsequent to integration of the system. Function point stands out to be the best measure of size in this case.
# Lack of counting standards: there is no standard definition of what a line of code is. Do comments count? Are data declarations included? What happens if a statement extends over several lines? – These are the questions that often arise. Though organizations like SEI and IEEE have published some guidelines in an attempt to standardize counting, it is difficult to put these into practice especially in the face of newer and newer languages being introduced every year.
# Psychology: a programmer whose productivity is being measured in lines of code will have an incentive to write unnecessarily verbose code. The more management is focusing on lines of code, the more incentive the programmer has to expand histheir code with unneeded complexity. This is undesirable, since increased complexity can lead to increased cost of maintenance and increased effort required for bug fixing.
 
In the [[PBS]] documentary ''[[Triumph of the Nerds]]'', Microsoft executive [[Steve Ballmer]] criticized the use of counting lines of code:
Line 183 ⟶ 189:
In IBM there's a religion in software that says you have to count K-LOCs, and a K-LOC is a thousand lines of code. How big a project is it? Oh, it's sort of a 10K-LOC project. This is a 20K-LOCer. And this is 50K-LOCs. And IBM wanted to sort of make it the religion about how we got paid. How much money we made off [[OS/2]], how much they did. How many K-LOCs did you do? And we kept trying to convince them – hey, if we have – a developer's got a good idea and he can get something done in 4K-LOCs instead of 20K-LOCs, should we make less money? Because he's made something smaller and faster, less K-LOC. K-LOCs, K-LOCs, that's the methodology. Ugh! Anyway, that always makes my back just crinkle up at the thought of the whole thing.
</blockquote>
According to the [[Computer History Museum]] Apple Developer [[Bill Atkinson]] in 1982 found problems with this practice:
 
<blockquote>
== Related terms ==
When the Lisa team was pushing to finalize their software in 1982, project managers started requiring programmers to submit weekly forms reporting on the number of lines of code they had written. Bill Atkinson thought that was silly. For the week in which he had rewritten QuickDraw’s region calculation routines to be six times faster and 2000 lines shorter, he put “-2000″ on the form. After a few more weeks the managers stopped asking him to fill out the form, and he gladly complied.<ref>{{Cite web|date=2010-07-18|title=MacPaint and QuickDraw Source Code|url=https://computerhistory.org/blog/macpaint-and-quickdraw-source-code/|access-date=2021-04-15|website=CHM|language=en}}</ref><ref>{{Cite web|title=Folklore.org: -2000 Lines Of Code|url=https://www.folklore.org/StoryView.py?story=Negative_2000_Lines_Of_Code.txt|access-date=2021-04-15|website=www.folklore.org}}</ref>
* KLOC {{IPAc-en|ˈ|k|eɪ|l|ɒ|k}} {{respell|KAY|lok}}: 1,000 lines of code
</blockquote>
** KDLOC: 1,000 delivered lines of code
** KSLOC: 1,000 source lines of code
* MLOC: 1,000,000 lines of code
* GLOC: 1,000,000,000 lines of code
 
==See also==
* [[Software development effort estimation]]
* [[Estimation (project management)]]
* [[Cost estimation in software engineering]]
 
==Notes==
Line 214 ⟶ 218:
|date=May 2005}}
* {{cite journal
|url=ftphttp://dimacs.rutgers.edu/pub/dimacs/TechnicalReports/TechReports/2003/2003-13.ps.gz
| last = McGraw
| first = Gary
Line 224 ⟶ 228:
| pages = 59–66
|doi=10.1109/MSECP.2003.1193213
| url-access = subscription
}}<!-- this is talking about a different type of metric -->
* {{cite journal
| author = Park, Robert E.| title = Software Size Measurement: A Framework for Counting Source Statements
| journal = Technical Report CMU/SEI-92-TR-20
| date = 31 August 1992
| url = http://www.sei.cmu.edu/library/abstracts/reports/92tr020.cfm |display-authors=etal}}
 
Line 237 ⟶ 243:
| title = SLOCCount
| url = http://www.dwheeler.com/sloccount
| accessdateaccess-date = 2003-08-12
}}
* {{cite web
Line 244 ⟶ 250:
|date=June 2001
| url = http://www.dwheeler.com/sloc
| accessdateaccess-date = 2003-08-12
}}
* Tanenbaum, Andrew S. ''Modern Operating Systems'' (2nd ed.). Prentice Hall. {{ISBN|0-13-092641-8}}.
Line 252 ⟶ 258:
|author = Howard Dahdah
|date = 2007-01-24
|accessdateaccess-date = 2007-01-29
|deadurlurl-status = yesdead
|archiveurlarchive-url = https://web.archive.org/web/20070127074508/http://www.computerworld.com.au/index.php/id%3B1942598204%3Bpp%3B1
|archivedatearchive-date = 2007-01-27
|df =
}}
* [http{{cite web |url=https://www.maultech.com/chrislott/resources/cmetrics/ |author=C. M. Lott: |title=Metrics collection tools for C and C++ Source Code] |archive-url=https://web.archive.org/web/20200619034717/https://www.maultech.com/chrislott/resources/cmetrics/ |archive-date=June 19, 2020}}
* [http://folklore.org/StoryView.py?project=Macintosh&story=Negative_2000_Lines_Of_Code.txt&detail=medium/ Folklore.org: Macintosh Stories: -2000 Lines Of Code]