assert(obj) is an atrocity
bearophile
bearophileHUGS at lycos.com
Sun Nov 13 14:08:42 PST 2011
Jonathan M Davis:
> The fun part about assert(obj) though is that it doesn't work with structs -
> not directly anyway. If obj is a struct, assert(obj) tries to convert it to
> bool like it would do normally. However, assert(&obj) _does_ call the
> invariant. Pointers to structs are treated exactly the same as references to
> classes in this case (complete with the lack of a null check). So, it's
> arguably consistent, but it's a bit weird.
I didn't remember this about pointer to struct.
Generally a good language needs to be designed with a more explicit syntax (unless the operation is very commonly done in this language, or among other languages too). If I am a newbie that doesn't know D a lot, and I see those asserts, for class instances, struct instances, and struct instances with &, I can't tell what they mean. This is not so good.
Bye,
bearophile
More information about the Digitalmars-d
mailing list