All asserts need to have messages attached! Explicit as possible!
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 10 06:45:20 PDT 2017
On Monday, July 10, 2017 1:28:44 PM MDT Jacob Carlborg via Digitalmars-d
wrote:
> On 2017-07-08 04:13, Jonathan M Davis via Digitalmars-d wrote:
> > I tend to agree - in many cases, the error message is completely
> > redundant - but a number of folks seem to think that you should never
> > have an assertion without a message, and it tends to get complained
> > about if you have an assertion without a message if it's not in a unit
> > test, so I'm a bit surprised that the OP ran into one in Phobos.
>
> I think it's extremely useful to have, especially in a code base you're
> not familiar with or is complicated. It has happened to me quite often
> that I hit asserts in DMD when I develop on that code base. It would
> help me a lot if all those asserts had descriptive messages.
That only helps if there's something to describe. Often, it's something like
assert(!range.empty);
in which case, there really isn't much to say. I totally agree that
assertion messages can be helpful when there's something to explain, but
there often really isn't, and all a message is going to do is repeat the
condition being checked in English, which is just pointless text.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list