News for hackers. Stuff that matters.
Re:I'm Switching to Python and Actually Liking It by cristoperb on Wednesday July 16, 2025 @05:39PM (#44587070)
Even slightly better is to first check both

    if not API_KEY and not CHANNEL_ID:
        print("Missing both YOUTUBE_API_KEY and YOUTUBE_CHANNEL_ID.")
        exit(1)
    if not API_KEY:
        print("Missing YOUTUBE_API_KEY.")
        exit(1)
    if not CHANNEL_ID:
        print("Missing YOUTUBE_CHANNEL_ID.")
        exit(1)
That way you don't end up fixing one just come back and be told you're also missing another requirement
Re:I'm Switching to Python and Actually Liking It by delusional on Wednesday July 16, 2025 @05:47PM (#44587140)
Even better would be to only check each once and buffer the decision:

    valid = True
    if not API_KEY:
        print("Missing YOUTUBE_API_KEY.")
        valid = False
    if not CHANNEL_ID:
        print("Missing YOUTUBE_CHANNEL_ID.")
        valid = False
    if not valid:
        exit(1)
This way you only check each value once (because your logic might be more complicated than just checking it's not set, maybe it can be wrongly formatted) and you still get to do whatever logic you want. It also removed the combinatorial problems.

This is a pretty general principle of separating decision from action.