Suggestion/proposal regarding std.logger candidate

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun May 25 00:49:42 PDT 2014


On Sat, 24 May 2014 23:56:39 -0700
Steven Schveighoffer via Digitalmars-d <digitalmars-d at puremagic.com>
wrote:

> IIRC, logging with 'debug' should work.

Yes, logging in debug blocks would work, because debug blocks ignore purity
constraints (which means that they _can_ cause a function to have weird
behavior if you're not careful, because the compiler is still free to do
things like optimizations based on purity). It's that way to help with
debugging (since not being able to print anything when debugging can be a
_real_ pain), but since logging is frequently used for purposes other than
simply debugging a program, putting logging statements in debug blocks doesn't
really solve the problem - and abusing debug blocks by using them specifically
for logging purposes could cause some weird stuff to happen if you're not
careful, since you'd be doing impure stuff in a pure function and thereby
violating guarantees that the compiler assumes hold.

Realistically, if you're looking to do much logging in your program, you're
probably going to have to give up on using pure in a lot of places.

- Jonathan M Davis


More information about the Digitalmars-d mailing list