Does Python Smell Like Java?
Written by Alex Armstrong   
Tuesday, 04 April 2017

A very interesting question. Python is so very different from Java but does it suffer from the same flaws?  New research from the University of Amsterdam and Raincode Labs Belgium looks into the question of whether or not Python has the same problem with code "smells" as Java.

In case you have missed the meaning of a "smell" it comes from the agile community and basically means something isn't right - its an indication that an antipattern might be lurking.

The context of this work is specification, detection and ultimately removal of detectable harmful patterns in source code that are associated with defects in design and implementation of software. In particular, we investigate five code smells and four antipatterns previously defined in papers and books.

Our inquiry is about detecting those in source code written in Python programming language, which is substantially different from all prior research, most of which concerns Java or C-like languages. Our approach was that of software engineers: we have processed existing research literature on the topic, extracted both the abstract definitions of nine design defects and their concrete implementation specifications, implemented them all in a tool we have programmed and let it loose on a huge test set obtained from open source code from thousands of GitHub projects.

When it comes to knowledge, we have found that more than twice as many methods in Python can be considered too long (statistically extremely longer than their neighbours within the same project) than in Java, but long parameter lists are seven times less likely to be found in Python code than in Java code.

We have also found that Functional Decomposition, the way it was defined for Java, is not found in the Python code at all, and Spaghetti Code and God Classes are extremely rare there as well.

The grounding and the confidence in these results comes from the fact that we have performed our experiments on 32'058'823 lines of Python code, which is by far the largest test set for a freely available Python parser. We have also designed the experiment in such a way that it aligned with prior research on design defect detection in Java in order to ease the comparison if we treat our own actions as a replication.

Thus, the importance of the work is both in the unique open Python grammar of highest quality, tested on millions of lines of code, and in the design defect detection tool which works on something else than Java.



So Python sort of smells like Java, but with some interesting differences. The detailed conclusions are:

  • No occurrences at all of Functional Decomposition and barely any of God Class and Spaghetti Code

    A God Class is an antipattern that consists of one complex class, possibly surrounded by multiple Data Classes. The complex class monopolises all the processing, while the only responsibility of the Data Classes is to encapsulate data. Could it be that God classes are rare because Python programmers don't do object oriented programming? And have you tried writing spaghetti code in Python? Its structure and use of meaningful white space makes it much harder. 
  • Significantly lower density of Long Parameter Lists in Python than in Java

    One possible reason is the availability of, and tendency to use, complex objects as function inputs and outputs.
  • Significantly higher density of Long Methods in Python than in Java

    Again a lack of really embracing object philosophy might explain this. It might also link to the lower density of long parameter lists. High level super functions tend to take only a few parameters. 

  • Relatively comparable densities for Large Classes and Swiss Army Knives.

    Swiss Army Knife is an antipattern for a class with too many responsibilities and it is an aspect of the same tendency as creation of large classes. Another smell explained by lack of good object oriented philosophy.

 So Python smells like Java:

Do Java code and Python code have comparable design defects?
Since we have been able to detect the majority of the design defects that have previously been detected by others in Java source code, we conclude that similar design defects can be detected in Java and Python source code.




More Information

Does Python Smell Like Java? Tool Support for Design Defect Discovery in Python

Related Articles

Choosing The Best Beginner's Programming Language 

Free Python Courses From Alison 

In Praise of Top Down Programming 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.




Microsoft Introduces .NET Smart Components

Microsoft has provided a set of .NET Smart Components, described as a set of genuinely useful AI-powered UI components that you can quickly and easily add to .NET apps. The components are prebuilt end [ ... ]

Can C++ Be As Safe As Rust?

Herb Sutter is a well known and respected C++ champion and he thinks that the language only needs a few tweaks to make it as safe as Rust. Can this be true?

More News


raspberry pi books



or email your comment to:


Last Updated ( Tuesday, 04 April 2017 )