HOME

TheInfoList



OR:

Code cleanup refers to the act of writing code so that it cleans up leftover
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the rel ...
s and other unwanted materials from memory and the filesystem. It is sometimes treated as a synonym of
refactoring In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structu ...
code, which involves making the source code itself easier to understand, maintain, and modify.


Examples


C++

In C++, code cleanup involves deallocating previously allocated
dynamic memory Memory management is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when ...
. This is usually done with the C++ delete and delete[] operations. int x = 15; int* mySequence = new int[x]; for (int i = 0; i < x; i++) mySequence = -127; delete[] mySequence;


Python

In
Python 3 The programming language Python was conceived in the late 1980s, and its implementation was started in December 1989 by Guido van Rossum at CWI in the Netherlands as a successor to ABC capable of exception handling and interfacing with th ...
, explicit deletion of variables requires the del keyword. x = 15 my_sequence = for useless_variable in range(x)my_sequence = -127 del my_sequence


JavaScript

In
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, objects are garbage collected if they are unreachable from the global object. One way to make an object unreachable is to overwrite the variables or properties that reference it. let x = ; // The variable x is declared and set to an object x = null; // x is overwritten and the object becomes unreachable


Java

In
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
, variables cannot be truly deleted. The most that can be done is to set the variable to null, which works with any Java object, including arrays. int x = 15; int[] my_sequence = new int[x]; for (int i = 0; i < x; i++) my_sequence = -127; my_sequence = null;


Other meanings

Code cleanup can also refer to the removal of all
computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
from
source code In computing, source code, or simply code, is any collection of code, with or without comment (computer programming), comments, written using a human-readable programming language, usually as plain text. The source code of a Computer program, p ...
, or the act of removing
temporary file A temporary file is a file created to store information temporarily, either for a program's intermediate use or for transfer to a permanent file when complete. It may be created by computer programs for a variety of purposes, such as when a program ...
s after a program has finished executing. For instance, in a
web browser A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used on ...
such as Chrome browser or
Maxthon Maxthon (, formerly named ''MyIE2'') is a freeware web browser, created by JeffChen in Singapore. It is available for Windows, macOS, Linux, and as ''Maxthon Mobile'' for Android, iOS, and Windows Phone 8. Since version 6 Maxthon is based on Chr ...
, code must be written in order to clean up files such as
cookies A cookie is a baked or cooked snack or dessert that is typically small, flat and sweet. It usually contains flour, sugar, egg, and some type of oil, fat, or butter. It may include other ingredients such as raisins, oats, chocolate chips, n ...
and storage. The deletion of temporary files is similar to the deletion of unneeded lists and arrays of
data In the pursuit of knowledge, data (; ) is a collection of discrete values that convey information, describing quantity, quality, fact, statistics, other basic units of meaning, or simply sequences of symbols that may be further interpret ...
. However, a file is treated as a permanent way to store a resizable list of
byte The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit ...
s, and can also be removed from existence.


Loop cleanup

Another technical term sometimes called "code cleanup" is
loop Loop or LOOP may refer to: Brands and enterprises * Loop (mobile), a Bulgarian virtual network operator and co-founder of Loop Live * Loop, clothing, a company founded by Carlos Vasquez in the 1990s and worn by Digable Planets * Loop Mobile, ...
cleanup. /* 'The i++ part is the cleanup for the for loop.' */ for i = 0; i < 100; i++ print i end import type list =
0, 20, 30, 40, 50 The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline (t ...
/* 'Even in a for each loop, code cleanup with an incremented variable is still needed.' */ i = 0 for each element of list list ^= 2 // 'Squares the element.' print string(element) + " is now... " + string(list i++ end


References

{{Reflist


Other Resources


HTML Code CleanupFormatting and Cleaning Up CodeCode Formatter
Source code