assert with format considered harmful
Ali Çehreli via Digitalmars-d
digitalmars-d at puremagic.com
Mon Feb 27 11:09:35 PST 2017
Let me point out the elephant in the room as well.
On 02/25/2017 10:34 PM, Ali Çehreli wrote:
> // In this case a %s is forgotten but it could be any other trivial
> error.
> assert(i == 42, format("Bad parameter:", i));
In addition to the current dangerous behavior of assert, there is the
philosophical argument whether the program can do anything at all after
an assert. Like many others, our friend Chris Wright thinks so:
http://forum.dlang.org/post/o6u5j5$1gnf$1@digitalmars.com
On the other hand, I, like many others, have apparently been
hypocritical every time I attempted to generate a message for assert.
That's wishful coding indeed. :)
How about this rule: The message generation code must be
- be nothrow
- have no side-effects, which means the message that it generates must
be written into a pre-allocated space, without going out of bounds (how
to control this?)
- nogc (I think this is implied from the previous two)
The more I learn and understand about computing the more it becomes
crazy. :)
Ali
More information about the Digitalmars-d
mailing list