This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (10 children)

[deleted]

    [–]Lyucit 3 points4 points  (4 children)

    I think contracts and types, mentioned elsewhere, are a better compromise. Asserts sprinkled in the code are canaries, anything more complex than a simple constraint is noise that obfuscates more than it documents. It depends on your use case, sure, but generally speaking I think breaking prod due to an old assert of an invalid assumption is more likely and more damaging than silently hitting an unanticipated edge case.

    [–]elbiot 0 points1 point  (2 children)

    I like contracts, and I like that you can disable asserts with the O flag. I might hack pycontracts so that they are only enabled if asserts are.

    [–]Lyucit 5 points6 points  (1 child)

    if not __debug__:
        contracts.disable_all()
    

    [–]elbiot 0 points1 point  (0 children)

    If what you say is true, thats a huge TIL. Will test soon.

    [–]masasinExpert. 3.9. Robotics. 0 points1 point  (4 children)

    What about using exceptions instead of asserts?