You get a bonus - 1 coin for daily activity. Now you have 1 coin

Source Code: Listing and Fundamentals

Lecture



Source code is a set of instructions written in a programming language that a computer can understand and execute. Source code contains a textual representation of a program that can be interpreted or compiled into an executable file. Source code is the text of a computer program written in some programming language or markup language that can be read by a human. In a generalized sense, it is any input data for a translator. Source code is translated into executable code in its entirety before the program is run using a compiler, or it can be executed immediately using an interpreter. Source code is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. Source code is specifically designed to facilitate the work of computer programmers, who define the actions to be performed by the computer mainly by writing source code. Source code is often transformed by an assembler or compiler into binary machine code that can be executed by the computer. The machine code can then be stored for execution later. Alternatively, source code can be interpreted and therefore executed immediately.

Most application programs are distributed in a form that includes only executable files. If the source code were included, it would be useful to the user, programmer, or system administrator, any of whom might wish to study or modify the program.

Note that every programming language has its own syntax and structure, and the source code can differ depending on the chosen language.

A listing is a paper or electronic printout of the text of a computer program or part of it.

Definitions

The Linux Information Project defines source code as:

Source code (also referred to as source or code) is the version of software as it was originally written (i.e., typed into a computer) by a human in plain text (i.e., human-readable alphanumeric characters).

The concept of source code can also be understood more broadly, including machine code and notations in graphical languages, neither of which is textual in nature. An example from a paper presented at the annual IEEE Conference on Source Code Analysis and Manipulation:

For clarity, "source code" means any fully executable description of a software system. It is therefore constructed so as to include machine code, very high-level languages, and executable graphical representations of systems.

There are often several stages of translation or minification of a program between the original source code typed by a human and the executable program. While some, such as the FSF, argue that an intermediate file "is not real source code and does not count as source code," others find it convenient to refer to each intermediate file as the source code for the following steps.

History

The earliest programs for stored-program computers were entered in binary format via switches on the front panel of the computer. In this first-generation programming language there was no distinction between source code and machine code.

When IBM first offered software to work with its machine, the source code was provided free of charge. At that time, the cost of software development and support was included in the cost of the hardware. For decades, IBM distributed source code with its software product licenses, up until 1983.

Most early computer magazines published source code as type-in programs.

Sometimes the entire source code of a large program is published as a hardcover book, such as Computers and Typesetting, vol. B: TeX, The Program by Donald Knuth, PGP Source Code and Internals by Philip Zimmermann, PC SpeedScript by Randy Thompson, and µC/OS, The Real-Time Kernel by Jean Labrosse.

Organization

The source code that makes up a program is usually stored in one or more text files stored on the computer's hard drive; typically these files are carefully organized into a directory tree known as a source tree. Source code can also be stored in a database (as is usually the case for stored procedures) or somewhere else.

Source Code: Listing and Fundamentals

Fig. 1. An example of source code in JavaScript

Source Code: Listing and Fundamentals
Fig. 2 A more complex example of Java source code. Written in an object-oriented programming style, it demonstrates boilerplate code. Prologue comments are marked in red, inline comments in green, and program statements in blue.

Source Code: Listing and Fundamentals

Fig. 3 An example of a program listing in C

The source code for a specific piece of software can be contained in a single file or in several files. Although such a practice is rare, the source code of a program can be written in different programming languages. For example, a program written mainly in the C programming language may have parts written in assembly language for optimization purposes. It is also possible for some software components to be written and compiled separately in an arbitrary programming language and then integrated into the software using a method called library linking. In some languages, such as Java, this can be done at runtime (each class is compiled into a separate file that is linked by the interpreter at runtime).

Another method is to make the main program an interpreter for a programming language, either designed specifically for the application in question or general-purpose, and then write most of the actual user functionality as macros or other forms of add-ins in that language, an approach taken, for example, by the GNU Emacs text editor.

The codebase of a computer programming project is a large collection of all the source code of all the computer programs that make up the project. Maintaining codebases in version control systems has become common practice. Moderately complex software usually requires the compilation or assembly of several, sometimes dozens, and perhaps hundreds of different source code files. In these cases, instructions for compilation, such as a Makefile, are included with the source code. They describe the programmatic relationships between the source code files and contain information about how they should be compiled.

Purposes

Source code is mainly used as input for a process that creates an executable program (i.e., it is compiled or interpreted). It is also used as a method of conveying algorithms between people (for example, code snippets in books).

Programmers often find it useful to review existing source code to learn about programming techniques. Sharing source code between developers is often cited as a factor contributing to the development of their programming skills. Some people consider source code an expressive artistic medium.

Porting software to other computer platforms without the source code is usually extremely difficult. Without the source code for a specific piece of software, portability is usually very computationally expensive. Possible porting options include binary translation and emulation of the original platform.

Decompilation of an executable program can be used to generate source code, either in assembly or in a high-level language.

Programmers often adapt the source code of one piece of software for use in other projects. This concept is known as software reusability.

Non-executable source code

Copyleft licenses for free software require the distribution of source code. These licenses are often used for non-program works as well, for example, documentation, images, and data files for computer games.

In such cases, the source code is considered to be the form of the given work preferred for editing it. In licenses intended not only for software, it may also be called the version in a "transparent format." This can be, for example:

  • for a lossily compressed file, the lossless version;
  • for a render of a vector image or a three-dimensional model, the vector version and the model, respectively;
  • for an image of text, the same text in a text format;
  • for music, a file in the internal format of a music editor;
  • and finally, the file itself, if it satisfies the specified conditions, or if a more convenient version simply did not exist.

Legal aspects. History of free and open-source software.

The situation varies around the world, but in the United States prior to 1974, software and its source code were not protected by copyright and therefore were always in the public domain.

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 a proper subject of copyright."

In 1983, in the US court case Apple v. Franklin, it was decided that the same applies to object code as well; and that the Copyright Act granted computer programs the copyright status of literary works.

In 1999, in the US court case Bernstein v. United States, it was also ruled that source code could be considered a constitutionally protected form of free speech. Free speech advocates argued that because source code conveys information to programmers, is written in some language, and can be used to share humor and other artistic pursuits, it is a protected form of communication.

Software license

Example of a copyright notice:

Copyright

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The author of a non-trivial work such as software , has several exclusive rights, among them the copyright to the source code and the object code. The author has the right and ability to grant clients and users of their software some of their exclusive rights in the form of software licensing. Software and its accompanying source code can be associated with several licensing paradigms; the most important distinction is between free and non-free software. This is done by including a copyright notice that declares the licensing terms. If no notice is found, then by default All rights reserved. is implied.

Generally speaking, software is free software if its users are free to use it for any purpose, study and modify its source code, provide or sell exact copies of it, and distribute or sell modified copies of it. Software is proprietary if it is distributed while the source code is kept secret, or is privately owned and restricted. One of the first software licenses to be published and to explicitly grant these freedoms was the GNU General Public License in 1989; the BSD license is another one of the earliest examples, from 1990.

For patented software, provisions of various copyright, trade secret, and patent laws are used to keep the source code closed. In addition, many pieces of retail software come with an end-user license agreement (EULA), which usually prohibits decompilation, reverse engineering, analysis, modification, or circumvention of copy protection. Types of source code protection, in addition to traditional compilation to object code, include code encryption, code obfuscation, or code transformation.

Software quality

The way a program is written can have important consequences for its maintainers. Coding conventions that emphasize readability, and some conventions specific to a particular language, are aimed at supporting the source code of the software, which includes debugging and updating. Other priorities, such as the program's execution speed or the ability to compile the program for multiple architectures, often make code readability a less important factor, since the quality of the code usually depends on its purpose.

See also

  • Bytecode
  • Code as data
  • Coding conventions
  • Computer code
  • Free software
  • Legacy code
  • Machine code
  • Markup language
  • Obfuscated code
  • Object code
  • Package (package management system)
  • Programming language
  • Source code repository
  • Syntax highlighting
  • Visual programming language
  • Refactoring
  • Code style standard
  • Free software
  • Esoteric programming languages
  • Software license
  • Hello, world!
  • low-code
  • zero-code platforms, zero-code

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Software and information systems development"

Terms: Software and information systems development