The Good, the Bad, and the Ugly: An Empirical Study of Implicit Type Conversions in JavaScript

Authors Michael Pradel, Koushik Sen



PDF
Thumbnail PDF

File

LIPIcs.ECOOP.2015.519.pdf
  • Filesize: 0.53 MB
  • 23 pages

Document Identifiers

Author Details

Michael Pradel
Koushik Sen

Cite AsGet BibTex

Michael Pradel and Koushik Sen. The Good, the Bad, and the Ugly: An Empirical Study of Implicit Type Conversions in JavaScript. In 29th European Conference on Object-Oriented Programming (ECOOP 2015). Leibniz International Proceedings in Informatics (LIPIcs), Volume 37, pp. 519-541, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2015)
https://doi.org/10.4230/LIPIcs.ECOOP.2015.519

Abstract

Most popular programming languages support situations where a value of one type is converted into a value of another type without any explicit cast. Such implicit type conversions, or type coercions, are a highly controversial language feature. Proponents argue that type coercions enable writing concise code. Opponents argue that type coercions are error-prone and that they reduce the understandability of programs. This paper studies the use of type coercions in JavaScript, a language notorious for its widespread use of coercions. We dynamically analyze hundreds of programs, including real-world web applications and popular benchmark programs. We find that coercions are widely used (in 80.42% of all function executions) and that most coercions are likely to be harmless (98.85%). Furthermore, we identify a set of rarely occurring and potentially harmful coercions that safer subsets of JavaScript or future language designs may want to disallow. Our results suggest that type coercions are significantly less evil than commonly assumed and that analyses targeted at real-world JavaScript programs must consider coercions.
Keywords
  • Types
  • Type coercions
  • JavaScript
  • Dynamically typed languages

Metrics

  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    0
    PDF Downloads

References

  1. Oscar Callaú, Romain Robbes, Éric Tanter, and David Röthlisberger. How (and why) developers use the dynamic features of programming languages: the case of smalltalk. Empirical Software Engineering, 18(6):1156-1194, 2013. Google Scholar
  2. Ravi Chugh, David Herman, and Ranjit Jhala. Dependent types for JavaScript. In Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 587-606, 2012. Google Scholar
  3. Douglas Crockford. JavaScript: The Good Parts. O'Reilly, 2008. Google Scholar
  4. Michael Furr, Jong-hoon (David) An, and Jeffrey S. Foster. Profile-guided static typing for dynamic scripting languages. In Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 283-300. ACM, 2009. Google Scholar
  5. Mark Grechanik, Collin McMillan, Luca DeFerrari, Marco Comi, Stefano Crespi-Reghizzi, Denys Poshyvanyk, Chen Fu, Qing Xie, and Carlo Ghezzi. An empirical investigation into a large-scale Java open source code repository. In Symposium on Empirical Software Engineering and Measurement (ESEM), 2010. Google Scholar
  6. Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. Typing local control and state using flow analysis. In European Symposium on Programming (ESOP), pages 256-275, 2011. Google Scholar
  7. Stefan Hanenberg. An experiment about static and dynamic type systems: doubts about the positive impact of static type systems on development time. In Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA), pages 22-35, 2010. Google Scholar
  8. Phillip Heidegger and Peter Thiemann. Recency types for analyzing scripting languages. In European Conference on Object-Oriented Programming (ECOOP), pages 200-224, 2010. Google Scholar
  9. Alex Holkner and James Harland. Evaluating the dynamic behaviour of Python applications. In Australasian Computer Science Conference (ACSC), pages 17-25, 2009. Google Scholar
  10. Ecma International. ECMAScript language specification, 5.1 edition, June 2011. Google Scholar
  11. Simon Holm Jensen, Anders Møller, and Peter Thiemann. Type analysis for JavaScript. In Symposium on Static Analysis (SAS), pages 238-255. Springer, 2009. Google Scholar
  12. Donald E. Knuth. An empirical study of FORTRAN programs. Software Practice and Experience, pages 105-133, 1971. Google Scholar
  13. Donna Malayeri and Jonathan Aldrich. Is structural subtyping useful? An empirical study. In European Symposium on Programming (ESOP), pages 95-111, 2009. Google Scholar
  14. Radu Muschevici, Alex Potanin, Ewan D. Tempero, and James Noble. Multiple dispatch in practice. In Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 563-582, 2008. Google Scholar
  15. Nick Nikiforakis, Luca Invernizzi, Alexandros Kapravelos, Steven Van Acker, Wouter Joosen, Christopher Kruegel, Frank Piessens, and Giovanni Vigna. You are what you include: large-scale evaluation of remote JavaScript inclusions. In CCS, pages 736-747, 2012. Google Scholar
  16. Frolin S. Ocariza Jr., Kartik Bajaj, Karthik Pattabiraman, and Ali Mesbah. An empirical study of client-side JavaScript bugs. In Symposium on Empirical Software Engineering and Measurement (ESEM), pages 55-64, 2013. Google Scholar
  17. Frolin S. Ocariza Jr., Karthik Pattabiraman, and Benjamin G. Zorn. JavaScript errors in the wild: An empirical study. In International Symposium on Software Reliability Engineering (ISSRE), pages 100-109, 2011. Google Scholar
  18. Veselin Raychev, Martin T. Vechev, and Andreas Krause. Predicting program properties from "big code". In Principles of Programming Languages (POPL), pages 111-124, 2015. Google Scholar
  19. Gregor Richards, Andreas Gal, Brendan Eich, and Jan Vitek. Automated construction of JavaScript benchmarks. In Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 677-694, 2011. Google Scholar
  20. Gregor Richards, Christian Hammer, Brian Burg, and Jan Vitek. The eval that men do - a large-scale study of the use of eval in JavaScript applications. In European Conference on Object-Oriented Programming (ECOOP), pages 52-78, 2011. Google Scholar
  21. Gregor Richards, Sylvain Lebresne, Brian Burg, and Jan Vitek. An analysis of the dynamic behavior of JavaScript programs. In Conference on Programming Language Design and Implementation (PLDI), pages 1-12, 2010. Google Scholar
  22. Koushik Sen, Swaroop Kalasapur, Tasneem Brutch, and Simon Gibbs. Jalangi: A selective record-replay and dynamic analysis framework for JavaScript. In European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE), pages 488-498, 2013. Google Scholar
  23. Ewan D. Tempero. How fields are used in Java: An empirical study. In Australian Software Engineering Conference (ASWEC), pages 91-100, 2009. Google Scholar
  24. Ewan D. Tempero, James Noble, and Hayden Melton. How do Java programs use inheritance? An empirical study of inheritance in Java software. In European Conference on Object-Oriented Programming (ECOOP), pages 667-691. Springer, 2008. Google Scholar
  25. Peter Thiemann. Towards a type system for analyzing JavaScript programs. In European Symposium on Programming (ESOP), pages 408-422, 2005. Google Scholar
Questions / Remarks / Feedback
X

Feedback for Dagstuhl Publishing


Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail