Source code of the program. How to write computer programs What is code in a programming language

Purpose

The source code is either used to produce object code or executed by an interpreter. Changes are never made to object code, only to source code, and then converted back to object code.

Another important purpose of source code is as a description of a program. Based on the text of the program, you can reconstruct the logic of its behavior. Comments are used to make source code easier to understand. There are also tools that allow you to automatically obtain source code documentation - the so-called. documentation generators.

In addition, the source code has many other uses. It can be used as a teaching tool; Beginning programmers may find it useful to examine existing source code to learn programming techniques and methodology. It is also used as a communication tool between experienced programmers, due to its (ideally) concise and unambiguous nature. Code sharing among developers is often cited as a contributing factor to improving the programmer experience.

Programmers often move source code from one project to another, which is called code reuse ( Software reusability).

Source code is a critical component for the process of porting software to other platforms. Without the source code of any piece of software, porting is either too difficult or completely impossible.

Organization

The source code of some part of the software (module, component) may consist of one or more files. Program code is not necessarily written in only one programming language. For example, often programs written in C language, for optimization purposes, contain inserts of code in assembly language. It is also possible that some components or parts of a program are written in different languages, and then assembled into a single executable module using a technology known as library linking ( library linking).

Complex software requires dozens or even hundreds of source code files to be built. In such cases, to simplify the build, project files are usually used that contain a description of the dependencies between the source code files and describe the build process. These files may also contain other compiler and design environment parameters. For different design environments, different project files can be used, and in some environments these files can be in a text format suitable for direct editing by a programmer using universal text editors; in other environments, special formats are supported, and the creation and modification of files is carried out using special tools programs. Project files are usually included in the term "source code". The vast majority of modern language environments require the use of project files, regardless of the complexity of the other source code included in the project. Often, source code also refers to resource files containing various data, for example, graphic images needed to build a program.

To facilitate work with source code, for collaboration on code by a team of programmers, version control systems are used.

Quality

Unlike humans, there is no “well-written” or “badly written” code for a computer. But how the code is written can greatly influence the software maintenance process. The quality of the source code can be judged by the following parameters:

  • code readability (including the presence or absence of comments to the code;
  • ease of support, testing, debugging and error correction, modification and porting;
  • low complexity;
  • low resource usage - memory, processor, disk space;
  • absence of comments output by the compiler;
  • absence of “garbage” - unused variables, unreachable code blocks, unnecessary outdated comments, etc.

Non-executable source code

see also

  • Example: Hello world program

Links

Wikimedia Foundation. 2010.

See what “Program code” is in other dictionaries:

    software package- 3.19 software package: An archive file containing program code in binary or source form, as well as metadata about the program, its version, dependencies and other information. Source: GOST R 54593 2011: Information technologies. Free... ...

    - (English: Netscape Plugin Application Programming Interface, NPAPI is a cross-platform plugin development architecture supported by many browsers. The interface was developed for the Netscape Navigator family of browsers, starting with Netscape... ... Wikipedia

    In computer science, a software agent is a program that enters into an intermediary relationship with a user or another program. The word “agent” comes from the Latin agere (to do) and means an agreement to perform actions from ... ... Wikipedia

    Framework is a term with a vague meaning. Commonly used in programming to denote "a simple conceptual structure used to solve a complex, problem-solving problem." The meaning of this term depends significantly on its context... ... Wikipedia

    This article is about the command system in general; For instructions, see: Transaction code. Machine code (platform-oriented code), machine language, a system of commands (set of operation codes) of a specific computer, which is interpreted ... ... Wikipedia

    Official terminology

    Virus (computer, software)- executable program code or an interpreted set of instructions that has the properties of unauthorized distribution and self-reproduction. The created duplicates of a computer virus do not always coincide with the original, but retain... ... Dictionary-reference book of terms of normative and technical documentation

    - (English managed code) is a term introduced by Microsoft to designate the code of a program executed under the “control” of a virtual machine. NET Common Language Runtime. In this case, ordinary machine code is called unmanaged code... ... Wikipedia

    A patch, or patch (English patch /pætʃ/ patch) is an automated, separately supplied software tool used to fix problems in software or change its functionality, as well as the process of installing the patch itself (... ... Wikipedia

    Pyramid Type Web application framework Developer ... Wikipedia

Books

  • Object-Oriented Design: Concepts and Program Code, Gast Holger. This book is designed to help the reader gain a deep understanding of the concept of objects, unlocking their true potential in order to write code that works effectively in the real world. It considers...

Some for fun, some to prove existence or disprove a hypothesis, some to exercise their brains (traveling on the surface of a Klein bottle or in four-dimensional space), but hundreds of people have created “esoteric” programming languages. I've gone through about 150 of these languages ​​and I'll never be the same again.

“Argh!”, “Oof!”, “2-ill”, “Nhohnhehr”, “Noit o" mnain gelb”, “DZZZZ”, “Ypsilax”, “YABALL”, fuckfuck - these are spells, poetry is only names... under catom - code examples in the most eye-catching programming languages.

The rabbit hole is deep.

INTERCAL (Turing-complete)



Don Woods and Jim Lyon

One of the oldest esoteric programming languages. According to the creators, its name means “Compiler Language With No Pronounceable Acronym”. The language was created in 1972 by students Don Woods and James M. Lyon as a parody of existing programming languages ​​and mental gymnastics.

Hello, world

Each program command can be given a probability with which it will be executed when the program starts. In addition, there are commands that block the execution of subsequent commands of a certain type or changes to variables.

Hello, world!

// “Hello World” by Stephen McGreal.
// Note that the views expressed in this source code do not necessarily coincide with those of the

Gr34t l33tN3$$?
M3h…
iT 41n"t s0 7rIckY.

L33t sP33k is U8er keWl 4nD eA5y wehn u 7hink 1t tHr0uGh.
1f u w4nn4be UB3R-l33t u d3f1n1t3lY w4nt in 0n a b4d4sS h4xX0r1ng s1tE!!! ;p
w4r3Z c0ll3cT10n2 r 7eh l3Et3r!

Qu4k3 cL4nS r 7eh bE5t tH1ng 1n teh 3nTIr3 w0rlD!!!
g4m3s wh3r3 u g3t to 5h00t ppl r 70tAl1_y w1cK1d!!!
I"M teh fr4GM4stEr aN I"lL t0t41_1Ly wIpE teh phr34k1ng fL00r ***j3d1 5tYlE*** wItH y0uR h1dE!!! L0L0L0L!
t3lEphR4gG1nG l4m3rs wit mY m8tes r34lLy k1kK$ A$$

L33t hAxX0r$ CrE4t3 u8er- k3wL 5tUff lIkE n34t pR0gR4mm1nG lAnguidGe$…
s0m3tIm3$ teh l4nGu4gES l00k jUst l1k3 rE41_ 0neS 7o mAkE ppl Th1nk th3y"r3 ju$t n0rMal lEE7 5pEEk but th3y"re 5ecRetLy c0dE!!!
n080DY unDer5tAnD$ l33t SpEaK 4p4rT fr0m j3d1!!!
50mE kId 0n A me$$4gEb04rD m1ghT 8E a r0xX0r1nG hAxX0r wH0 w4nT2 t0 bR34k 5tuFf, 0r mAyb3 ju5t sh0w 7eh wAy5 l33t ppl cAn 8E m0re lIkE y0d4!!! hE i5 teh u8ER!!!
1t m1ght 8E 5omE v1rus 0r a Pl4ySt4tI0n ch34t c0dE.
1t 3v3n MiTe jUs7 s4y “H3LL0 W0RLD!!!” u ju5t cAn"T gu3s5.
tH3r3"s n3v3r anY p0iNt l00KiNg sC3pT1c4l c0s th4t, be1_1Ev3 iT 0r n0t, 1s whAt th1s 1s!!!

5uxX0r5!!!L0L0L0L0L!!!

ArnoldC

Terminator programming language.

Hello, world!

Don't worry too much about which language you should choose to learn. Many novice programmers find it difficult to choose a language when they first start learning to write program codes. The actual language you choose does not matter when it comes to learning the structures and logic of constructing information. These skills are much more important and can be learned with any programming language.

  • When choosing a language, focus on the purpose for which you want to create program codes, and only then choose a starting language. For example, if you want to develop websites, then you should start by learning HTML and then supplement it with CSS, JavaScript and PHP. If you want to create programs for computers, then start learning C++ or any other basic programming language.
  • If you become a professional programmer, you will quickly realize that you will never use the language you originally learned for your work. Instead, you will continue to learn new languages ​​through documentation and experimentation all the time.

Find free online resources specific to your chosen language. The Internet is a treasure chest of free tutorials, courses, and videos dedicated to the language you choose to learn. You can learn the basics of almost any introductory language in a day.

  • Here are just a few popular sites: Bento, CodeAcademy, Code.org, html.net, Khan Academy, Udacity, W3Schools and many others.
  • wikiHow also has a wide variety of starter tutorials for different languages.
  • You can find educational videos for almost any language on YouTube.
  • Stack Exchange is one of the most popular forums where professional programmers answer any questions from users.
  • Download a good text editor. Many programming languages ​​allow the use of external text editors to write programs. Find a text editor that will display indentation and code markup.

    • Popular programs include Notepad++ (Windows), TextWrangler (OS X), and JEdit (any system).
  • Download any necessary compilers. Some programming languages ​​require a compiler to display the source code you have written. Compilers translate source code into an equivalent low-level language program, which is then processed by the computer. Many compilers are open source and free software. Languages ​​that require the use of compilers include:

    • BASIC
    • Fortran
    • Pascal
  • Start your first project. Choose a good introductory project that will allow you to try out your new skills. There are many offers and tutorials on this topic on the Internet; for example, you can start by creating simple websites with HTML, simple databases and functions with PHP, or simple programs in any of the languages ​​that require the use of compilers.

    This is an introductory part devoted to the theoretical foundations of programming. The reader can familiarize himself with it and then move on to studying programming in practice (links at the beginning and end of this material), can turn to practical exercises right away, or can continue to get acquainted with the theory of software development, choosing questions that interest him from the list above. As for this article, here are its main sections:

    Advice: When reading further material, do not try to remember all the terms and definitions that appear throughout the story. Everything will fall into place over time, especially since the hypertext of Internet pages is good because links to a detailed presentation of the material can be found where necessary. You can always return to the desired page and do it exactly when you feel a lack of knowledge. If any section is difficult for you to understand, skip it. If you don’t return to it in the future, this means that it turned out to be unnecessary for you in the process of learning the basics of programming.

    What is an algorithm, programming and pseudocode

    Let's start by defining what an algorithm is. Algorithm is the order of actions that must be performed to solve a specific problem. The concept of an algorithm is not associated only with programs executed on , so the answer to the question “who needs to execute” can be anyone or anything: a person, a robot, computer technology, etc. Algorithm- this is an instruction or guide or, finally, just action program. In this case, it is a description of the algorithm by means of , the constructions of which the computer can process. Or is it simply the process of writing the text of a computer program. In this interpretation, programming is synonymous with coding process. Why did I talk about interpretations? The fact is that software developers are very passionate about what they do, and can be extremely unhappy when their work is reduced to just the process of coding in a specific programming language. Itself is not only coding, but also the preliminary design stage, as well as subsequent stages and maintenance. By programming they often mean the process of creating a computer program as a whole, including the development of an algorithm, and coding is the translation of an already developed algorithm into a language understandable encoding object(meaning a computer or any other device that works according to a program specified by someone).

    So, the algorithm for any problem, described in any algorithmic language(procedural programming language), to a first approximation appears as a sequence of instructions or operators. An operator can be simple or compound. Simple operator- this is atomic programming language unit. Simple operators include (defining the name and type of a variable), (assigning a value to a variable), input and output operations, etc.

    Variable (in programming) is a named area of ​​RAM intended for temporary storage of a portion of data processed by a computer program. A variable is characterized by the size of the memory it occupies and its type, which determines how the memory is interpreted by the computer. The type of a variable can be simple or complex (complex). Simple types include numeric, character and logical types. A complex type is a collection of simple and/or other composite types.

    Compound statements are used to organize other statements in a sequence and control the flow of program execution. Compound operators include (repetition of a sequence of operators), etc. and are not operators themselves. They can be arguments to variable values ​​or criteria for executing loops and conditional statements. Part of mathematical and logical expressions can be .

    Subtotals: The simplest computer program is a sequence of operators (program instructions), some of which modify variables, while others control the execution of the program (loops, conditional statements), based on conditions specified by logical and arithmetic expressions.

    If any of this raises questions, then I suggest you follow any of the links above and get acquainted with the constructs of the procedural programming language I described in more detail.

    Previously, algorithms, before being implemented in , were presented in the form . Today, it seems to me, classical flowcharts are used quite rarely (in schools or in various courses on the basics of programming). Also, flowcharts are used to describe business processes together with diagrams, but this already applies to the stages of macro design. In my practice, I very rarely use any intermediate forms of describing algorithms, but if such a need arises, I do it using pseudocode. Pseudocode- This pseudo programming language, for which there are no standards for syntax. Pseudocode is devoid of details that are insignificant for understanding the essence of the algorithm, without which it is impossible to write programs in real programming languages. The only one the purpose of pseudocode is to formalize the description of the algorithm. Problems whose solutions are described in pseudocode are very easily transferred to any programming language, since pseudocode is a programming language with the only difference that there is no compiler for it, and the only interpreter for it is the human brain. I will tell you what a compiler and interpreter are at the end of this material.

    Examples of algorithms in pseudocode and in the form of flowcharts

    Here is an example of a description of the algorithm for the problem of dividing one number by another, performed in pseudocode:

    A: INTEGER TYPE INPUT(A) B: INTEGER TYPE INPUT(B) IF B=0 THEN OUTPUT(“ERROR: DIVISION BY 0!”) OUTPUT END IF C: REAL TYPE C = A / B OUTPUT(C)

    Integrated development environment (IDE) – a set of software tools that offer the user tools for writing program code, searching for and highlighting syntax errors in it, and running the application in debugging mode. The integrated development environment includes a compiler, linker, debugger, profiler, and other components. The most popular environment for developing software products in the programming languages ​​C#, VB.NET and C++ is, and for educational purposes I suggest using the following.

    Debugger – an IDE tool that allows you to execute a program step by step and track the values ​​of variables at each step defined by breakpoints or break points.

    Profiler – an IDE tool used to optimize program code in terms of its execution speed and the amount of RAM it occupies. Using a profiler, you can collect statistics on which part of the code is executed most often, and how much time and resources the computer spends on its execution. Based on these statistics, you can identify the bottlenecks of your program and direct your efforts to optimize them.

    Programming language – a formal language represented by a set of instructions (operators) with the help of which computer programs are written in compliance with a certain syntax. In other words, a programming language is the main tool for implementing an algorithm for a specific task on a computer.

    Machine code - a system of commands that the computer processor understands “without translation”.

    High and low level programming languages – classification of programming languages ​​according to the degree of ease of their use by humans to solve applied problems (high-level languages) or according to the degree of their proximity to machine code (low-level languages).

    Compiler – an application that deals with the compilation process - the translation of a program (translation of program code) written in a high-level programming language into a low-level language or into machine code. Compiling into a low-level language most often means translating a program into assembly language in order to fine-tune individual bottlenecks before finally translating it into machine code. An example of a program in assembler can be seen.

    Object module – a file containing the result of the compiler’s work, namely the machine code itself with links to other object modules, if the program is complex and consists of many components.

    Linker – an application that enters the process of creating an executable module after the compiler. If the result of compilation is several object modules, then the linker finds them all and builds an executable module from them.

    Executable module – a file containing the program exactly in the form that the bootloader of a specific operating system can process. Most often these are files with the extension exe or dll.

    Loader - part of the operating system that creates a separate one for the program, loads the data of the executable file into RAM (into the RAM area allocated for the process), initializes the processor registers, and starts the process. From this moment the program begins to execute.

    Interpreter – a program that executes program code step by step, translating into machine code only that part of it that needs to be executed at a specific point in time. The interpreter processes the program line by line. The difference between a compiler and an interpreter is that the compiler translates the entire program into machine code at once, creating one or more object modules, and the interpreter, having translated only the fragment of the program it needs, immediately executes this fragment. Thus, some interpreters are a compiler, linker and loader rolled into one. An example of an interpreter is a processing unit in an Internet browser.

    Let me finish with the theory and move on to practice. I'll start with this.

    Any program or online service, for example, Word, Microsoft Windows, WhatsApp or a browser, which hundreds of millions of people launch every day, one way or another, consists of special instructions. Or special program code that the machine understands and tells it what to do or, conversely, not to do. Or how to properly respond to user actions. What program code is will be discussed in this article.

    Description

    A program's program code is text written in a special language that a machine can understand. It can be executed directly from the text using an interpreter or translated into a special form using a compiler.

    The source code of a program may consist of several files. Moreover, they all must be of the same format. The program text contained in them must be written in the same language. True, there may be exceptions. For example, in web development, a page file may contain several different programming languages ​​and standards. Depending on the complexity of the project, languages ​​and technologies such as PHP, HTML, and others may be present.

    When assembled, complex software systems may require a large number of files, which can number in the hundreds. To collaborate on such large projects, programmers very often use version control systems. They allow you to simultaneously work with several copies of source code, which at a certain stage of development can be combined into one common one.

    Code quality

    The computer is not able to understand how the code for it is written, bad or good. If it is operational and does not contain errors, then the machine will launch it in any case. Bad code can complicate software maintenance tasks. This is especially true for large projects. Typically, high-quality code is characterized by several parameters:

    • Code readability. One glance at it should be enough to generally understand what is being implemented by a piece of code.
    • The presence of clear and succinct comments. This parameter greatly affects readability, ease of debugging, support testing, and troubleshooting of program code.
    • Low difficulty.
    • Code optimization. It should be organized in such a way that the program uses as few system resources as possible, such as memory, processor time and hard disk space.
    • No trash. That is, unused variables or blocks of code in which program control never enters.

    Malicious code

    In addition to useful programs, there are some that can harm the system or even the equipment. As a rule, such code is written by people who are interested in some benefit from the ongoing process. For example, programs that can steal personal data from users’ computers. They may be payment card numbers, passport data, or any other confidential information. Others may simply interfere with the operation of the system, thereby causing failures and preventing full functionality.

    Jeff Vogel, a longtime programmer, shared some tips for teaching aspiring developers the rules of good code.

    In particular, he suggests always commenting your program code. What is a comment? It is a clear and concise description of what is happening in a given line of code or function. The fact is that the development of a certain program may drag on for a month or even stop for some time. Returning to work on a project after a couple of months, even an experienced programmer will find it difficult to understand his own program. But detailed comments will be able to restore the chain of events and the behavior of the code.

    He further recommends using global variables in your program as often as possible. This is explained by the fact that when changing the program code, you will have to adjust the value of the variable in just one place. In this case, all functions or procedures that use the value will immediately know about it and will perform operations with the new data.

    Variable names and error detection

    The correct name of variables will also help to significantly reduce the time spent studying the source code of the program, even if the code was written by yourself. That is, good code is considered to be text where variables and functions have names that make it clear what exactly they do or store. In this case, you should try not to use long variable names.

    It is very important to pay great attention to timely elimination of errors. What is program code that executes perfectly? This is code that has no errors. That is, any loop branching or variable change, or even any unexpected user actions, will always lead to the expected result. This is achieved by testing the finished product several times.

    Identifying program code errors, or rather, predicting them, is possible at the program design stage. The presence in the code of various checks of conditions and possible exceptions will help control the program along a certain course.

    Optimization is of enormous importance for writing a workable program that will economically use computer resources and at the same time avoid errors in program code execution. What is an optimized program? This is a product that is capable of performing all the declared functionality, while behaving “quietly” and economically.

    Almost always, optimization for stable program operation can only be achieved by conducting several tests on different platforms and under different conditions. If a program begins to behave unpredictably, you need to determine what caused it and, if possible, eliminate or intercept the process.

    Conclusion

    What is program code? In simple terms, it is a set of instructions and concepts for a computer. It contains text that a compiler or interpreter can turn into machine-readable language. That is, in essence, program code is an intermediary between a person and a computer, which simplifies their relationship.