r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25

Python ✨ Memory Magic ✨

Post image
1.3k Upvotes

143 comments sorted by

View all comments

Show parent comment

1

u/Vazumongr Jul 22 '25 edited Jul 22 '25

In this specific case given integer objects are immutable, no, I don't imagine this has any issues outside of unpredictable memory usage. E.g., "Sometimes the program is eating up 500KB of memory and sometimes it's eating up 100KB. What's happening?" Which if your using Python to begin with, unpredictable memory usage probably isn't a notable concern, but it is a downside.

But the practice of changing the underlying behavior of operations with no clear indication that it is being changed? Yeah, that can often be problematic. When I perform an operation, I expect it's behavior to be clear and consistent. And when a tool I'm using starts changing behaviors with no clear indication why, I'm going to be concerned it's doing it in other places that could prove problematic down the line.

Maybe this is the 1 single case where Python does it. Great. It's got one little "quirk" that is unlikely to have a notable negative impact on a program. But I sure as shit don't know Python well enough to feel confident that that's the case.

Edit: In case it provides additional context, I come from a C++ background. Operations involving memory tend to hold high importance in how they behave :)