Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
j0n4s53101yIdk just rtfm:
"Assertions should be used as a debugging feature only."
https://php.net/manual/en/... -
@j0n4s
This is how C++ works. Assertions are on when compiled in debug mode. Off when compiled in release mode. -
j0n4s53101y@Demolishun python also has this, but it removes them only when you run it with 'python -O' (which sole purpose is to remove assert and set the builtin __debug__ boolean to false) but idk if anyone does this. I just checked and rust's assert_eq does also run in release mode but there is a debug_assert.
-
I‘m all for hating PHP but to be fair, yup: asserts are disabled for release/prod in every language that I worked with so far.
-
Asserts are not for error handling.
They're debugging helpers.
Thus most languages treat them as conditionals, short wrapper ala "if debug ... do X".
Thus in most languages it will be stripped by the compiler / ignored by the runtime engine, which is completely correct.
If you utilize a debugging aid as an error handler or even worse as an go-to statement, please please please relearn the basics of the language.
It is wrong for so many reasons and definitely a cardinal sin. -
On the flip side, debug-only assertions are allowed to be really expensive. When I'm fixing bugs I add assertions for almost any invariant I can think of and many of them can remain in the code afterwards.
Related Rants
Today I learned that PHP disables assertions by default on prod via:
zend.assertions = -1
Which means, it is running in "production mode". PHP then simply ignores all those pesky assertions, so your code can run superfast! 🤡
Guess how I found out... I'm sick to my stomach right now.
rant
php