Reusing codesnippets from online programming Q&A communities has become a common development practice, in which developers often need to adapt codesnippets to their code contexts to satisfy their own programming...
详细信息
Reusing codesnippets from online programming Q&A communities has become a common development practice, in which developers often need to adapt codesnippets to their code contexts to satisfy their own programming needs. However, how developers make these codeadaptations 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 codesnippet 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 codesnippet 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.
暂无评论