How do Developers Adapt Code Snippets to Their Contexts? An Empirical Study of Context-Based Code Snippet Adaptations

计算机科学 代码段 编码(集合论) 背景(考古学) 程序设计语言 实证研究 万维网 生物 认识论 哲学 古生物学 集合(抽象数据类型)
作者
Tanghaoran Zhang,Yao Lu,Yue Yu,Xinjun Mao,Yang Zhang,Yuxin Zhao
出处
期刊:IEEE Transactions on Software Engineering [IEEE Computer Society]
卷期号:50 (11): 2712-2731 被引量:1
标识
DOI:10.1109/tse.2024.3395519
摘要

Reusing code snippets from online programming Q&A communities has become a common development practice, in which developers often need to adapt code snippets to their code contexts to satisfy their own programming needs. However, how developers make these code adaptations based on contexts is still unclear. To bridge this gap, we first conduct a semi-structured interview of 21 developers to investigate their adaptation practices and perceived challenges during this process. The result suggests that code snippet adaptation is a challenging and exhausting task for developers, as they should tailor the snippets to guarantee their correctness and quality with laborious work. We also note that developers all resort to their intra-file context to complete adaptations, which motivates us to further study how developers performed context-based adaptations (CAs) in real scenarios. To this end, we conduct a quantitative study on an adaptation dataset comprising 300 code snippet reuse cases with 1,384 adaptations from Stack Overflow to GitHub. For each adaptation, we manually annotate its intention and relationship with the context. Based on our annotated data, we employ frequent itemset mining to obtain four CA patterns from our dataset, including Fortification , Code Wiring , Attribute-ization and Parameterization . Our main findings reveal that: (1) more than half of the code snippet reuse cases include CAs and 23.3% of the adaptations are CAs; (2) more than half of the CAs are corrective adaptations and variable is the primary adapted language construct; (3) attribute is the most frequently utilized context and 88% of the local contexts are within the nearest 10 LOCs; and (4) CAs towards different intentions are repetitive, which are useful for automatic adaptation. Overall, our study provides valuable insights into code snippet adaptation and has important implications for research, practice, and tool design.

科研通智能强力驱动
Strongly Powered by AbleSci AI
科研通是完全免费的文献互助平台,具备全网最快的应助速度,最高的求助完成率。 对每一个文献求助,科研通都将尽心尽力,给求助人一个满意的交代。
实时播报
所所应助Nike采纳,获得10
刚刚
JamesPei应助Nike采纳,获得10
刚刚
小马甲应助Nike采纳,获得10
刚刚
Orange应助Nike采纳,获得10
刚刚
小地蛋完成签到 ,获得积分10
刚刚
刚刚
情怀应助Nike采纳,获得10
刚刚
bkagyin应助Nike采纳,获得10
刚刚
我是老大应助Nike采纳,获得10
刚刚
田様应助Nike采纳,获得10
刚刚
Hello应助Nike采纳,获得10
刚刚
星辰大海应助静子采纳,获得10
1秒前
顺利毕叶发布了新的文献求助10
1秒前
iquwtony发布了新的文献求助10
1秒前
1秒前
3秒前
5秒前
小鹿完成签到,获得积分10
6秒前
结实凌瑶完成签到 ,获得积分10
8秒前
9秒前
9秒前
小札过发布了新的文献求助10
9秒前
10秒前
千里发布了新的文献求助10
10秒前
顺利毕叶完成签到,获得积分10
11秒前
11秒前
12秒前
Nae完成签到,获得积分10
12秒前
星辰大海应助机智的巧凡采纳,获得10
12秒前
河狸发布了新的文献求助20
13秒前
14秒前
田様应助孙困采纳,获得10
14秒前
14秒前
Ava应助Lee采纳,获得10
15秒前
16秒前
16秒前
一键变瘦发布了新的文献求助10
17秒前
18秒前
包容映安完成签到,获得积分10
18秒前
18秒前
高分求助中
(应助此贴封号)【重要!!请各用户(尤其是新用户)详细阅读】【科研通的精品贴汇总】 10000
The Cambridge History of China: Volume 4, Sui and T'ang China, 589–906 AD, Part Two 1500
Cowries - A Guide to the Gastropod Family Cypraeidae 1200
Quality by Design - An Indispensable Approach to Accelerate Biopharmaceutical Product Development 800
Pulse width control of a 3-phase inverter with non sinusoidal phase voltages 777
Signals, Systems, and Signal Processing 610
Research Methods for Applied Linguistics: A Practical Guide 600
热门求助领域 (近24小时)
化学 材料科学 医学 生物 纳米技术 工程类 有机化学 化学工程 生物化学 计算机科学 物理 内科学 复合材料 催化作用 物理化学 光电子学 电极 细胞生物学 基因 无机化学
热门帖子
关注 科研通微信公众号,转发送积分 6400805
求助须知:如何正确求助?哪些是违规求助? 8217669
关于积分的说明 17414982
捐赠科研通 5453838
什么是DOI,文献DOI怎么找? 2882311
邀请新用户注册赠送积分活动 1858934
关于科研通互助平台的介绍 1700618