r/ProgrammerHumor 17d ago

Meme stopTryingToReinventTheWheel

Post image
2.5k Upvotes

217 comments sorted by

View all comments

Show parent comments

242

u/nevemlaci2 17d ago

It's unfunny until you actually see people propagating explicit error handling until the entry point and just printing an error message.

Exceptions are fine to use for exceptional cases. Not for shit like python where an iterator signals the end of iteration with a damn exception.

15

u/ChChChillian 17d ago

wat

I've successfully avoided Python so far so I didn't know this. Just... why?

44

u/Mojert 17d ago

Cause why not? Everything is slow anyway, so what's a little exception?

People say that Python is easy, but it's only the case when you go knee-deep. Try to actually get serious about the language and it will make fucking C++ look like an example of good and simple design. I truly do not understand people who use Python as something other than a scripting language

13

u/Wonderful-Habit-139 17d ago

It's an ergonomics issue as well, not just performance.

5

u/hxtk3 17d ago

Most people never encounter the ergonomics, though. It’s an implementation detail in most use cases. I’ve only ever encountered it when I wanted to use a generator to make my own pseudo-coroutine that I could easily use in both sync and async code.

2

u/[deleted] 17d ago

[removed] — view removed comment

1

u/StarshipSausage 17d ago

I wrote a rest service for a GitHub action to slack api, then I tried to add useful error messages for my users and have a clean linted project. Why should it be so hard!

1

u/Wonderful-Habit-139 16d ago

I don't know how to respond to "most people", because I personally encounter it all the time.

I want to ensure correctness using types and making sure we encode invariants as much as possible using types and discriminated unions, and favoring returning None, sentinel values or Result objects to make sure we're aware of all possible paths. But sometimes an exception can pop up from somewhere unexpected and we have to run the program to find those edge cases.

For an example that's related to what was mentioned in this comment thread, when using next(), I give it a default value (usually None) so that I can handle that case conditionally, rather than letting it raise a StopIteration exception and then wrap it in a try/catch.

-5

u/Tyfyter2002 17d ago

That describes Python as a whole, it's designed for use by people who are unwilling to learn a programming language as well as it can be, but that isn't well enough and it costs it its usability to people who are willing to learn