The line of code from past.builtins import cmp often catches the eye of Python developers, especially those who have been using it for a while. It's among the first lines in the classic "Hello, World!" example, but it's more than just boilerplate. It's a window into the language's history and a learning opportunity about deprecated features.

Python's cmp function was a way to perform simple comparisons between two objects, returning -1, 0, or 1 depending on whether the first object was less than, equal to, or greater than the second. However, the developers eventually decided to remove it in Python 3, marking the beginning of a new era in Python's evolution.

The Evolution of Python Comparisons
The simple 'less than', 'greater than', and 'equal to' comparisons (<, >, ==) in Python have been around for a long time. They're fundamental to the language, used in conditional statements, sorting algorithms, and many other contexts.

However, in the early days of Python, these operators weren't quite enough. Enter the cmp function, designed to simplify complex comparisons.
What was cmp used for?

The cmp function was a way to perform a custom comparison operation. It was often used in sorting algorithms or other contexts where a custom comparison was necessary. It simplified the task of writing complex comparison logic.
For instance, say you wanted to sort a list of strings, but not alphabetically. With cmp, you could define a custom comparison function that sorted based on some other criterion. This is where cmp's power lay: it allowed for complex, application-specific sorting and comparison logic.
Why was cmp deprecated?

While cmp served its purpose well, Python's developers started to move towards a more expression-based way of programming. They wanted to get rid of the old, functional model where you directly define what you want the function to do (like cmp(-1) if x < y else 1 if x > y else 0).
The new model, encapsulated in the 'Rich Comparisons' added in Python 3, involves objects directly saying how they compare to each other (x < y is now defined by `__lt__` method). This is more natural, more powerful, and more extensible - you can now add entirely new comparison operators to your objects.
Understanding the Deprecation

The deprecation of cmp means that it's no longer considered good practice to use it in new Python code. If you find yourself writing cmp(x, y), you should step back and think about what you're really trying to do.
If you're writing a sorting algorithm, use key functions. If you're performing complex comparisons, define your own comparison methods (__lt__, __eq__, etc.). This will not only help you write more modern, Pythonic code, but it will also help you gain a deeper understanding of how Python works.




















Upgrading Legacy Code
If you're maintaining legacy code that uses cmp, you should consider upgrading it. While it's not strictly necessary - Python 2 is still supported officially, and cmp is still usable there - upgrading to Python 3 has many other benefits.
Moreover, using cmp in new code could trips up other developers who might not recognize it. If you want your code to be easily understandable and maintainable, it's best to use modern, well-known techniques.
So, what do you do when you see from past.builtins import cmp in your code? You respect the past, but look towards the future. It's a reminder of where Python has been, but it's also a nudge to where it's going - and where you should be going with your code.