Why Julia and Swift Programming Languages Will Squeeze Python
Python was released in the 1990s as a general-purpose programming language. Despite its clean syntax, the exposure Python got in its first decade wasn’t encouraging, and it didn’t really find inroads into the developer’s workspace. Perl was the first-choice scripting language and Java had established itself as the go-to in the object-oriented programming arena. Of course, any language takes time to mature and only gets adopted when it’s better suited to a task than the existing tools.
Fast forward to the present, and Python has trumped Java to become the second-most-popular language according to the StackOverflow Developer Survey 2019. It was also the fastest-growing programming language of the previous decade. Python’s rise in popularity has a lot to do with the emergence of big data in the 2010s as well as developments in machine learning and artificial intelligence. Businesses urgently required a language for quick development with low barriers of entry that could help manage large-scale data and scientific computing tasks. Python was well-suited to all these challenges.
Besides having those factors in its favor, Python was an interpreted language with dynamic typing support. More importantly, it had the backing of Google, which had invested in Python for Tensorflow, which led to its emergence as the preferred language for data analysis, visualization, and machine learning.
Yet, despite the growing demand for machine learning and AI at the turn of this decade, Python won’t stay around for long. Like every programming language, it has its own set of weaknesses. Those weaknesses make it vulnerable to replacement by languages more suited to the common tasks businesses ask of them. Despite the presence of R, the emergence of newer languages such as Swift, Julia, and Rust actually poses a bigger threat to the current king of data science.
Rust is still trying to catch up with the machine learning community, and so I believe Swift and Julia are the languages that will dethrone Python and eventually rule data science. Let’s see why odds are against Python.
Python Lacks Type-Safety and Is Super Slow
All good things come at a cost, and Python’s dynamically typed nature is no exception. It hampers developers, especially when running the code in production. Dynamic typing that makes it easy to write code quickly without defining types increases the risk of running into runtime issues, especially when the codebase size increases. Bugs that a compiler would easily figure out could go unidentified in Python, causing hindrances in production and ultimately slowing the development process in large-scale applications.
Worse, unlike compiled code, Python’s interpreter analyzes every line of code at execution time. This leads to an overhead that causes a significantly slower performance when compared to other languages.
Julia allows you to avoid some of these problems. Despite being dynamically typed, it has a just-in-time compiler. The JIT compiler either generates the machine code right before it’s executed or uses previously stored, cached compilations, which makes it as performant as statically typed languages. More importantly, it has a key feature known as multiple dispatch that is like function overloading of OOPs, albeit at runtime. The power of multiple dispatch lies in its ability to handle different argument types without the need to create separate function names or nested if statements. This helps in writing compact code, which is a big win in numeric computations since, unlike Python, you can easily scale solutions to deal with all types of arguments.
Even better, Swift is a statically typed language and is highly optimized due to its LLVM (Low-Level Virtual Machine) compiler. The LLVM makes it possible to quickly compile into assembly code, making Swift super-efficient and almost as fast as C. Also, Swift boasts better memory safety and management tools known as Automatic Reference Counting. Unlike garbage collectors, ARC is a lot more deterministic as it reclaims memory whenever the reference count hits zero.
As compiled languages that offer type annotations, Swift and Julia are a lot faster and robust for development than Python. That alone might be enough to recommend them over the older language, but there are other factors to consider as well.
Python Has Limitations in Parallelism
If slowness was not the most obvious drawback of Python, the language also has limitations with parallel computing.
In short, Python uses GIL (Global Interpreter Lock), which prevents multiple threads from executing at the same time in order to boost the performance of single threads. This process is a big hindrance because it means that developers cannot use multiple CPU cores for intensive computing.
I agree with the commonplace notion that we’re currently doing fine when leveraging Python’s interoperability with C/C++ libraries like Tensorflow and PyTorch. But a Python wrapper doesn’t solve all debugging issues. Ultimately, when inspecting the underlying low-level code, we’re falling back on C and C++. Essentially, we can’t leverage the strengths of Python at the low level, which puts it out of the picture.
This factor will soon play a decisive role in the fall of Python and rise of Julia and Swift. Julia is a language exclusively designed to address the shortcomings of Python. It primarily offers three features: coroutines (asynchronous tasks), multi-threading, and distributed computing — all of which only show the immense possibilities for concurrent and parallel programming. This structure makes Julia capable of performing scientific computations and solving big data problems at a far greater speed than Python.
On the other hand, Swift possesses all the tools required for developing mobile apps and has no problems with parallel computing.
Swift and Julia Have Python’s Interoperability and Strong Support in Their Favor
Despite the disadvantages it has with respect to speed, multi-threading, and type-safety, Python still has a huge ecosystem that boasts an enormous set of libraries and packages. Understandably, Swift and Julia are still infants in the field of machine learning and possess only a limited number of libraries. Yet, their interoperability with Python more than compensates for the lack of library support in Julia and Swift.
Julia not only lets programmers use Python code (and vice-versa), but also supports interoperability with C, R, Java, and almost every major programming language. This versatility would certainly give the language a good boost and increase its chances of a quick adoption among data scientists.
Swift, on the other hand, provides interoperability with Python with the PythonKit library. The biggest selling point for Swift (which has an Apple origin) is a strong support it’s been getting from Google, who fully backed Python decades ago. See how the tables have turned!
Also, the fact that the creator of Swift, Chris Lattner, is now working on Google’s AI brain team just shows that Swift is being seriously groomed as Python’s replacement in the machine learning field. The Tensorflow team investing in Swift with its S4TF project only further proves that the language isn’t merely regarded as a wrapper over Python. Instead Swift, thanks to its differential programming support and ability to work at a low level like C, will potentially be used to replace the underlying deep learning tools.
As the size of data continues to increase, Python’s Achilles heel will be soon found out. Gone are the days when ease of use and ability to write code quickly mattered. Speed and parallel computing are the name of the game and Python, which is a more general-purpose language, will no longer solve that problem. Inevitably, it will fade away while Julia and Swift seem like the candidates to take over the reins.
It’s important to note that Python as a programming language won’t disappear any time soon. Instead, it’ll only take a backseat in data science as the languages that are more specifically designed for deep learning will rule.