Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Source code
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Human-readable instructions a computer can execute}} {{About|the software concept|the film|Source Code}}{{Use dmy dates|date=January 2016}} [[File:Hello world c.svg|thumb|Simple [[C (programming language)|C-language]] source code example, a [[procedural programming language]]. The resulting program prints "hello, world" on the computer screen. This first known "[["Hello, World!" program|Hello world]]" [[Snippet (programming)|snippet]] from the seminal book ''[[The C Programming Language]]'' originates from [[Brian Kernighan]] in the [[Bell Labs|Bell Laboratories]] in 1974.<ref name="ctutorial">{{cite web| url = http://cm.bell-labs.com/cm/cs/who/dmr/ctut.pdf| title = Programming in C: A Tutorial |first1=Brian W. |last1=Kernighan |publisher=Bell Laboratories, Murray Hill, N. J. | archive-url = https://web.archive.org/web/20150223025837/http://cm.bell-labs.com/cm/cs/who/dmr/ctut.pdf| archive-date = 23 February 2015| url-status = dead}}</ref><!-- See http://cm.bell-labs.com/cm/cs/who/dmr/ctut.pdf for original.-->]] {{Program execution}} In [[computing]], '''source code''', or simply '''code''' or '''source''', is a [[plain text]] [[computer program]] written in a [[programming language]]. A [[programmer]] writes the [[human readable]] source code to control the behavior of a [[computer]]. Since a computer, at base, only understands [[machine code]], source code must be [[Translator (computing)|translated]] before a computer can [[Execution (computing)|execute]] it. The translation process can be implemented three ways. Source code can be converted into machine code by a [[compiler]] or an [[assembler (computing)|assembler]]. The resulting [[executable]] is machine code ready for the computer. Alternatively, source code can be executed without conversion via an [[interpreter (computing)|interpreter]]. An interpreter loads the source code into memory. It simultaneously translates and executes each [[statement (computer science)|statement]]. A method that combines compilation and interpretation is to first produce [[bytecode]]. Bytecode is an intermediate representation of source code that is quickly interpreted. ==Background== The first programmable computers, which appeared at the end of the 1940s,{{sfn|Gabbrielli|Martini|2023|p=519}} were programmed in [[machine language]] (simple instructions that could be directly executed by the processor). Machine language was difficult to debug and was not [[portability (computing)|portable]] between different computer systems.{{sfn|Gabbrielli|Martini|2023|pp=520–521}} Initially, hardware resources were scarce and expensive, while [[human resources]] were cheaper.{{sfn|Gabbrielli|Martini|2023|p=522}} As programs grew more complex, [[programmer productivity]] became a bottleneck. This led to the introduction of [[high-level programming language]]s such as [[Fortran]] in the mid-1950s. These languages [[abstraction (computing)|abstracted]] away the details of the hardware, instead being designed to express algorithms that could be understood more easily by humans.{{sfn|Gabbrielli|Martini|2023|p=521}}{{sfn|Tracy|2021|p=1}} As instructions distinct from the underlying [[computer hardware]], software is therefore relatively recent, dating to these early high-level [[programming languages]] such as [[Fortran]], [[Lisp (programming language)|Lisp]], and [[Cobol]].{{sfn|Tracy|2021|p=1}} The invention of high-level programming languages was simultaneous with the [[compiler]]s needed to translate the source code automatically into machine code that can be directly executed on the [[computer hardware]].{{sfn|Tracy|2021|p=121}} Source code is the form of code that is modified directly by humans, typically in a high-level programming language. [[Object code]] can be directly executed by the machine and is generated automatically from the source code, often via an intermediate step, [[assembly language]]. While object code will only work on a specific platform, source code can be ported to a different machine and recompiled there. For the same source code, object code can vary significantly—not only based on the machine for which it is compiled, but also based on performance optimization from the compiler.{{sfn|Lin ''et al.''|2001|pp=238-239}}{{sfn|Katyal|2019|p=1194}} == Organization == {{main|Software configuration management}} Most programs do not contain all the resources needed to run them and rely on external [[software library|libraries]]. Part of the compiler's function is to link these files in such a way that the program can be executed by the hardware.{{sfn|Tracy|2021|pp=122-123}} [[Image:CodeCmmt002.svg|thumb|right|A more complex [[Java (programming language)|Java]] source code example. Written in [[object-oriented programming]] style, it demonstrates [[boilerplate code]]. With prologue comments indicated in red, inline comments indicated in green, and program statements indicated in blue.]] Software developers often use [[Software configuration management|configuration management]] to track changes to source code files ([[version control]]). The configuration management system also keeps track of which object code file corresponds to which version of the source code file.{{sfn|O'Regan|2022|pp=230-231, 233, 377}} == Purposes == ===Estimation=== The number of lines of source code is often used as a metric when evaluating the productivity of computer programmers, the economic value of a code base, [[software development effort estimation|effort estimation]] for projects in development, and the ongoing cost of [[software maintenance]] after release.{{sfn|Foster|2014|pp=249, 274, 280, 305}} ===Communication=== Source code is also used to communicate [[algorithm]]s between people {{endash}} e.g., [[code snippets]] online or in books.<ref name=Spinellis>Spinellis, D: ''Code Reading: The Open Source Perspective''. Addison-Wesley Professional, 2003. {{ISBN|0-201-79940-5}}</ref> [[Programmer|Computer programmers]] may find it helpful to review existing source code to learn about programming techniques.<ref name=Spinellis/> The sharing of source code between developers is frequently cited as a contributing factor to the maturation of their programming skills.<ref name=Spinellis/> Some people consider source code an expressive [[Media (arts)|artistic medium]].<ref>"''Art and Computer Programming''" [http://www.onlamp.com/pub/a/onlamp/2005/06/30/artofprog.html ONLamp.com] {{Webarchive|url=https://web.archive.org/web/20180220045508/http://www.onlamp.com/pub/a/onlamp/2005/06/30/artofprog.html |date=20 February 2018 }}, (2005)</ref> Source code often contains [[comment (programming)|comment]]s—blocks of text marked for the compiler to ignore. This content is not part of the program logic, but is instead intended to help readers understand the program.{{sfn|Kaczmarek ''et al.''|2018|p=68}} Companies often keep the source code confidential in order to hide algorithms considered a [[trade secret]]. Proprietary, secret source code and algorithms are widely used for sensitive government applications such as [[criminal justice]], which results in [[black box]] behavior with a lack of [[Transparency (behavior)|transparency]] into the algorithm's methodology. The result is avoidance of public scrutiny of issues such as bias.{{sfn|Katyal|2019|pp=1186–1187}} ===Modification=== {{see also|Software development|Software maintenance}} Access to the source code (not just the [[object code]]) is essential to modifying it.{{sfn|Katyal|2019|p=1195}} Understanding existing code is necessary to understand how it works{{sfn|Katyal|2019|p=1195}} and before modifying it.<ref name=Offutt>{{cite web |last1=Offutt |first1=Jeff |author1-link=Jeff Offutt |title=Overview of Software Maintenance and Evolution |url=https://cs.gmu.edu/~offutt/classes/437/maintessays/maintEvolutionOverview.html |website=[[George Mason University]] Department of Computer Science |access-date=5 May 2024 |date=January 2018}}</ref> The rate of understanding depends both on the code base as well as the skill of the programmer.{{sfn|Tripathy |Naik|2014|p=296}} Experienced programmers have an easier time understanding what the code does at a high level.{{sfn|Tripathy |Naik|2014|p=297}} [[Software visualization]] is sometimes used to speed up this process.{{sfn|Tripathy |Naik|2014|pp=318-319}} Many software programmers use an [[integrated development environment]] (IDE) to improve their productivity. IDEs typically have several features built in, including a [[source-code editor]] that can alert the programmer to common errors.{{sfn|O'Regan|2022|p=375}} Modification often includes [[code refactoring]] (improving the structure without changing functionality) and restructuring (improving structure and functionality at the same time).{{Sfn|Tripathy |Naik|2014|p=94}} Nearly every change to code will introduce new bugs or unexpected [[ripple effect]]s, which require another round of fixes.<ref name=Offutt/> [[Code review]]s by other developers are often used to scrutinize new code added to a project.{{sfn|Dooley|2017|p=272}} The purpose of this phase is often to verify that the code meets style and [[maintainability]] standards and that it is a correct implementation of the [[software design]].{{sfn|O'Regan|2022|pp=18, 21}} According to some estimates, code review dramatically reduce the number of bugs persisting after [[software testing]] is complete.{{sfn|Dooley|2017|p=272}} Along with software testing that works by executing the code, [[static program analysis]] uses automated tools to detect problems with the source code. Many IDEs support code analysis tools, which might provide metrics on the clarity and maintainability of the code.{{sfn|O'Regan|2022|p=133}} [[Debuggers]] are tools that often enable programmers to step through execution while keeping track of which source code corresponds to each change of state.{{sfn|Kaczmarek ''et al.''|2018|pp=348-349}} ===Compilation and execution=== Source code files in a high-level programming language must go through a stage of preprocessing into [[machine code]] before the instructions can be carried out.{{sfn|Tracy|2021|p=121}} After being compiled, the program can be saved as an [[object file]] and the [[Loader (computing)|loader]] (part of the operating system) can take this saved file and [[execution (computing)|execute]] it as a [[process]] on the computer hardware.{{sfn|Tracy|2021|pp=122-123}} Some programming languages use an [[Interpreter (computing)|interpreter]] instead of a compiler. An interpreter converts the program into machine code at [[execution (computing)|run time]], which makes them 10 to 100 times slower than compiled programming languages.{{sfn|O'Regan|2022|p=375}}{{sfn|Sebesta|2012|p=28}} ==Quality== {{main article|Software quality}} [[Software quality]] is an overarching term that can refer to a code's correct and efficient behavior, its reusability and [[porting|portability]], or the ease of modification.{{sfn|Galin|2018|p=26}} It is usually more cost-effective to build quality into the product from the beginning rather than try to add it later in the development process.{{sfn|O'Regan|2022|pp=68, 117}} Higher quality code will reduce lifetime cost to both suppliers and customers as it is more reliable and [[maintainability|easier to maintain]].{{sfn|O'Regan|2022|pp=3, 268}}{{sfn|Varga|2018|p=12}} Maintainability is the quality of software enabling it to be easily modified without breaking existing functionality.{{sfn|Varga|2018|p=5}} Following coding conventions such as using clear function and variable names that correspond to their purpose makes maintenance easier.{{sfn|Tripathy |Naik|2014|pp=296-297}} Use of [[conditional loop]] statements only if the code could execute more than once, and eliminating code that will never execute can also increase understandability.{{sfn|Tripathy |Naik|2014|p=309}} Many software development organizations neglect maintainability during the development phase, even though it will increase long-term costs.{{sfn|Varga|2018|p=12}} [[Technical debt]] is incurred when programmers, often out of laziness or urgency to meet a deadline, choose quick and dirty solutions rather than build maintainability into their code.{{sfn|Varga|2018|pp=6-7}} A common cause is underestimates in [[software development effort estimation]], leading to insufficient resources allocated to development.{{sfn|Varga|2018|p=7}} A challenge with maintainability is that many [[software engineering]] courses do not emphasize it.{{sfn|Varga|2018|pp=7-8}} Development engineers who know that they will not be responsible for maintaining the software do not have an incentive to build in maintainability.<ref name=Offutt/> == Copyright and licensing == {{main|Software copyright|Software license}} {{see also|History of free and open-source software}} The situation varies worldwide, but in the United States before 1974, software and its source code was not [[copyright]]able and therefore always [[public domain software]].<ref>{{Cite journal|last1=Liu |first1=Joseph P.|last2=Dogan |first2= Stacey L.|date=2005|title=Copyright Law and Subject Matter Specificity: The Case of Computer Software|url=https://lawdigitalcommons.bc.edu/lsfp/536/|journal=New York University Annual Survey of American Law|language=en|volume=61|issue=2 |url-status=dead |archive-url=https://web.archive.org/web/20210625073240/https://lawdigitalcommons.bc.edu/lsfp/536/ |archive-date=Jun 25, 2021}}</ref> In 1974, the US Commission on New Technological Uses of Copyrighted Works ([[CONTU]]) decided that "computer programs, to the extent that they embody an author's original creation, are proper subject matter of copyright".<ref>[http://digitalcommons.law.ggu.edu/cgi/viewcontent.cgi?article=1344&context=ggulrev Apple Computer, Inc. v. Franklin Computer Corporation Puts the Byte Back into Copyright Protection for Computer Programs] {{Webarchive|url=https://web.archive.org/web/20170507231059/http://digitalcommons.law.ggu.edu/cgi/viewcontent.cgi?article=1344&context=ggulrev |date=7 May 2017 }} in Golden Gate University Law Review Volume 14, Issue 2, Article 3 by Jan L. Nussbaum (January 1984)</ref><ref name="sail_book">Lemley, Menell, Merges and Samuelson. ''Software and Internet Law'', p. 34.</ref> [[Proprietary software]] is rarely distributed as source code.{{sfn|Boyle|2003|p=45}} Although the term [[open-source software]] literally refers to [[source-available software|public access to the source code]],{{sfn|Morin ''et al.''|2012|loc=Open Source versus Closed Source}} open-source software has additional requirements: free redistribution, permission to modify the source code and release derivative works under the same license, and nondiscrimination between different uses—including commercial use.{{sfn|Sen ''et al.''|2008|p=209}}{{sfn|Morin ''et al.''|2012|loc=Free and Open Source Software (FOSS) Licensing}} The free [[software reuse|reusability]] of open-source software can speed up development.{{sfn|O'Regan|2022|p=106}} == See also == * [[Bytecode]] * [[Code as data]] * [[Coding conventions]] * [[Free software]] * [[Legacy code]] * [[Machine code]] * [[Markup language]] * [[Obfuscated code]] * [[Object code]] * [[Open-source software]] * [[Package (package management system)]] * [[Programming language]] * [[Source code repository]] * [[Syntax highlighting]] * [[Visual programming language]] == References == {{reflist}} === Sources === {{refbegin|indent=yes}} *{{cite book |last1=Ablon |first1=Lillian |last2=Bogart |first2=Andy |title=Zero Days, Thousands of Nights: The Life and Times of Zero-Day Vulnerabilities and Their Exploits |date=2017 |publisher=Rand Corporation |isbn=978-0-8330-9761-3 |language=en|url=https://www.rand.org/content/dam/rand/pubs/research_reports/RR1700/RR1751/RAND_RR1751.pdf}} *{{cite journal |last1=Boyle |first1=James |title=The Second Enclosure Movement and the Construction of the Public Domain |journal=Law and Contemporary Problems |date=2003 |volume=66 |issue=1 |pages=33–74 |url=https://scholarship.law.duke.edu/lcp/vol66/iss1/2/ |issn=0023-9186}} *{{cite book |last1=Campbell-Kelly |first1=Martin |last2=Garcia-Swartz |first2=Daniel D. |title=From Mainframes to Smartphones: A History of the International Computer Industry |date=2015 |publisher=Harvard University Press |isbn=978-0-674-28655-9 |language=en}} *{{cite book |last1=Daswani |first1=Neil|authorlink=Neil Daswani |last2=Elbayadi |first2=Moudy |title=Big Breaches: Cybersecurity Lessons for Everyone |date=2021 |publisher=Apress |isbn=978-1-4842-6654-0}} *{{Cite book |last=Dooley |first=John F. |title=Software Development, Design and Coding: With Patterns, Debugging, Unit Testing, and Refactoring |date=2017 |publisher=Apress |isbn=978-1-4842-3153-1 |language=en}} *{{cite book |last1=Foster |first1=Elvis C. |title=Software Engineering: A Methodical Approach |date=2014 |publisher=Apress |language=en|isbn= 978-1-4842-0847-2}} *{{cite book |last1=Gabbrielli |first1=Maurizio |last2=Martini |first2=Simone |title=Programming Languages: Principles and Paradigms |date=2023 |publisher=Springer |isbn=978-3-031-34144-1 |language=en|edition=2nd}} *{{cite book |last1=Galin |first1=Daniel |title=Software Quality: Concepts and Practice |date=2018 |publisher=John Wiley & Sons |isbn=978-1-119-13449-7 |language=en}} *{{cite book |last1=Haber |first1=Morey J. |last2=Hibbert |first2=Brad |title=Asset Attack Vectors: Building Effective Vulnerability Management Strategies to Protect Organizations |date=2018 |publisher=Apress |isbn=978-1-4842-3627-7 |language=en}} *{{cite book |last1=Kaczmarek |first1=Stefan |last2=Lees |first2=Brad |last3=Bennett |first3=Gary |last4=Fisher |first4=Mitch |title=Objective-C for Absolute Beginners: iPhone, iPad and Mac Programming Made Easy |date=2018 |publisher=Apress |isbn=978-1-4842-3428-0 |ref={{sfnref|Kaczmarek ''et al.''|2018}} |language=en}} *{{cite journal |last1=Katyal |first1=Sonia K. |title=The Paradox of Source Code Secrecy |journal=Cornell Law Review |date=2019 |volume=104 |pages=1183 |url=https://heinonline.org/HOL/LandingPage?handle=hein.journals/clqv104&div=32&id=&page=}} *{{cite book |last1=Kitchin |first1=Rob |last2=Dodge |first2=Martin |title=Code/space: Software and Everyday Life |date=2011 |publisher=MIT Press |isbn=978-0-262-04248-2 |language=en}} *{{cite journal |last1=Lin |first1=Daniel |last2=Sag |first2=Matthew |last3=Laurie |first3=Ronald S. |title=Source Code versus Object Code: Patent Implications for the Open Source Community |journal=Santa Clara Computer and High Technology Law Journal |date=2001 |volume=18 |pages=235 |url=https://heinonline.org/HOL/LandingPage?handle=hein.journals/sccj18&div=16&id=&page=|ref={{sfnref|Lin et al.|2001}}}} *{{cite journal |last1=Morin |first1=Andrew |last2=Urban |first2=Jennifer |last3=Sliz |first3=Piotr |title=A Quick Guide to Software Licensing for the Scientist-Programmer |journal=PLOS Computational Biology |date=2012 |volume=8 |issue=7 |pages=e1002598 |doi=10.1371/journal.pcbi.1002598 |doi-access=free |pmid=22844236 |pmc=3406002 |bibcode=2012PLSCB...8E2598M |language=en |issn=1553-7358|ref={{sfnref|Morin et al.|2012}}}} *{{cite book |last1=O'Regan |first1=Gerard |title=Concise Guide to Software Engineering: From Fundamentals to Application Methods |date=2022 |publisher=Springer Nature |isbn=978-3-031-07816-3 |language=en}} *{{cite journal | last1=Sen | first1=Ravi | last2=Subramaniam | first2=Chandrasekar | last3=Nelson | first3=Matthew L. | title=Determinants of the Choice of Open Source Software License | journal=Journal of Management Information Systems | publisher=Informa UK Limited | volume=25 | issue=3 | year=2008 | issn=0742-1222 | doi=10.2753/mis0742-1222250306 | pages=207–240|ref={{sfnref|Sen et al.|2008}}}} * {{cite book |last1=Sebesta |first1=Robert W. |title=Concepts of Programming Languages |date=2012 |publisher=Addison-Wesley |isbn=978-0-13-139531-2 |edition=10 |language=en}} *{{cite book |last1=Tracy |first1=Kim W. |title=Software: A Technical History |date=2021 |publisher=Morgan & Claypool Publishers |isbn=978-1-4503-8724-8 |language=en}} *{{cite book |last1=Tripathy |first1=Priyadarshi |last2=Naik |first2=Kshirasagar |title=Software Evolution and Maintenance: A Practitioner's Approach |date=2014 |publisher=John Wiley & Sons |isbn=978-0-470-60341-3 |language=en}} *{{cite book |last1=Varga |first1=Ervin |title=Unraveling Software Maintenance and Evolution: Thinking Outside the Box |date=2018 |publisher=Springer |isbn=978-3-319-71303-8 |language=en}} {{refend}} == External links == {{Wiktionary|code|source code}} {{Commons category}} {{Authority control}} {{DEFAULTSORT:Source Code}} [[Category:Source code| ]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Authority control
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Commons category
(
edit
)
Template:Endash
(
edit
)
Template:ISBN
(
edit
)
Template:Main
(
edit
)
Template:Main article
(
edit
)
Template:Program execution
(
edit
)
Template:Refbegin
(
edit
)
Template:Refend
(
edit
)
Template:Reflist
(
edit
)
Template:See also
(
edit
)
Template:Sfn
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Webarchive
(
edit
)
Template:Wiktionary
(
edit
)