All asserts need to have messages attached! Explicit as possible!

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 7 19:13:01 PDT 2017


On Saturday, July 8, 2017 1:51:34 AM MDT Moritz Maxeiner via Digitalmars-d 
wrote:
> On Saturday, 8 July 2017 at 00:55:46 UTC, FoxyBrown wrote:
> > [...]
> > It should be mandatory that all asserts, throws, etc provide
> > correct information about not only the point of the error but
> > also the location and what caused it. [...]
>
> Error messages are sensible when they provide context (e.g. for
> complex conditions).
> In my experience, though, most asserts exist to cover fairly
> obvious cases, where an additional message would just add noise:
>
> ---
> struct SomeRange
> {
>      bool empty() { ... }
>      void popFront()
>      {
>          assert (!empty);
>          ...
>      }
> }
> ---

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.

- Jonathan M Davis



More information about the Digitalmars-d mailing list