清晨好,您是今天最早来到科研通的研友!由于当前在线用户较少,发布求助请尽量完整的填写文献信息,科研通机器人24小时在线,伴您科研之路漫漫前行!

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.
最长约 10秒,即可获得该文献文件

科研通智能强力驱动
Strongly Powered by AbleSci AI
科研通是完全免费的文献互助平台,具备全网最快的应助速度,最高的求助完成率。 对每一个文献求助,科研通都将尽心尽力,给求助人一个满意的交代。
实时播报
凌露完成签到 ,获得积分0
1秒前
兔孖完成签到,获得积分10
14秒前
14秒前
兔孖发布了新的文献求助10
20秒前
一早完成签到 ,获得积分10
43秒前
chichenglin完成签到 ,获得积分10
46秒前
迅速千愁完成签到 ,获得积分10
55秒前
无悔完成签到 ,获得积分10
56秒前
自然之水完成签到,获得积分10
1分钟前
1分钟前
soong完成签到 ,获得积分10
1分钟前
个性仙人掌完成签到 ,获得积分10
1分钟前
谨慎鹏涛完成签到 ,获得积分10
1分钟前
甜甜的tiantian完成签到 ,获得积分10
2分钟前
Tong完成签到,获得积分0
2分钟前
2分钟前
volvoamg发布了新的文献求助10
2分钟前
迅速的幻雪完成签到 ,获得积分10
2分钟前
creep2020完成签到,获得积分10
3分钟前
3分钟前
光合作用完成签到,获得积分10
3分钟前
科研通AI2S应助太阳花采纳,获得30
3分钟前
愉快若剑发布了新的文献求助10
4分钟前
TOUHOUU完成签到 ,获得积分10
4分钟前
希望天下0贩的0应助zzy采纳,获得10
4分钟前
赧赧完成签到 ,获得积分10
4分钟前
任伟超完成签到,获得积分10
4分钟前
李鹏辉完成签到 ,获得积分10
5分钟前
传奇3应助科研通管家采纳,获得10
5分钟前
科研通AI2S应助科研通管家采纳,获得10
5分钟前
老刘Diamond完成签到,获得积分10
6分钟前
袁雪蓓完成签到 ,获得积分10
6分钟前
元气饱满完成签到 ,获得积分10
6分钟前
笨笨完成签到 ,获得积分10
6分钟前
碧蓝香芦完成签到 ,获得积分10
6分钟前
song完成签到 ,获得积分10
7分钟前
7分钟前
zzy发布了新的文献求助10
7分钟前
aiyawy完成签到 ,获得积分10
7分钟前
Emperor完成签到 ,获得积分0
8分钟前
高分求助中
Introduction to Strong Mixing Conditions Volumes 1-3 500
Tip60 complex regulates eggshell formation and oviposition in the white-backed planthopper, providing effective targets for pest control 400
Optical and electric properties of monocrystalline synthetic diamond irradiated by neutrons 320
共融服務學習指南 300
Essentials of Pharmacoeconomics: Health Economics and Outcomes Research 3rd Edition. by Karen Rascati 300
Peking Blues // Liao San 300
Political Ideologies Their Origins and Impact 13 edition 240
热门求助领域 (近24小时)
化学 材料科学 医学 生物 工程类 有机化学 物理 生物化学 纳米技术 计算机科学 化学工程 内科学 复合材料 物理化学 电极 遗传学 量子力学 基因 冶金 催化作用
热门帖子
关注 科研通微信公众号,转发送积分 3800957
求助须知:如何正确求助?哪些是违规求助? 3346489
关于积分的说明 10329482
捐赠科研通 3063031
什么是DOI,文献DOI怎么找? 1681328
邀请新用户注册赠送积分活动 807463
科研通“疑难数据库(出版商)”最低求助积分说明 763714