Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Source code

From Wikipedia, the free encyclopedia
Human-readable instructions a computer can execute
For other uses, seeSource Code (disambiguation).

SimpleC-language source code example, aprocedural programming language. The resulting program prints "hello, world" on the computer screen. This first known "Hello world"snippet from the seminal bookThe C Programming Language originates fromBrian Kernighan in theBell Laboratories in 1974.[1]
Program execution
General concepts
Types of code
Compilation strategies
Notable runtimes
Notable compilers & toolchains

Incomputing,source code, or simplycode orsource, ishuman readableplain text that can eventually result in controlling the behavior of acomputer. In order to control a computer, it must be processed by acomputer program – either executed directly via aninterpreter ortranslated into a more computer-consumable form such as via acompiler. Sometimes, code is compiled directly tomachine code so that it can be run in the native language of the computer without further processing. But, many modern environments involve compiling to anintermediate representation such asbytecode that can either run via an interpreter or be compiled on-demand to machine code viajust-in-time compilation.

Background

[edit]

The first programmable computers, which appeared at the end of the 1940s,[2] were programmed inmachine language (simple instructions that could be directly executed by the processor). Machine language was difficult to debug and was notportable between different computer systems.[3] Initially, hardware resources were scarce and expensive, whilehuman resources were cheaper.[4] As programs grew more complex,programmer productivity became a bottleneck. This led to the introduction ofhigh-level programming languages such asFortran in the mid-1950s. These languagesabstracted away the details of the hardware,and were designed to express algorithms that could be understood more easily by humans.[5][6] As instructions distinct from the underlyingcomputer hardware, software is therefore relatively recent, dating to these early high-levelprogramming languages such asFortran,Lisp, andCobol.[6] The invention of high-level programming languages was simultaneous with thecompilers needed to translate the source code automatically into machine code that can be directly executed on thecomputer hardware.[7]

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.[8][9]

Organization

[edit]
Further information:Software configuration management

Most programs do not contain all the resources needed to run them and rely on externallibraries. Part of the compiler's function is to link these files in such a way that the program can be executed by the hardware.[10]

A more complexJava source code example. Written inobject-oriented programming style, it demonstratesboilerplate code. With prologue comments indicated in red, inline comments indicated in green, and program statements indicated in blue.

Software developers often useconfiguration 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.[11]

Purposes

[edit]

Estimation

[edit]

The number ofsource lines of code (SLOC) is often used as a metric when evaluating the productivity of computer programmers, the economic value of a code base,effort estimation for projects in development, and the ongoing cost ofsoftware maintenance after release.[12]

Communication

[edit]

Source code is also used to communicatealgorithms between parties, e.g.,code snippets online or in books.[13]

Computerprogrammers can find it helpful to review extant source code to learn about programming techniques.[13] The sharing of source code between developers is often cited as a contributing factor to the maturing of their programming skills.[13] Some consider source code an expressiveartistic medium.[14]

Source code often containscomments—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.[15]

Companies often keep the source code confidential in order to hide algorithms considered atrade secret. Proprietary, secret source code and algorithms are widely used for sensitive government applications such ascriminal justice, which results inblack box behavior with a lack oftransparency into the algorithm's methodology. The result is avoidance of public scrutiny of issues such as bias.[16]

Modification

[edit]
See also:Software development andSoftware maintenance

Access to the source code (not just theobject code) is essential to modifying it.[17] Understanding extant code is necessary to understand how it works[17] and before modifying it.[18] The rate of understanding depends both on the code base as well as the skill of the programmer.[19] Experienced programmers have an easier time understanding what the code does at a high level.[20]Software visualization is sometimes used to speed up this process.[21]

Many software programmers use anintegrated development environment (IDE) to improve their productivity. IDEs typically have several features built in, including asource-code editor that can alert the programmer to common errors.[22] Modification often includescode refactoring (improving structure without changing function) and restructuring (improving structure and function simultaneously).[23] Nearly every change to code introduces new bugs or unexpectedripple effects, which require another round of fixes.[18]

Code reviews by other developers are often used to scrutinize new code added to a project.[24] The purpose of this phase is often to verify that the code meets style andmaintainability standards and that it is a correct implementation of thesoftware design.[25] According to some estimates, code review dramatically reduce the number of bugs persisting aftersoftware testing is complete.[24] 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.[26]Debuggers are tools that often enable programmers to step through execution while keeping track of which source code corresponds to each change of state.[27]

Compilation and execution

[edit]

Source code files in a high-level programming language must go through a stage of preprocessing intomachine code before the instructions can be carried out.[7] After being compiled, the program can be saved as anobject file and theloader (part of the operating system) can take this saved file andexecute it as aprocess on the computer hardware.[10] Some programming languages use aninterpreter instead of a compiler. An interpreter converts the program into machine code atrun time, which makes them 10 to 100 times slower than compiled programming languages.[22][28]

Portability

[edit]
Further information:Software portability

Another reason many programs are distributed in source code form, instead of as executablebinary files, is that (often) a single source code file can be written once and will run on a variety of different end-user machines (each with their own localized compiler or interpreter), unlike an executable code file which generally only works on nearly-identical machines. Source code was used this way to distribute the Unix operating system early in thehistory of Unix, and later to allow programs written inscripting languages (in particular theJavaScriptclient-side scripting language) to run on a wide variety of machines.

For this goal,minified,obfuscated, ordecompiled source code files (all of which eliminate the comments in the original code) are generally just as portable as the original source code files (which nearly always include commments), even though they are far less useful for modification, and therefore don't meet the definition of source code in theGNU General Public License, version 2 (GPL2).

Quality

[edit]
Further information:Software quality

Software quality is an overarching term that can refer to a code's correct and efficient behavior, its reusability andportability, or the ease of modification.[29] It is usually more cost-effective to build quality into a product from the start rather than try to add it later in a development process.[30] Higher quality code reduces lifetime cost to both suppliers and customers as via higher reliability andmaintainability.[31][32]

Maintainability is the quality of software enabling it to be easily modified without breaking extant functions.[33] Following coding conventions such as using clear function and variable names that correspond to their purpose makes maintenance easier.[34] Use ofconditional loop statements only if the code could execute more than once, and eliminating code that will never execute can also increase understandability.[35] Many software development organizations neglect maintainability during the development phase, even though it will increase long-term costs.[32]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.[36] A common cause is underestimates insoftware development effort estimation, leading to insufficient resources allocated to development.[37] A challenge with maintainability is that manysoftware engineering courses do not emphasize it.[38] Development engineers who know that they will not be responsible for maintaining the software do not have an incentive to build in maintainability.[18]

Copyright and licensing

[edit]
Further information:Software copyright andSoftware 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 notcopyrightable and therefore alwayspublic domain software.[39] 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".[40][41]

Proprietary software is rarely distributed as source code.[42] Although the termopen-source software literally refers topublic access to the source code,[43] 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.[44][45] The freereusability of open-source software can speed up development.[46]

See also

[edit]

References

[edit]
  1. ^Kernighan, Brian W."Programming in C: A Tutorial"(PDF). Bell Laboratories, Murray Hill, N. J. Archived fromthe original(PDF) on 23 February 2015.
  2. ^Gabbrielli & Martini 2023, p. 519.
  3. ^Gabbrielli & Martini 2023, pp. 520–521.
  4. ^Gabbrielli & Martini 2023, p. 522.
  5. ^Gabbrielli & Martini 2023, p. 521.
  6. ^abTracy 2021, p. 1.
  7. ^abTracy 2021, p. 121.
  8. ^Linet al. 2001, pp. 238–239.
  9. ^Katyal 2019, p. 1194.
  10. ^abTracy 2021, pp. 122–123.
  11. ^O'Regan 2022, pp. 230–231, 233, 377.
  12. ^Foster 2014, pp. 249, 274, 280, 305.
  13. ^abcSpinellis, D:Code Reading: The Open Source Perspective. Addison-Wesley Professional, 2003.ISBN 0-201-79940-5
  14. ^"Art and Computer Programming"ONLamp.comArchived 20 February 2018 at theWayback Machine, (2005)
  15. ^Kaczmareket al. 2018, p. 68.
  16. ^Katyal 2019, pp. 1186–1187.
  17. ^abKatyal 2019, p. 1195.
  18. ^abcOffutt, Jeff (January 2018)."Overview of Software Maintenance and Evolution".George Mason University Department of Computer Science. Retrieved5 May 2024.
  19. ^Tripathy & Naik 2014, p. 296.
  20. ^Tripathy & Naik 2014, p. 297.
  21. ^Tripathy & Naik 2014, pp. 318–319.
  22. ^abO'Regan 2022, p. 375.
  23. ^Tripathy & Naik 2014, p. 94.
  24. ^abDooley 2017, p. 272.
  25. ^O'Regan 2022, pp. 18, 21.
  26. ^O'Regan 2022, p. 133.
  27. ^Kaczmareket al. 2018, pp. 348–349.
  28. ^Sebesta 2012, p. 28.
  29. ^Galin 2018, p. 26.
  30. ^O'Regan 2022, pp. 68, 117.
  31. ^O'Regan 2022, pp. 3, 268.
  32. ^abVarga 2018, p. 12.
  33. ^Varga 2018, p. 5.
  34. ^Tripathy & Naik 2014, pp. 296–297.
  35. ^Tripathy & Naik 2014, p. 309.
  36. ^Varga 2018, pp. 6–7.
  37. ^Varga 2018, p. 7.
  38. ^Varga 2018, pp. 7–8.
  39. ^Liu, Joseph P.; Dogan, Stacey L. (2005)."Copyright Law and Subject Matter Specificity: The Case of Computer Software".New York University Annual Survey of American Law.61 (2). Archived fromthe original on 25 June 2021.
  40. ^Apple Computer, Inc. v. Franklin Computer Corporation Puts the Byte Back into Copyright Protection for Computer ProgramsArchived 7 May 2017 at theWayback Machine in Golden Gate University Law Review Volume 14, Issue 2, Article 3 by Jan L. Nussbaum (January 1984)
  41. ^Lemley, Menell, Merges and Samuelson.Software and Internet Law, p. 34.
  42. ^Boyle 2003, p. 45.
  43. ^Morinet al. 2012, Open Source versus Closed Source.
  44. ^Senet al. 2008, p. 209.
  45. ^Morinet al. 2012, Free and Open Source Software (FOSS) Licensing.
  46. ^O'Regan 2022, p. 106.

Sources

[edit]

External links

[edit]
Look upcode orsource code in Wiktionary, the free dictionary.
Wikimedia Commons has media related toSource code.
International
National
Other
Retrieved from "https://en.wikipedia.org/w/index.php?title=Source_code&oldid=1323491037"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp