Tuesday, December 3, 2013

Basics for Snippet



SNIPPET:
"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. This concrete inclusion is in contrast to abstraction methods, such as a function, which is abstraction within the language, and processed by the compiler, or macros, which are abstractions using a separate language, and processed by the preprocessor. Snippets are thus primarily used when these alternative abstractions are not available or not desired, such as in languages that lack abstraction, or for clarity and absence of overhead (by contrast with the indirection of macros).
Snippets are similar to having static preprocessing included in the editor, and do not require support by a compiler: once a snippet is included into the text, no further processing occurs. On the flip side, this means that snippets cannot be modified after the fact (except via search and replace, assuming the code has not been changed), 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, or standard library imports.
A snippet is a small section of text or source code that can be inserted into the code of a program or Web page. Snippets provide an easy way to implement commonly used code or functions into a larger section of code. Instead of rewriting the same code over and over again, a programmer can save the code as a snippet and simply drag and drop the snippet wherever it is needed. By using snippets, programmers and Web developers can also organize common code sections into categories, creating a cleaner development environment.
Snippets used in software programming often contain one or more functions written in C, Java, or another programming language. For example, a programmer may create a basic "mouse-down event" snippet to play an action each time the user clicks a mouse button. Other snippets might be used to perform "Open file" and "Save file" operations. Some programmers also use plain text snippets to comment code, such as adding developer information at the beginning of each source file.
In Web development, snippets often contain HTML code. An HTML snippet might be used to insert a formatted table, a Web form, or a block of text. CSS snippets may be used to apply formatting to a Web page. Web scripting snippets written in JavaScript, PHP, or another scripting language may be used to streamline dynamic Web page development. For example, a PHP snippet that contains database connection information can be inserted into each page that accesses information from a database. Whether programming software or developing websites, using snippets can save the developer a lot of time.