Great article about designing a new Python library. As someone who is a self-taught coder, I learned how to create a library by copying what I saw on peoples' GitHub repos. I wish I'd seen this post back then!
Great article about designing a new Python library. As someone who is a self-taught coder, I learned how to create a library by copying what I saw on peoples' GitHub repos. I wish I'd seen this post back then!
I agree with everything here except for the part about exceptions. Handling exceptions in Python is one of my least favorite things to do, because try/except blocks in Python look really ugly to me 🙁
I would cry if I had to catch an exception every time requests.get(url) returned a 401 or something.
@johnabooth I've never worked with C++ and only have a limited amount of experience with C#. I don't think that handling exceptions in Python is hard, necessarily. I just don't love the way it looks in code. Mostly due to the fact that increases the number of indents required, and I start to get uneasy if my code starts creeping down and to the right in my IDE.
Like here's a not terribly realistic example of where you need to catch an exception, and then have logic within the except block. To me this feels ugly. Especially if you need to handle multiple types of exceptions, each with their own nested if statements.
@johnabooth Sometimes you'll see libraries raise errors when you're trying to get something and there isn't anything to get, which I'm not a huge fan of.
I often find myself creating boilerplate functions like this to handle these exceptions.