How To Format Your Code

Table of contents:

How To Format Your Code
How To Format Your Code

Video: How To Format Your Code

Video: How To Format Your Code
Video: Code Formatting - How To Format Your Code with Style 2024, December
Anonim

Cases when the source code of a program consists of one line are extremely rare. Typically, the source code contains from hundreds to a thousand (sometimes - up to several hundred thousand) lines of code and work on it takes several weeks or months. Later, the programmer again has to return to the old and fairly well forgotten source code. Easy-to-read design of the code saves a lot of time spent on working with an already written program - this applies both to comments and friendly names of variables and user-defined functions, as well as to formatting the source code.

How to format your code
How to format your code

Instructions

Step 1

Use the formatting capabilities provided by the programming environment itself if you have the ability to take care of the layout of the source code while writing the program. Most code editors allow you to do this - almost all of them automatically respect the indentation used on the previous line when you press the Enter key. In addition, the preferences usually provide the ability to specify whether to use tabs or an adjustable number of spaces for formatting. Save frequently used blocks of code in code libraries already formatted so you don't have to do it again every time.

Step 2

Use the built-in function of the code editor if you need to format the ready-made source code of the program - it is available in many popular programming environments. The placement of the link to launch this function depends on the editor used. For example, in the PHPEdit application, this option is placed in the "Tools" section of its menu. The corresponding subsection is called “Code Formatting” here. There you can select options for formatting only the active document or the contents of all open windows, and there is also a link to launch the settings panel for this procedure. Some of the editors do not have built-in functions of this kind, but they allow you to download additional plugins from the manufacturer's website and use them in conjunction with the program.

Step 3

Choose a specialized program designed not for creating source code, but for formatting it, if your editor does not have the corresponding built-in function. As a rule, such applications are designed to work with source codes in one or several programming languages. However, there are also programs that allow you to change sets of rules in accordance with the processed code. For example, the Polystyle application (https://polystyle.com) can format sources in a dozen programming languages. In addition, it provides a function of masking ("obfuscation") of the program code, which may also be useful.

Recommended: