HOME

TheInfoList




Snippet is a programming term for a small region of re-usable
source code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...

source code
,
machine code In computer programming Computer programming is the process of designing and building an executable In computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, c ...
, or text. Ordinarily, these are formally defined operative units to incorporate into larger programming modules. Snippet management is a feature of some
text editor A text editor is a type of computer program In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret. In declarative programming, a ''computer program'' is ...

text editor
s, program
source code editor A source-code editor is a text editor A text editor is a type of computer program In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret. In declarati ...
s, IDEs, and related
software Software is a collection of instructions Instruction or instructions may refer to: Computing * Instruction, one operation of a processor within a computer architecture instruction set * Computer program, a collection of instructions Music * I ...

software
. It allows the user to avoid repetitive typing in the course of routine edit operations. Example of the feature in the Gedit editor.


Definition

In programming practice, "snippet" refers narrowly to a portion of source code that is literally included by an editor program into a file, and is a form of
copy and paste programming Copy-and-paste programming, sometimes referred to as just pasting, is the production of highly repetitive computer programming Computer programming is the process of designing and building an executable computer program to accomplish a specif ...
. This concrete inclusion is in contrast to abstraction methods, such as
functions Function or functionality may refer to: Computing * Function key A function key is a key on a computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations automatically. Modern comp ...
or macros, which are abstraction within the language. Snippets are thus primarily used when these abstractions are not available or not desired, such as in languages that lack abstraction, or for clarity and absence of overhead. Snippets are similar to having static preprocessing included in the editor, and do not require support by a compiler. On the flip side, this means that snippets cannot be invariably modified after the fact, and thus is vulnerable to all of the problems of copy and paste programming. For this reason snippets are primarily used for simple sections of code (with little logic), or for boilerplate, such as copyright notices, function prototypes, common control structures, or standard library imports.


Overview

Snippet management is a text editor feature popular among software developers or others who routinely require content from a catalogue of repeatedly entered text (such as with
source code In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and ...

source code
or boilerplate). Often this feature is justified because the content varies only slightly (or not at all) each time it is entered.


Snippets in text editors

Text editors that include this feature ordinarily provide a mechanism to manage the catalogue, and separate "snippets" in the same manner that the text editor and operating system allow management of separate files. These basic management abilities include operations such as viewing, adding, editing, deleting, sorting, filtering, grouping, renaming, and storing snippets in a
repository Repository may refer to: * ''The Repository'', a newspaper in Ohio * ''Ackermann's Repository'', a British periodical published 1809–1829 * Repository (version control), a data structure which stores metadata for a set of files or directory str ...
, catalogue, or
database In computing Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes and development of both computer hardware , hardware and sof ...

database
. Some editors provide a macro ability to snippets allowing function prototypes and variable control structures to be generated based on a standard template.


Snippets in IDEs

Some programmer's applications such as
Eclipse ECLiPSe is a software system for the development and deployment of Constraint Programming Constraint programming (CP) is a paradigm for solving combinatorial Combinatorics is an area of mathematics Mathematics (from Ancient Greek, Gr ...

Eclipse
,
NetBeans NetBeans is an integrated development environment#REDIRECT Integrated development environment {{Redirect category shell, 1= {{R from other capitalisation ... (IDE) for Java Java ( id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda ...
, and Microsoft's
Visual Studio Microsoft Visual Studio is an integrated development environment An integrated development environment (IDE) is a software application Application software (app for short) is computing software designed to carry out a specific task other ...
(uses
TextMate TextMate is a general-purpose GUI text editor A text editor is a type of computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually wr ...
-inspired snippets underhood) and other IDEs include built-in parts of structure for ease of coding. Other applications such as Macromedia
Dreamweaver Adobe Dreamweaver is a proprietary {{Short pages monitor