On 03/28/2013 09:03 PM, Adam D. Ruppe wrote:
I was working on a project earlier today that stores IP addresses in a
database as a uint. For some reason though, some addresses were coming
out as 0.0.0.0, despite the fact that if(ip == 0) return; in the only
place it actually saves them (which was my first attempted quick fix for
the bug).
Turns out the problem was this:
if (arg == typeid(uint)) {
int e = va_arg!uint(_argptr);
a = to!string(e);
}
See, I copy/pasted it from the int check, but didn't update the type on
the left hand side. ...
While I agree that implicit uint <-> int is a bad situation, I think the
following practises deserve the larger part of the blame:
- Having too much redundant information in the code.
- Copypasta & edit instead of string mixins / static foreach.
Of course, sometimes there is a significant amount of temptation.
(Also, that code snippet is nowhere near the most convenient line
length. Eliminating the temporary completely is a valid option. :o))