EPYTHONLAB Telegram 1961
The Bug That Taught Me More Than Any Tutorial

Last week, I ran into a bug that almost derailed a client demo.

A function that should have returned filtered results was quietly failing due to a simple logic oversight: an unintended mutable default argument in Python.

def get_filtered_data(filters=[]): # classic trap
...

Each call was modifying the default list, leading to unpredictable results. After debugging, I replaced it with:

def get_filtered_data(filters=None):
if filters is None:
filters = []
...

Takeaways:

Default mutable arguments in Python are a silent trap.

Writing tests isn't just a best practice—it’s your first line of defense.

Don’t just “write code that works”—write code that fails loudly and early when it breaks.


I’m sharing this because even experienced devs fall into these traps. The real lessons come from the messy, unpredictable parts of real-world coding.

Common mistakes of naming functions https://youtu.be/PY22gyHjLW8



tgoop.com/epythonlab/1961
Create:
Last Update:

The Bug That Taught Me More Than Any Tutorial

Last week, I ran into a bug that almost derailed a client demo.

A function that should have returned filtered results was quietly failing due to a simple logic oversight: an unintended mutable default argument in Python.

def get_filtered_data(filters=[]): # classic trap
...

Each call was modifying the default list, leading to unpredictable results. After debugging, I replaced it with:

def get_filtered_data(filters=None):
if filters is None:
filters = []
...

Takeaways:

Default mutable arguments in Python are a silent trap.

Writing tests isn't just a best practice—it’s your first line of defense.

Don’t just “write code that works”—write code that fails loudly and early when it breaks.


I’m sharing this because even experienced devs fall into these traps. The real lessons come from the messy, unpredictable parts of real-world coding.

Common mistakes of naming functions https://youtu.be/PY22gyHjLW8

BY Epython Lab




Share with your friend now:
tgoop.com/epythonlab/1961

View MORE
Open in Telegram


Telegram News

Date: |

"Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn. Over 33,000 people sent out over 1,000 doxxing messages in the group. Although the administrators tried to delete all of the messages, the posting speed was far too much for them to keep up. ‘Ban’ on Telegram Choose quality over quantity. Remember that one high-quality post is better than five short publications of questionable value.
from us


Telegram Epython Lab
FROM American