Python Hands-on

What is Python? Everything you need to know

Why the Python programming language shines for data science, machine learning, systems automation, web and API development, and beyond

1 2 Page 2
Page 2 of 2

Python for .Net and Java developers. Editions of Python exist that run the .Net and Java Virtual Machine runtimes—IronPython and Jython, respectively. Both of them allow Python to interoperate with other languages on their respective runtimes—such as an IronPython app can interoperate with .Net classes. Jython development hasn’t budged much in the last couple of years, but work on IronPython has been rejuvenated with a new development team.

Is Python too slow?

One common caveat about Python is that it’s slow. Objectively, it’s true. Python programs generally run much more slowly than corresponding programs in C/C++ or Java. Some Python programs will be slower by an order of magnitude or more.

Why so slow? It isn’t just because most Python runtimes are interpreters rather than compilers. It is also due to the fact that the inherent dynamism and the malleability of objects in Python make it difficult to optimize the language for speed, even when it is compiled. That said, Python’s speed may not be as much of an issue as it might seem, and there are ways to alleviate it.

Python has many routes for speed optimization. It isn’t always the fate of a slow Python program to be forever slow. Many Python programs are slow because they don’t properly leverage the functionality present in Python or its standard library. Math and statistics operations can be boosted tremendously by way of libraries such as NumPy and Pandas, and the PyPy runtime can provide orders-of-magnitude speedups for many Python apps.

A common adage of software development is that 90 percent of the activity for a program tends to be in 10 percent of the code, so optimizing that 10 percent can yield major improvements. With Python, you can selectively convert that 10 percent to C or even assembly, by way of projects like Cython or Numba. The end result is often a program that runs within striking distance of a counterpart written entirely in C, but without being cluttered with C’s memory micromanagement details.

In Python, developer time is usually far more valuable than machine time. Or to put it another way: For many tasks, speed of development beats speed of execution.

A given Python program might take six seconds to execute versus a fraction of a second in another language. But it might take only ten minutes for a developer to put that Python program together, versus an hour or more of development time in another language. The amount of time lost in the execution of the Python program is more than gained back by the time saved in the development process.

Obviously, this is less true when you’re writing software that has high-throughput, low-concurrency demands, such as a trading application. But for many real-world applications, in domains ranging from systems management to machine learning, Python will prove to be rich enough and fast enough for the job. And the flexibility and pace of development that Python enables may allow for innovation that would be more difficult and time-consuming to achieve in other languages.

When speed of development and programmer comfort are more important than shaving a few seconds off the machine clock, Python may well be the best tool for the job.

1 2 Page 2
Page 2 of 2