Don't Call Us, We'll Call You: Characterizing Callbacks in Javascript

Keheliya Gallaba, A. Mesbah, Ivan Beschastnikh
{"title":"Don't Call Us, We'll Call You: Characterizing Callbacks in Javascript","authors":"Keheliya Gallaba, A. Mesbah, Ivan Beschastnikh","doi":"10.1109/ESEM.2015.7321196","DOIUrl":null,"url":null,"abstract":"JavaScript is a popular language for developing web applications and is increasingly used for both client-side and server-side application logic. The JavaScript runtime is inherently event-driven and callbacks are a key language feature. Unfortunately, callbacks induce a non-linear control flow and can be deferred to execute asynchronously, declared anonymously, and may be nested to arbitrary levels. All of these features make callbacks difficult to understand and maintain. We perform an empirical study to characterize JavaScript callback usage across a representative corpus of 138 JavaScript programs, with over 5 million lines of JavaScript code. We find that on average, every 10th function definition takes a callback argument, and that over 43% of all callback-accepting function callsites are anonymous. Furthermore, the majority of callbacks are nested, more than half of all callbacks are asynchronous, and asynchronous callbacks, on average, appear more frequently in client-side code (72%) than server-side (55%). We also study three well-known solutions designed to help with the complexities associated with callbacks, including the error-first callback convention, Async.js library, and Promises. Our results inform the design of future JavaScript analysis and code comprehension tools.","PeriodicalId":258843,"journal":{"name":"2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM)","volume":"24 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2015-11-09","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"52","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM)","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1109/ESEM.2015.7321196","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 52

Abstract

JavaScript is a popular language for developing web applications and is increasingly used for both client-side and server-side application logic. The JavaScript runtime is inherently event-driven and callbacks are a key language feature. Unfortunately, callbacks induce a non-linear control flow and can be deferred to execute asynchronously, declared anonymously, and may be nested to arbitrary levels. All of these features make callbacks difficult to understand and maintain. We perform an empirical study to characterize JavaScript callback usage across a representative corpus of 138 JavaScript programs, with over 5 million lines of JavaScript code. We find that on average, every 10th function definition takes a callback argument, and that over 43% of all callback-accepting function callsites are anonymous. Furthermore, the majority of callbacks are nested, more than half of all callbacks are asynchronous, and asynchronous callbacks, on average, appear more frequently in client-side code (72%) than server-side (55%). We also study three well-known solutions designed to help with the complexities associated with callbacks, including the error-first callback convention, Async.js library, and Promises. Our results inform the design of future JavaScript analysis and code comprehension tools.
不要打电话给我们,我们会打电话给你:描述Javascript中的回调
JavaScript是一种开发web应用程序的流行语言,越来越多地用于客户端和服务器端应用程序逻辑。JavaScript运行时本质上是事件驱动的,回调是一个关键的语言特性。不幸的是,回调会导致非线性控制流,并且可以延迟到异步执行,匿名声明,并且可以嵌套到任意级别。所有这些特性都使得回调难以理解和维护。我们进行了一项实证研究,以表征138个JavaScript程序的代表性语料库中JavaScript回调的使用情况,其中包含超过500万行JavaScript代码。我们发现,平均每10个函数定义就有一个回调参数,并且超过43%的接受回调的函数调用点是匿名的。此外,大多数回调都是嵌套的,超过一半的回调都是异步的,而且异步回调在客户端代码中出现的频率(72%)比在服务器端代码中出现的频率(55%)更高。我们还研究了三种众所周知的解决方案,它们旨在帮助解决与回调相关的复杂性,包括错误优先回调约定、Async.js库和Promises。我们的研究结果为未来JavaScript分析和代码理解工具的设计提供了参考。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信