荷花五行属什么| 什么是佛| 山药和什么不能一起吃| 五月十九日是什么星座| hold住是什么意思| 胎梦梦见蛇是什么意思| 女性盆腔炎吃什么药| offer是什么意思| 大人发烧吃什么退烧药| 胆汁反流性胃炎吃什么中成药| 什么茶提神| 养什么能清理鱼缸粪便| ocg是什么意思| 做爱为什么那么舒服| nox是什么意思| 千焦是什么单位| 拔牙之后可以吃什么| 血常规是检查什么的| 莺是什么鸟| 阿胶有什么功效| 干咳是什么原因| 女人阴部黑是什么原因| 11月25是什么星座| 4月份是什么星座| 种草莓什么意思| 咳嗽吃什么好的快偏方| 梦见自己生个女孩是什么意思| 睡眠不好总做梦是什么原因| 头自动摇摆是什么原因| 黄飞鸿属什么生肖| tap是什么意思| 唵是什么意思| std什么意思| 葛根是什么| 血小板低会引发什么病| 补肾最好的药是什么药| 唱歌有什么好处| abi医学上是什么意思| 尿带血是什么原因| 女人跑马是什么意思| 土耳其说什么语言| 全身痒是什么病| 什么是亲子鉴定| 大便是黑色的是什么原因| 宝宝便秘吃什么食物好| 3月29号是什么星座| 圆脸适合什么发型| 屈光检查是什么| 烂好人是什么意思| 红糖荷包蛋有什么功效| 人人有的是什么生肖| 一什么眼镜| 为什么来月经肚子疼| 什么的池塘| 上腹部饱胀是什么原因| bea是什么意思| 分泌是什么意思| 尿糖阳性是什么意思| 降尿酸什么药最好| 锦鲤可以和什么鱼混养| 生气过度会气出什么病| 胃酸是什么颜色的| 外感发热什么意思| 湿疹是什么| 什么叫糖化血红蛋白| 梦见打老公是什么意思| 女人脾虚吃什么药最好| 空泡蝶鞍是什么病| 18k金和24k金有什么区别| ala是什么| 太阳穴长痘痘是什么原因| 622188开头是什么银行| 兔子爱吃什么| 为什么支气管炎咳嗽长期不好| 劝君更尽一杯酒的下一句是什么| 孩子打喷嚏流鼻涕吃什么药| 世界最大的岛是什么岛| 四不放过是什么| 拔罐对身体有什么好处和坏处| 后背中心疼是什么原因| mlb是什么牌子| asks是什么意思| 女性血热吃什么好得快| 减肥什么方法最快最有效| 潋滟什么意思| 快菜是什么| 梦见买豆腐是什么意思| 吃什么对脾胃好| 肾腺瘤是什么病严重吗| 蹲久了站起来头晕是什么原因| 做牛排需要什么调料| 咸鱼什么意思| 宫颈粘膜慢性炎是什么意思| 丘疹性荨麻疹用什么药| 夏天吃什么养生| 盐水洗脸有什么好处与坏处| 难以入睡是什么原因引起的| 泥鳅什么人不能吃| 什么样的男人不能嫁| 肉偿是什么意思| 偶尔头疼是什么原因| 对什么什么感兴趣| lps医学上是什么意思| mpr是什么意思| 花生的种子是什么| 覃读什么| 丁亥日五行属什么| 乳腺癌ki67是什么意思| 胎位左枕前是什么意思| 梳子断了有什么预兆| 肚子右边是什么部位| 璨字五行属什么| 高血压吃什么菜| 后背疼痛挂什么科| 梦见韭菜是什么预兆| 脸部浮肿是什么原因| porsche是什么牌子的车| 覅是什么意思| 新婚志喜是什么意思| 胎监不过关是什么原因| 鸦片鱼又叫什么鱼| 尿路感染不能吃什么东西| 海丽汉森是什么档次| 素数是什么| 吃什么盐比较好有利于健康| 王加呈念什么| aml是什么病| 吃什么对肺好| 蛀牙是什么原因引起的| 梦见修坟墓是什么预兆| 今年88岁属什么生肖| 胃寒吃什么药最有效| 心率慢吃什么药| 兰花是什么季节开的| 碳酸钙d3颗粒什么时候吃最好| 心身医学科是看什么病| 怀孕有什么现象| 聚宝盆什么意思| u盾是什么| 晨五行属什么| 梅毒单阳性是什么意思| 胆结石吃什么水果好| 癌症病人吃什么| 什么是因果| 走投无路是什么意思| 降压灵又叫什么| tc版是什么意思| 有酒窝的女人代表什么| 抗生素药对人体有什么危害| 排骨炖苦瓜有什么功效| 婚检男性检查什么项目| 辟谷是什么都不吃吗| 前列腺ca是什么意思| 什么无为| 口腔溃疡吃什么水果好| 殿试是什么意思| 为什么明星不激光祛斑| 鸭子烧什么好吃| 牙龈炎吃什么消炎药| 什么是甲醛| 家里进黄鼠狼是什么预兆| 单核细胞偏高说明什么| 女生痛经有什么办法缓解| 津液不足吃什么中成药| 睾丸发炎吃什么药| 牙疼是什么原因引起的| 小孩小腿疼是什么原因引起的| 妊娠什么意思| 7月初7是什么日子| 鲱鱼罐头为什么这么臭| 湿气重吃什么药最好| 迷糊是什么意思| 戴尾戒是什么意思| 大腿抽筋是什么原因引起的| charging是什么意思| 内蒙古有什么特产| igc是什么意思| 尿维生素c阳性是什么意思| 到此为止是什么意思| 憩室什么意思| 破执是什么意思| 为什么会长疣| ca199是什么检查项目| 女人排卵期有什么反应| 蜂蜜什么人不能吃| 什么是太岁| 七八年属什么| 手电筒什么牌子的好| 手抖是什么症状| 小暑吃什么| 一般细菌培养及鉴定是检查什么| 右下腹疼痛挂什么科| 蜘蛛侠叫什么名字| 上海最高的楼叫什么| ro是什么意思| 天蝎女喜欢什么样的男生| 父母坟上长树意味什么| 折耳猫是什么| c60是什么| 辽国是现在的什么地方| 腋下发黑是什么原因| 查结核做什么检查| leg是什么意思| 咳嗽有绿痰是什么原因| 灶心土是什么| 花团锦簇是什么意思| 1217是什么星座| 向日葵是什么意思| 肌酸激酶偏高说明什么| 蝉鸣是什么季节| 哥弟属于什么档次| 珍惜眼前人是什么意思| 什么是生理盐水| 安眠药有什么副作用| 蛇怕什么东西| 男人性功能太强是什么原因| 属猴的什么命| 嬴稷是秦始皇的什么人| 肩膀疼挂什么科室最好| 五道杠是什么牌子| 婴儿胎发什么时候剪最好| 化疗期间吃什么最好| 鹿柴什么意思| 附件炎吃什么药效果好| 贾琏为什么叫二爷| 陈皮和橘子皮有什么区别| 阿莫西林主要治疗什么| 人乳头瘤病毒39型阳性是什么意思| 怼人是什么意思| 香蕉人是什么意思| 什么叫低级别上皮内瘤变| 血管瘤是什么样子的图| 甘油三酯低有什么危害| 头发油性大是什么原因| 牛奶不能和什么一起吃| 牙龈发炎用什么药| 莴苣是什么| 八仙过海指什么生肖| 鲶鱼吃什么| srpl是什么药| loaf是什么意思| 贵州有什么| 减肥适合吃什么| 88年出生属什么生肖| 擦什么能阻止毛发生长| 风向是什么意思| 斯沃琪手表什么档次| 尿多是什么原因| 梦见巨蟒是什么预兆| 缩量横盘意味着什么| 什么耳朵| 对什么什么感兴趣| 吃什么去除体内湿热| 夹不住尿是什么原因| 慢性萎缩性胃炎吃什么食物好| 什么叫脂溢性脱发| lg是什么牌子| 动脉硬化是什么意思| 钥匙代表什么生肖| 藤茶是什么茶| 上睑下垂是什么原因造成的| 指甲竖纹是什么原因| 鼍是什么动物| 梦见修坟墓是什么预兆| 百度

伪造火车票“家族企业”被打掉 婆媳落网公公在逃

百度 司卡纳控制着美国西部监狱四成以上的老干妈货源,而他的LaoGanMa帮也让人闻风丧胆。

Snippet is a programming term for a small region of re-usable source code, machine code, or text. Ordinarily, these are formally defined operative units to incorporate into larger programming modules. Snippet management is a feature of some text editors, program source code editors, IDEs, and related software. It allows the user to avoid repetitive typing in the course of routine edit operations.[1]

Example of a code snippet.

Definition

edit

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.[2] This concrete inclusion is in contrast to abstraction methods, such as functions 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

edit

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 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

edit

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, catalogue, or 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

edit

Some programmer's applications such as Eclipse, NetBeans, and Microsoft's Visual Studio (uses TextMate-inspired snippets underhood) and other IDEs include built-in parts of structure for ease of coding.

Other applications such as Macromedia Dreamweaver make use of these code snippets as well for Web development.

Snippets in JIT compilers

edit

Just-in-time (JIT) compilers can "splice together" pre-compiled sections of code as longer object code/machine code segments. This reduces interpret time significantly and simultaneously speeds execution.

 
Animated example demonstrating use of snippet in PowerShell ISE

Snippets in shells

edit

Snippets may be used inside commandline interfaces like bash, zsh (GNU Linux/Unix-like) or powershell (MS Windows). Features like completion and placeholders substitution may or may not be supported.

Example

edit

Consider the process of swapping the values of two variables, x and y. Assuming weak typing and not being concerned about name collision, this is represented by the code:

temp = x
x = y
y = temp

When the snippet is inserted, the programmer is prompted for the values of the two parameters. Assuming they are type foo and bar, which are the actual names of the variables they wish to swap, this will yield the code:

temp = foo
foo = bar
bar = temp

If the snippet is subsequently changed, say to use __temp instead of temp, it will not change the code that has already been inserted, but will be used in subsequent insertions of the snippet.

A snippet for this might be represented as:

temp = $1
$1 = $2
$2 = temp

Conventions

edit

In addition to the basic management abilities described previously, snippet management features can be classified according to the scope of interactivity between snippets and the text editor or application that hosts them.

These snippet feature groups include:

  • plain-text or "static" snippets
  • interactive or "dynamic" snippets
  • scriptable snippets
Static
Snippets of this type consist primarily of fixed text that the user can choose to insert into the current document. The user is not able to specify anything else, except perhaps the cursor position relative to the newly inserted text. Static snippets are similar to simple macros, excepting that macro are often evaluated (or inserted) by a command-line program instead of IDE.
Dynamic
Snippets consist of fixed text combined with dynamic elements (placeholders) which are allowed to be modified either by editor or by user. The user may specify both the content of the dynamic elements, as well as their position relative to the fixed text, as part of choosing what to insert into the current document. Examples of dynamic elements could be variables such as the current date or system time, or input from the user that is supplied via a GUI, or input from another application. (see also: programmable macro).
Scriptable
Snippets consist of runnable segments of code in either a macro language or a scripting language. Scriptable snippets provide the greatest degree of flexibility to the user, although that depends somewhat on the programming languages supported by the text editor, and whether or not the programming language is well-known, or particular and unique to that specific editor.

The type of scripting support varies, but may include features such as running shell commands, providing a GUI dialog or other methods of user interaction with the operating system; other applications; or other sub-components of the hosting application itself.


Snippet placeholders

edit

Placeholders are elements within a snippet that are left to be supplied by the user or other external process. The values for placeholders are not determined until the text of the snippet is inserted during an editing session.

Placeholders may have special markup syntax that allows the editor to identify the boundaries of placeholders relative to the other text in the current edit buffer.

Other applications employ graphical user interfaces and modal dialog boxes that allow the user to enter one or more values to be supplied for the placeholders.

Placeholder identifiers

edit

Placeholders are usually indicated by some special character or sequence of characters to distinguish them from the rest of the snippet text. Some systems allow snippet placeholders to be named identifiers. The identifiers may be useful for supporting such features as placeholder duplication or placeholder transformation.

The following example uses the identifiers first_name, last_name, and item:

Hello {%first_name%} {%last_name%},

Your shipment of {%item%} is now ready to pick up.

Thanks {%first_name%}!

Example of a snippet in TexMate syntax:

Hello ${1:first_name} ${2:last_name},

Your shipment of ${3:item} is now ready to pick up.

Thanks ${4:first_name}!

Placeholder duplication

edit

This allows the user to indicate that the value supplied for one placeholder should be replicated in multiple places, relative to the entire text of the programmable snippet. In the previous example, the named placeholder first_name is an example of this usage.

Placeholder transformation

edit

This allows the user to indicate that one or more values supplied for a placeholder should be replicated and transformed in other places within the text of the programmable snippet. For example, the user may supply a document title in one part of the snippet, and specify that the document title should be repeated in other places, with the first instance being all-uppercase and every other instance being lower-case.

Snippet programming features

edit

For applications that support scriptable snippets, the range of supported programming features varies. The following enumerates some of the features that are commonly implemented for programmable snippets.

Plain text

edit

Although plain text is a fundamental feature included even with applications that support only non-programmable "static" snippets, programmable snippets are also used for working with plain text.

One common complication, however, is that environments that support programmable snippets often have to make distinctions between what counts as "plain text" and what counts as "programming instructions". Further complicating this distinction is the fact that applications that support programmable snippets almost always include support for recognition of multiple programming languages, either through basic syntax highlighting or execution of embedded commands.

For these and other reasons, emitting plain text from programmable snippets almost always entails being careful to avoid problems with syntax and delimiter collisions.

Constants and variables

edit

Programmable snippets often include an ability to establish a binding to an existing variable scope or namespace, from which the user can select any of various constants or variables. These might include values such as the email address of the currently logged-in user on a given machine, the current system time and date, or the output value of a function.

Scriptable snippets are often associated with one or more currently active files. Consequently, variables may also include environment variables and arguments that specify the filename, cursor position, and parent directory among other stats relating to the files in a current editing session.

Interpreted code

edit

Scriptable snippets may allow execution of code in one or more programming languages. This may include one or more standalone languages, or a language that is specific to the application in which the language is hosted.

Alternatives

edit

The most basic alternative to code snippets is subroutines in libraries. Subroutines can be incorporated into a reusable software library and shared between multiple programming projects.

Design patterns in object-oriented programming, and functional programming, are both techniques that can allow programmers to avoid or reduce the practice of repeatedly inserting snippets into different pieces of code with slight variations each time. In languages in the C family, preprocessors are sometimes used for this purpose.

The disadvantage of this approach however is that it's harder to remember pattern or documentation.

Software assistance

edit

As of 2021 some sophisticated deep-learning tooling emerged that can help to infer specific functionality from a human readable text and generate corresponding source code snippets (e.g. GitHub Copilot).[3][4]

See also

edit
  • Autocomplete – Computing feature predicting ending to a word a user is typing
  • Codebase – Source-code collection used to build a system, application, or component
  • Code refactoring – Restructuring existing computer code without changing its external behavior
  • Content management – Creation and presentation of information for an audience
  • Pastebin – Type of online content hosting service where users can store plain text
  • Scrapbook (Mac OS) – Macintosh computer software
  • Version control – Managing versions of source code or data
  • Web widget – Applet intended to be used within web pages

References

edit
  1. ^ "Gedit/Plugins/Snippets". Archived from the original on 2025-08-07. Retrieved 2025-08-07. Example of the feature in the Gedit editor.
  2. ^ Kim, Miryung; Bergman, Lawrence; Lau, Tessa; Notkin, David (2004). "An ethnographic study of copy and paste programming practices in OOPL" (PDF). Proceedings: 2004 International Symposium on Empirical Software Engineering, ISESE 2004: 19–20 August 2004, Redondo Beach, California. Los Alamitos, CA: IEEE. pp. 83–92. ISBN 978-0-7695-2165-7. OCLC 326620442. Archived from the original (PDF) on 19 October 2016. Retrieved 18 October 2016. For each C&P instance, we also noted the relationship between a copied code snippet and code elsewhere in the code base.
  3. ^ H. M. LE, TRIET; CHEN, HAO; ALI BABAR, MUHAMMAD (2021). "Deep Learning for Source Code Modeling and Generation". ACM Computing Surveys. 53 (3). The University of Adelaide: 1–38. arXiv:2002.05442. doi:10.1145/3383458. S2CID 211096967.
  4. ^ "GitHub previews new AI tool that makes coding suggestions". TechCrunch. 29 June 2021. Retrieved 2025-08-07.
日文是什么字 劳损是什么意思 万圣节为什么要送糖果 唾液酸苷酶阳性什么意思 法国的货币叫什么
大拇指脱皮是什么原因 男人容易出汗是什么原因造成的 什么的公园 唐僧念的紧箍咒是什么 02年属马的是什么命
什么是汉服 麦芽糖是什么做的 当今社会什么行业前途比较好 建议MRI检查是什么意思 什么是家庭
8月10号是什么星座 aquascutum是什么牌子 儿童看牙齿挂什么科 1947属什么生肖 发生火灾时的正确做法是什么
甲亢是什么回事hcv9jop7ns4r.cn 什么是对偶句hcv8jop7ns9r.cn 干咳是什么原因hcv8jop2ns9r.cn 爬山有什么好处hcv8jop2ns5r.cn 男生小肚子疼是什么原因520myf.com
滑板鞋是什么鞋96micro.com 十万个为什么内容hcv8jop6ns3r.cn 甲状腺什么原因引起的hcv8jop1ns9r.cn 皮肤黑穿什么颜色的衣服hcv8jop6ns0r.cn 匝道是什么hcv8jop9ns6r.cn
全身发烫但不发烧是什么原因hcv8jop3ns2r.cn 精神小伙什么意思hcv8jop1ns7r.cn 宝宝说话晚是什么原因造成的mmeoe.com 为什么崴脚了休息一晚脚更疼hebeidezhi.com 什么叫痤疮bfb118.com
为什么医者不自医aiwuzhiyu.com 减肥期间吃什么水果好hcv9jop5ns9r.cn 什么叫做脂肪肝hcv8jop2ns5r.cn 为什么冬天会下雪hcv9jop4ns8r.cn 引火下行是什么意思hcv8jop9ns6r.cn
百度