Hacker News new | past | comments | ask | show | jobs | submit login

Unless I'm misunderstanding, they are wrapping their asserts in try/catch blocks? That's... yikes.



Most likely they just `assert` error conditions and let that blow up as error reporting, rather than write a full conditional and raise a custom exception.

I’ve been guilty of that in my own code when I just want to tell myself about an error.


Isnt just assert the error condition how assert is actually intended to be used?


Depends. The issue is that since `assert` is stripped out in “O” mode, if the codebase depends on `assert` for correctness… they’re not compatible.


What do you mean by depends on assert for correctness? How?


    get_president_inside_bunker()
    assert president_is_inside_bunker()
    close_bunker_doors()
    assert bunker_doors_are_closed()
    send_nukes()
With asserts enabled this is fine. With asserts disabled you might start sending nukes while the president is still outside or the doors to the bunker are still open.


Thanks! I never thought anybody would do such a thing.


No one should, but it happens.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: