Skip to content

Instantly share code, notes, and snippets.

@alexdelorenzo
Last active March 29, 2018 05:55
Show Gist options
  • Save alexdelorenzo/3a970d055551e7bfb1c2969e9880cd1c to your computer and use it in GitHub Desktop.
Save alexdelorenzo/3a970d055551e7bfb1c2969e9880cd1c to your computer and use it in GitHub Desktop.

Why Python is Making a Comeback

Since the advent of nodeJS, you may have experienced something called Javascript-fatigue: the natural exhaustion one feels in response to the influx of new Javascript modules and developers putting Javascript everywhere - your phone, your car, your toaster - instead of just the web. For a while, it seemed that Javascript would eat the world.

However, over the past few years, an underdog has silently established itself as a cogent solution in both mainstream and niche spaces. Not only has it proved its mettle seemingly overnight, developers are adopting it fast.

Growth of Popular Programming Languages Over a Six Year Period - Courtesy of StackOverflow

Enter Python. A dynamic, strongly-typed programming language with a well-deserved reputation of having a beautifully concise, yet expressive, syntax. One might even say that Python code is executable pseudocode.

Python's popularity has exploded in a relatively short timespan. A myriad of reasons exist that can easily explain this upsurge in adoption, all of which go far beyond the simple fact that snakes are cool.

Ease of Use

Rapid prototyping and development are arguably Python's mainstay. Boilerplate and cruft that are all too familiar in Java development Need Not Apply: Python doesn't want or need it. This is a language that aids, and doesn't hinder, a developer's ability to actualize their billion dollar ideas in code.

Like many other dynamic scripting languages, Python takes care of low-level details that a developer might handle on their own in another language.

Python manages memory automatically and includes a garbage collector to that end. No more having to be mindful of the call-stack, heap, or issuing malloc() and free() appropriately when writing code! Forget worrying about buffer overflows, Python shields the developer from the mindless minutiae that enable this class of exploits.

The language doesn't require explicit typing, yet it maintains a strongly-typed runtime which ensures that this won't happen in your Python project:

let stringOrNumber = 1 + "1";
console.log(stringOrNumber);
// stdout: "11"

Whoa there! Behind the scenes Javascript coerced a numeric type into a string so that it could be concatenated with another string.

Let's see what happens in PHP.

$stringOrNumber = 1 + "1";
echo $stringOrNumber;
// stdout: 2

Strange. In this case, the string "1" was type-coerced into an int so that it could be added to the trailing numerical 1.

Truthfully, unexpected results are scary. I would hope that the runtime would catch such a programmer error so that it doesn't go unnoticed.

try:
	string_or_number = 1 + "1"
	print(string_or_number)

except Exception as e:
	print(e.__class__.__name__, e)

# stdout: TypeError unsupported operand type(s) for +: 'int' and 'str'

Ease of development is further aided by Python's rich ecosystem of modules split between its standard library and 3rd party add-ons. That means you won't have to roll your own implementation of commonly used code.

Take a look at this example, where we print a string to stdout in Java.

public class HelloWorld
{
    public static void main (String[] args)
    {
        System.out.println("Hello, world!");
    }
}

There's an absurd amount of boilerplate for what is a simple task.

Now, look at how easy it is to accomplish the same thing in Python.

print("Hello, world!")

It's exceedingly clear why a developer, novice or expert, might favor Python over more verbose languages.

The Numbers Guys and Academics are Getting Their Hands Dirty with Python, Too

Python's lavish ecosystem can almost ensure that there's a module for that. This rich repository of Python libraries has proven to be invaluable in finance, bioinformatics, data science and analytics, machine learning and academia.

Libraries like pandas, NumPy, sciKit.learn, TensorFlow and matplotlib are worthy competition to former industry staples, such as MatLab and R. Combined with Python's easy to learn (and to love!) syntax, these modules have enabled an era of rapid data processing for researchers, quants and other analysts.

As an interpreted language with a Global Interpreter Lock (GIL), Python can be slow at times. Brilliant mitigation solutions exist to address this problem: both a C extension interface and a C foreign function interface are provided in the Python standard distribution.

If code must run close to the metal for performance reasons, the C extension interface can be used to write importable Python modules in C/C++. For existing software written in C/C++, Python allows developers to load foreign libraries and call them within Python code. If you have a masochistic streak, C extensions allow you to sidestep the GIL (but why do that when multiprocessing exists in the standard library?).

The C extension interface enables powerful scientific computing packages like NumPy to crunch data so quickly that it leaves native Python code in the dust.

Python Rules the Web

While Python dominates at data analysis, it's also a great choice for building web applications. Frameworks like Django and Flask are battle-hardened competitors to Ruby on Rails or Laravel in PHP-land. Instagram, Pinterest and The Washington Times wield the power of Python frameworks to run their massively popular web applications.

With cloud computing, running and scaling Python web applications is easier than ever. Today, you can automatically throw more memory, processing power or nodes at a resource-intensive Python application in a cost-effective manner.

Python Responds to Developer Demand

Single-threaded, asynchronous programming has made a comeback with the popularity of nodeJS and its impressive speed benchmarks. Due to the flexibility Python provides, it too, can take advantage of node's tight event loop, libuv. Even using Python's native event loop, asynchronous web servers are pretty darn fast.

Remember the Global Interpreter Lock? While threading in Python might be constrained by the GIL, the asynchronous programming model in Python works with it through cooperative multitasking. Within the async model, there's no need to sidestep the GIL and no need to worry about common multithreading pitfalls.

In Python 3.5, a new syntax for async programming was implemented in yet another step towards prioritizing developer convenience.

Python is Ubiquitous

Python code doesn't just run in the cloud. Not only is Python portable and extensible, it is embeddable. Python powers Internet of Things (IoT) hubs and devices. MicroPython has even found its way onto low-powered microcontrollers.

Conclusion

Data intensive fields have exploded recently, and with it, so has Python adoption. Python's portable, extensible and embeddable qualities make it a great choice for almost all development platforms. The language's ecosystem and ease of use attract developers from all walks of life. Finally, Python's developers make sure the 20+ year old language stays relevant and continues to meet developer needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment