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

"Assert is not a shortcut for lazy coders."

Then they need to make something better for me. My c and python code isn't functional with asserts compiled out, because assert just makes my life easier.

In a perfect world, current assert semantics would be _DEBUG_ASSERT (all caps to let you know it has macro-ish behavior), and the normal assert would always be on.

Can you give an example of the Python you're writing that requires assertions to be functional? My guess is that you're using assertions where raising and catching exceptions would be more appropriate.

In c, checking memory allocation. In python, checking that sql queries succeeded. The point is there's always something that should _never_ fail in real life but I feel better with an explicit check on it. I figure the ease in coding makes up for telling people (not that it's a high probability of this happening) to not compile asserts out.

It just bugs me to no end how people try to make the easiest forms of error checking difficult.

In C it's easy enough to define your own macro (I like to call it "require") which behaves similarly, but doesn't "abuse" assert. Not so in Python, though.

It is silly to make the most, convenient form of error checking subtly wrong, and then castigate programmers as lazy for using it.

yeah, the problem is assert is already such a fine name. why, oh why, must it be confined to debug only builds :-(

well it doesn't have to be, it's just a convention -- feel free to violate it, you just have to deal w/ your usage being a bit surprising, and lectures like the original blog post. :)

Just because you happen to like a particular coding technique doesn't mean its a good one, or that the developers are obliged to support you in it. For example, my preference could be to use all one character variables, because I can remember them all just fine, and they make my typing faster. However, this is obviously not a good habit, and hurts the comprehension of any other programmers that try to read my code. Or I could be addicted to using __add__ to call functions on my objects, with a hack that turns `my_object +"user"` into calling the user function on my_object. I could find this preferable to my_object.user() because it looks better, but that in no way entitles me to complain when a library calls + on a list-like object I passed it and it errors out, because I broke the contract of __add__. Python provides `assert` for a specific purpose, basically those outlined in the blog post, and using it for other things is just plain hackish, and is in no way a good practice.

assert is both easy to write and read. that's why people use it. the people who made it debug only were stupid.

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