Python: The Unsung Hero of Hard Tech
True hard-tech development is often a blend of hardware and software engineering, where we build systems that deliver real-world value. Since we're dealing with tangible, physical systems, considerations such as performance optimization, real-time data processing, and cost-effectiveness become important. This becomes especially critical when integrating AI at the edge with robotics, IoT, and Industry 4.0. When weighing the total cost of ownership, alongside design considerations for maintenance and development velocity, the importance of the right tools cannot be understated.
This is why I love Python. It may not be the fastest, nor the fanciest, and it lacks strong typing (much to my chagrin). However, what it lacks in these areas, it makes up for with a rich ecosystem of packages, a stellar developer experience, and a pragmatic "get it done" attitude. This ethos empowers us to go from idea to deployment quickly and efficiently, all the while ensuring maintainability for the long haul.
Today's post is a celebration of Python, the language that made me fall in love with software. We'll look into the nuances and enhancements in the recent Python 3.12 release, from new functionalities and improved code structures to new data-handling techniques.
Celebrating Python 3.12: A Quick Peek
Python 3.12 has officially been released! While it may not be the most groundbreaking release in the Python journey, it's a significant step forward. The release introduces foundational features to be leveraged in upcoming versions, such as a new real-time debugging and profiling API and the isolation of sub-interpreters for concurrent task execution. These enhancements might not immediately impact daily coding, but I'm sure innovative tools and packages will soon leverage their potential. Personally, I'm excited about the more flexible f-string parsing.
The Overlooked Gems of Python 3.12
The Python 3.12 release, despite its spotlight features, has hidden treasures:
Enhanced debugging and revamped command-line interfaces to bolster problem-solving and optimize real-time solutions.
Refinements in Pathlib and functionalities like
math.sumprod()
, all designed to streamline code and curtail computational demands.
My Favourite Python 3.12 Feature: itertools.batched()
Python 3.12's standout feature? In my opinion, its itertools.batched
. This function is amazing for efficient real-time data batch processing, an indispensable tool for AI, machine learning, and data tasks. With its efficient approach, Python developers can now enjoy improved performance, fewer custom utility functions, and enhanced code clarity.
Python 3.12 and Supply Chain Security
Coming from the hardware world, the concept of supply chain has always come naturally to me. In software, while things seem more streamlined, it's crucial to understand the underlying infrastructure. Python's interpreter, its build, delivery, deployment, and its role in our applications is the foundation. Emphasizing the integrity of releases and addressing potential supply chain security risks is vital. The introduction of software bills of materials (SBOMs) to track transparent changes between releases is an important step forward.
Why does Python Code Run Faster in a Function?
The intricacies of popular languages like Python often remain obscured. Here's a tidbit: Python code is faster within a function.
Python scripts are commonly used in various applications, from cloud ETL functions to local IT tools. A detail to note is that code inside a function runs with local variables using an array offset, which is faster than the hash table lookup for global variables. This leads to better real-time processing.
Organizing code into functions also makes it more structured and maintainable. It's a good practice to ensure that most code is inside a function, such as with a good old fashion:
if __name__ == "__main__":
main()
Merging Rust with Python: PyO3 and Optimization
Python's strength lies in its ability to rapidly transform ideas into deployed solutions while maintaining a clean code base. However, early optimization can be a trap.
Before truly understanding a problem, over-optimizing can divert us from the main goal. It's only after deployment when we've gained a deep understanding of the problem and the required solutions, that optimization becomes crucial. Tools like PyO3 bridge Rust and Python, and provide a pathway for optimized solutions for high-performance tasks. This integration is vital for applications requiring performance, such as robotics and AI in Industry 4.0. By combining Rust's performance-oriented features with Python's vast libraries, we get the best of both worlds.
Pybotics: Python Toolbox for Robotics
Pybotics is an open-source Python toolbox dedicated to robotics, developed by me during my PhD, and published in The Journal of Open Source Software. Its primary function is to assist in robot kinematics and calibration. The toolbox enables users to simulate and assess fundamental robotic concepts, including kinematics, dynamics, trajectory generations, and calibration. It is built specifically for the Modified Denavit–Hartenberg parameters convention, a system used to define reference frames on robot manipulators.
The need for Pybotics arises from the importance of accurate robotic programming and offline simulations, which ensures that robotic applications are not just precise but also accurate. Calibration plays a crucial role in ensuring this accuracy.