Python vs Java. You should read before starting the next project.

Technologiesthumb

    Few issues in software development are more controversial or conjunctual than the choice of programming language. Software developers often clearly identify their tools of choice, freely mixing objective facts with subjective preferences.

    However, in the last decade there has been an explosion of both the number of languages used in production and the number of languages that individual developers can use every day. This means that language is sometimes distributed more freely and widely in different code versions, frameworks and platforms. Modern projects and modern developers are increasingly using polyglot to use more languages and libraries than ever before. The original choice still plays a role.

    In this lively bazaar of programming languages, let’s focus on the two survivors in the 1990s who have completely different origins: Java and Python.

What we know about Python

    Python is the oldest of the two languages, first released in 1991 by its inventor Guido van Rossum. It has been open source since its inception. Foundation Python Software manages the design and standardization of the language and its libraries. The Python Enhancement Proposal (PEP) process manages its development.

    In the evolution of the programming language, it is customary to maintain backward compatibility for an indefinite period. This does not apply to Python. Python 2 originated in 2000, and Python 3 came on the scene in 2008. They are largely compatible, but they have enough differences in functionality and syntax, so they can be viewed as different languages. Instead of modifying new trends and ideas in Python 2 (complicating and compromising the language), Python 3 was conceived as a new language that used the experience of Python 2. Python 3-version 3.6 at the time of writing is where the current evolution exists and emphasis in the world of Python. The development of Python 2 continued separately, and its final implementation is version 2.7, which will no longer be supported after 2020.

    Python syntax embodies a readability philosophy with a simple and common style that encourages the brevity and consistency of code. It originated as a scripting language, embodying the philosophy of Unix in that it can create new programs from old ones, and also directly use existing code. This simplicity and convenience of work is provided by the dynamic Python system. This is an interpreted language available on many platforms, which makes it a portable option for general development.

    The Python implementation, written in C and known as CPython, is available on many platforms and is the most commonly used. Other groups have created their own implementations, such as IronPython, which are written in C # and provide tight integration with the .NET runtime.

    Python is a general-purpose language built around an extensible object model. Its object-oriented kernel does not necessarily mean that object orientation is the most common development style used in programming in Python. It supports procedural programming, modular programming, and some aspects of functional programming.

    The source of the name of the language is the British surreal comedy band Monty Python and this is the small amount of humor that is present in its documentation and libraries.

What we know about Java

    Although Java was not released until 1995, its history began in 1991. James Gosling and others at Sun Microsystems conceived the programming language for interactive television systems, which was released with advertising, that Java is a portable browser-based Internet language. Modern Java is far from this starting point and its original name: Oak.

    Also, Java, because it was too hard at that time to stay on the original TV target market, lost the niche of the browser language in the battle with dynamic HTML and JavaScript (which, despite its name, has nothing to do with the Java language). However, Java quickly found itself on the server and in education, which helped to ensure its rank as the dominant language at the turn of the millennium.

    Part of its attractiveness and value is its mobility and relative effectiveness. Although this is not a native language, such as C and C ++, Java is a compiled language. Its execution model is more machine-oriented than pure interpreted languages ​​such as Python and Perl. Java is more than just language and libraries: it is also a virtual machine and, therefore, an ecosystem. The Java Virtual Machine (JVM) is the ideal and portable platform for launching Java code. Instead of worrying about the specifics of the hardware and the need to port the code to new platforms, Java promises – write once, and run anywhere (Wora). This is so, because as long as the JVM is present, everything that is compiled into its bytecode can work and easily interact with anything written for the JVM. There are many JVM languages, including the more scripted Groovy, the functional Clojure, the object functional hybrid Scala and even the Python variant, Jython.

    Java is an object-oriented language with a C / C ++-like syntax that is familiar to many programmers. It is dynamically linked, allowing you to load and run new code, but not dynamically typing. The evolution of Java as a language has been relatively slow, and only recently Java has included functions that support functional programming. On the other hand, the philosophy of both the language and the virtual machine was to treat backwards compatibility as the main directive.

    After Oracle acquired Sun, the language and its compiler eventually became open. The development of the language is managed by the Java Community Process (JCP), which includes companies and individuals outside Oracle.

    So how do these two languages ​​relate? Let’s put everything in order.

Python vs Java speed

    Although performance is not always the main problem in software, it should always be considered. With the dominance of network input / output costs or access to the database, the specific effectiveness of the language is less significant than other aspects of the choice of technology and design when it comes to overall efficiency.

    Although neither Java nor Python is particularly suited for high-performance computing, for which performance is paramount, Java has an advantage over Python in terms of platform and design. Although some Python implementations, such as PyPy, are configured for performance, high-performance applications for a laptop computer, this is not the niche where Python can somehow compete.

    Most of the effectiveness of Java is achieved by optimizing the virtual machine. The JVM can translate the bytecode into its own machine code as the program executes. This Just-In-Time (JIT) compilation is due to the fact that Java performance can often compete with performance in native languages. Reliance on JIT is solved with enough tolerable offer of Oracle JVM by default HotSpot.

    Java supports parallelism from the first public version, whereas Python is more definitely a consistent language. This has implications for using current trends in multi-core processors, and Java code can more easily do this. Global Interpreter lock (GIL) in the dominant Python implementation, CPython, does not allow you to scale Python applications. Implementations of Python without GIL exist, but relying on them can conflict with some of the portability requirements that underlie Python code.

Compatibility

    Often the choice of language does not concern the design and internal qualities of the language itself. There are languages ​​for creating code, and this code has a context in business, economics, history, software architecture, skills and culture of development.

    Compatible systems have inertia around their existing technologies. Changes will be easier to follow the already established path, gradually and gradually increase, rather than rewrite and roll over. For example, the existing codebase of Python 2 is more likely to find a new life in Python 3 than in rewriting. The internal server of an existing Java project is likely to extend the functionality with more Java code, perhaps it will migrate to a more modern version of the language, or add new functions to other JVM languages ​​such as Scala and Groovy.

    The history of Java in the enterprise and its slightly more detailed coding style mean that inherited Java systems are usually larger and more numerous than the legacy of Python. On the other hand, you might be surprised to find out how many of the scripts and code of the connecting modules that integrate the enterprise IT infrastructure consist of Python. Both languages ​​have a compatibility problem, but usually it is represented in different ways.

Practical flexibility

    Culture and development trends have helped both Java and Python. Thanks to publications that have used Java as their lingua franca and Java-centric tools, Java is often perceived as a closer link to flexible development and its community. But no community is static and therefore easily redefined. Python has always been present in a flexible space and has grown in popularity for many reasons, including the growth of the DevOps movement.

    Java has more consistent support for refactoring than Python, so that, on the one hand, its static type makes automatic refactoring more predictable and reliable, and on the other hand, the prevalence of IDE in Java development (for example, IntelliJ, Eclipse and NetBeans). A more dynamic Python system encourages varying flexibility in code, focusing on brevity, fluidity and experimentation, where Java may be seen as a more stringent option. However, the same type system can become an obstacle to automated refactoring in Python. Pythonic culture prefers a wide range of editors, and is not based on IDE, which means that for it a strong automated support for refactoring is less than expected.

    The early popularity of JUnit and its connection with the development of testing (TDD) mean that of all languages ​​Java has, perhaps, the most consistent enthusiasm of developers for unit testing of any language. This was largely due to the inclusion of automatic JUnit in the IDE.

However, the origins of Python in scripts and the inclusion of test functions in a standard library mean that Python is not unaware of the automatic testing used in modern development, although it is often integration rather than unit testing.

Architecture

    Skills and existing software systems and their variations determine the programming languages ​​used in any given software architecture. Software architecture is also a matter of structure and libraries, reuse and integration. In many cases, it is technology that makes people make a choice of language, and not vice versa. The software architecture, conceived around the Python web infrastructure, was not far behind the architecture of the projects of the team using only Java.

    Both Java and Python use an endless supply of open source libraries filled with code from individuals and companies that have solved common and unusual problems and are happy to share so that others can take advantage of their solutions. Indeed, both languages ​​benefited from this and were formed by online forums and the development of open source.

    When all questions about compatibility, reuse, performance and development skills are completely learned, some architectural solutions can still leave language selection open. For example, the growth of microservice architectures (where Internet-centric systems are divided into small, interacting processes) make the choice of language more localized than the dominant considerations within the project.

    With all the diversity present in the modern programming landscape and its software architectures, some teams and companies prefer to cut some of their technologies, rather than live with the messy past decision-making and personal whim. But consolidation can reduce options, so this is not a solution that should be taken lightly. It is worthwhile to follow trends in languages ​​and structures to avoid wrong direction on the road fork.

Conclusion

    Java and Python have been used in programming for a long time. Along with their development communities, they have evolved and adapted since the 1990s, find new niches and replace other languages, sometimes competing in the same space. Both languages ​​are open-minded, so companies, teams and developers are best left out when it comes to making a decision.

    From the article it is clear that Java outperforms Python in performance, compatibility, flexibility and architecture. Python wins in quick learning and simplicity. In the field of education, Python is used in high school, and Java is used in higher education. What to choose? We’ll say the following: want a more perfect project then take Java. However if you want to sacrifice efficiency in favor of simplicity and cheapness – well then, Python is not the worst option.