debugging code with mixins

Jonathan M Davis jmdavisProg at gmx.com
Thu Dec 2 14:48:57 PST 2010


On Thursday, December 02, 2010 14:16:50 Trass3r wrote:
> I often use mixins in my code.
> This is nice programming-wise but really becomes painful when trying to
> debug cause it completely messes up dmd's line numbers.
> Is there any solution to this in D?
> Could we have some sort of "preprocessed source code" and use that for
> debugging?

Well, there is an enhancement request for that sort of thing ( 
http://is.gd/i73ls ), but I think that the best thing to do at the moment is to 
ensure that your string mixins have no newlines in them. As long as there's no 
newlines, it doesn't screw up the line numbers in the error messages. Now, that 
doesn't really help you in finding where in the mixin the problem is, but it does 
help make sure that your error messages aren't all screwed up line number-wise.

Personally, when I want to debug string mixins, I print out what they are 
(they're strings, so it's easy to do) and examine them. If you leave newlines in 
them, you could even do the math to figure out where the error is the mixin (or 
you could leave the newlines in and do just add a lot of writeln(__LINE__) 
statements to your mixin). It _is_ insentive not to make your string mixins too 
big and complicated though. Regardless, I'd advise making your string mixins not 
have newlines in them when you're not debugging them. Otherwise, all of the 
error messages following the mixins are messed up.

- Jonathan M Davis


More information about the Digitalmars-d mailing list