Author

Bob Belderbos Avatar

Bob Belderbos

Latest articles

by

  • , ,

    6 Cool Things You Can Do With The Functools Module

    ·

    ·

    5 min read

    In this article let’s look at the functools Standard Library module and 6 cool things you can do with it (be warned, a lot of decorators are coming your way! 😍) … 1. Cache (“memoize”) things You can use the @cache decorator (formerly called @lru_cache) as a “simple lightweight unbounded function cache”. The classic example is calculating a Fibonacci series where the intermediate results are cached, speeding up the calculation significantly: On my system this code takes 0.02s to complete. 😎 However if I comment the @cache decorator it takes 28.30s because of all the repeated calculations! 😱 Hence caching is…


  • Introduction I recently re-engaged with one of my open source projects and it was a rewarding experience. 🎉 It was a Pybites project I had written the core for years ago, but thanks to some amazing Pythonistas in our community it became a way more mature tool so I had to get acquainted again. I was resolving an issue that had been causing some disturbance in our community, hence fixing it was quite satisfying. Contributing to open source is amazing, and with the amount of projects out there your contributions are necessary. It’s also one of the best way to…


  • , , ,

    Debunking 7 Myths About Software Development Coaching

    ·

    ·

    11 min read

    If you give a man a fish, you feed him for a day. If you teach a man to fish, you feed him for a lifetime. Chinese proverb Transformative power of guidance 10 years ago I was overweight, maybe not more than +12 kg, but it definitely had a bearing on the quality of my life and (!) future health perspective. Back then I thought I ate reasonably healthy and did my daily walk (the World Health Organization (WHO) recommends you “do at least 150–300 minutes of moderate-intensity aerobic physical activity”, I definitely did that). Now I know: I simply…


  • A challenge in software development is to keep things simple 🤯 For your code to not grow overly complex over time 😱 Simple is better than complex.Complex is better than complicated. Zen of Python 🐍 Simplicity in your code means fewer possibilities for bugs to hide and easier debugging when they do arise 📈 It also makes your code more understandable and maintainable, which is crucial in a team setting or when returning to your code after a period of time. Photo by Pablo Arroyo on Unsplash Let’s look at 5 examples: 1. Are all numbers divisible? A good first example is underutilizing…


  • Anyone who’s worked with Python knows that modules can be a Godsend, saving you time, effort, and many lines of code. They even have namespacing built-in 💪 😍 To expand on this a bit: However, not all ways of using modules are equally beneficial. In this article, we will discuss why using import * can be more problematic than it’s worth, and what you should do instead. Why is this a problem? When you use import *, Python brings in every single function and variable from the other module into your own. This can cause something called “namespace pollution” 😱…


  • Python allows you to use *args and **kwargs in function definitions to accept an arbitrary number of positional and keyword arguments, respectively. Here is a simple example: Different types of function arguments In the above example, the arbitrary_args function is defined to accept any number of positional and keyword arguments using the *args and **kwargs syntax. When the function is called with arbitrary_args(1, 2, 3, a=”apple”, b=”banana”), the *args collects all the positional arguments (1, 2, 3) into a tuple, and **kwargs gathers the keyword arguments (a and b) into a dictionary. Consequently, the function prints the tuple (1, 2,…


  • In the world of programming, errors are inevitable. But how we choose to handle these errors can make the difference between a system that is robust and user-friendly and one that is fraught with ambiguous issues 😱 The Zen of Python famously states, “Errors should never pass silently.” This principle emphasizes the importance of addressing issues head-on rather than ignoring them 😅 In this article, we’ll delve into the consequences of silent failures, the value of transparent error handling, and practical ways to ensure that errors in our Python code are always brought to light. Requests Let’s look at a…


  • ,

    How to better streamline your Python project using a Makefile

    ·

    ·

    1 min read

    Makefiles are awesome, and you can use them in your Python projects too (they are not only to compile and build C/C++ projects that is) 😎 They help you automate various tasks and streamline the development process overall 🚀 They allow you to: – Manage dependencies– Run tests– Build documentation– Format your code– Lint and perform static analysis of you code– Clean up temp files– Manage virtual environments– Build distributions– Deploy your code I often add one to my projects and they save me time and streamline the experience for other developers 📈😍 Here is a 5 minute video to…


  • ,

    Why is Flat Better Than Nested? (Zen of Python)

    ·

    ·

    1 min read

    The short answer: deeply nested code can be hard to read and understand (and this not only applies to Python, but for any code really). Each level of indentation adds a level of complexity and an additional condition that the reader (which is often you!) has to keep in their head while trying to understand the code. Here is an example of deeply nested code and how we can refactoring it to make it more readable (and therefor maintainable): In the refactoring we reduce the level of nesting by using “early returns”. Instead of nesting conditions, you can invert the…


  • ,

    5 tips to learn any new Python library faster

    ·

    ·

    4 min read

    This was a Pybites email first. To always get the latest and greatest content, subscribe here. Lately I have been learning some new libraries for weekly PDM Code Clinic demo sessions (e.g. PyScript, Flet, PySimpleGUI, Playwright, htmx, Redis, Leaflet, etc.) There is a general approach I take that makes this less painful and more fun. Of course having done development for quite a while makes things easier, but even after years of experience this craft does not come easy per se. The following tips are still generic enough that they help developers of all levels. Let’s also time the steps…