Share
 

Hey Pythonista,

Happy Monday! We hope your week is off to a great start ...

Here are our 5 bullets of the week:

1. Quote to ponder on / are design patterns overrated for Python developers?

"Design patterns should not be applied indiscriminately. Often they achieve flexibility and variability by introducing additional levels of indirection. A design pattern should only be applied when the flexibility it affords is actually needed." - Erich Gamma

Design patterns are solutions to common problems in software design.

But we have to use them judiciously.

Sometimes we see people overengineer things at the start of their app or project.

They worry about what design pattern to apply before even addressing the core problem they're trying to solve.

It's important to keep in mind that the benefits of design patterns can come with the cost of added complexity.

One thing we love about Python's philosophy is that it emphasizes simplicity and readability, with a preference for straightforward solutions over complex ones.

So next time you (eagerly) want to apply a design pattern:

  • First try to understand the problem deeply and ideally get something working first.

  • Prefer simpler solutions that achieve the same goals as more complex ones. There's a good chance the Standard Library + PyPI usually offer something pretty robust.

  • Consider the future needs of your application. If flexibility, scalability, and maintainability are crucial, applying a design pattern early on might save time and effort in the long run (e.g. how we used ABCs in pybites-search).

  • Every layer of abstraction introduces complexity (additional levels of indirection) affecting the code's maintainability. Ensure that the benefits of applying a design pattern outweigh the costs in terms of performance, readability, and maintainability.

Design patterns can make software more adaptable to change, supporting principles like encapsulation, modularity, and polymorphism, but as per Gamma's advice we should be pragmatic and purposeful in our use of design patterns, they are tools to solve (business logic) problems, not goals in themselves.

2. A practical context manager example

Ever wondered about practical use cases of context managers?

Let's look at `redirect_stdout()` 🐍 today.

This context manager allows you to temporarily redirect standard output to a different stream. 💪

Example:

from contextlib import redirect_stdout
from io import StringIO
from types import BuiltinFunctionType

def get_len_help_text(builtin: BuiltinFunctionType) -> int:  
    f = StringIO()
    with redirect_stdout(f):
        help(builtin)       
        return len(f.getvalue())

In this example, we use it to capture the output of Python's `help()` built-in into a string to measure its length.

While measuring help text might not be super useful, understanding how to redirect stdout opens up possibilities for logging, testing, etc. where capturing output is essential. 🚀

3. More exciting podcast episodes (we're north of 150 now! 🎉)

We have 3 new exciting episodes for you:

  • Steve Lott shares how he approaches writing about / teaching Python, uncovering his research process and how he infuses fun into his personal side projects. He also shares his insights on the evolving landscape of Python, the importance of hands-on learning through real-world projects, the unparalleled impact of the Python community on developers worldwide and his adventurous "technomad" / boat life. Listen here.

  • Marcelo Trylesinski shares his unique journey, discussing his disciplined routine of GitHub issue resolution that propelled him toward becoming a prolific open-source maintainer and a FastAPI expert! Marcelo shares insights into his pivotal moment of joining Pydantic, his ongoing contributions, and the mindset that drives his success as a developer.  We also explore how to be a valuable open-source contributor. Listen here.

  • Upcoming: we (Bob & Julian) finally recorded an episode together (it had been a month!) on the impact of AI tools on our work as developers. No, we don't think we're going extinct, far from it ... + we also have some other exciting Pybites updates. To be released later today...

4. A powerful career (and mindset) tip

Do you keep a WINS file (also known as a "brag doc" or "success wall")? You should!

It's simply a document that you create for yourself detailing all of your wins and accomplishments over time.

"Over time" because:

1) Our memory will fail us (similar to how we overestimate how well we understand our code in the future).

2) This will have a compound effect (as per Darren Hardy's book).

Also at times your biggest enemy in the face of adversity is YOU.

What we say to ourselves matters (Shad Helmstetter's "What to Say When You Talk to Yourself" is an insightful read in this context).

When we're feeling demotivated or are having a hard time, it's easy to spiral into thinking we're not good enough (also known as imposter syndrome) which will affect our confidence.

A brag doc serves as a reminder of how amazing we really are, of how many incredible things we actually accomplished.

And here's the kicker...

One of our clients reminded me the other day that this also is a great tip for work! 💡

When performance reviews come around you NEED to be able to quickly pull up what you have achieved in the past year. This tool will give you ample evidence so you'll go into the meeting prepared. 😎

We know as developers how important documentation (either code or external) is, similarly document your career progress in a wins file, your future self will thank you! 😍📈

5) From the archives

While Python’s *args and **kwargs provide a dynamic and flexible way to handle function arguments, their use comes with trade-offs. Striking the right balance is key.

Being explicit in our code fosters readability, maintainability, and reduces potential pitfalls. As developers, it’s our responsibility to weigh the benefits of flexibility against the clarity and safety of explicitness.

Learn more about the *args + **kwargs trade-offs for clean + maintainable code in our article.

---

Go crush it this week!

Bob & Julian


P.S. Our community is on fire! 🔥 - people joining pick up so many good tidbits and make powerful connections.

If you're not yet in our new Circle community, you really should join:

1. Go to https://pybites.circle.so/ and sign up (it's free!)

2. Once there please introduce yourself: what do you do with Python, what do you want to learn/improve, something about yourself... < looking forward to greeting you there.

Expect more developer + personal growth to happen.


Email Marketing by ActiveCampaign