一句话:提出自动化范式分类技术,并对十万余个开源 Python 项目进行分析,发现面向对象范式占据主导。
Python 是一种多范式语言,同时支持面向对象、过程式、命令式与函数式等编程风格,但此前尚不清楚实际 Python 代码与项目中究竟以哪些范式为主。本文首先提出一种将 Python 源文件划分到其主导范式的分类技术,并将其自动化实现;随后通过人工判断对该方法进行评估,两者一致率超过 80%。在此基础上,作者对超过 10 万个开源 Python 项目进行自动逐文件分类,并统计范式分布。结果显示,Python 开发者明显更偏好面向对象特性;面向对象与过程式范式的使用同项目规模呈正相关;尽管以函数式范式为主的文件或项目很少,但函数式特性的使用仍相当广泛。
Python is a multi-paradigm programming language that fully supports object-oriented (OO) programming. The language allows writing code in a non-procedural imperative manner, using procedures, using classes, or in a functional style. To date, no one has studied what paradigm(s), if any, are predominant in Python code and projects. In this work, we first define a technique to classify Python files into predominant paradigm(s). We then automate our approach and evaluate it against human judgements, showing over 80% agreement. We then analyze over 100k open-source Python projects, automatically classifying each source file and investigating the paradigm distributions. The results indicate Python developers tend to heavily favor OO features. We also observed a positive correlation between OO and procedural paradigms and the size of the project. And despite few files or projects being predominantly functional, we still found many functional feature uses.