I wonder who had the idea to implement a ToBoolean method in the new record helper for simple numeric types.
I wonder who had the idea to implement a ToBoolean method in the new record helper for simple numeric types.
Or does anyone think this is a good coding style?
if i.ToBoolean then
Or does anyone think this is a good coding style?
if i.ToBoolean then
Assuming it's implemented right (ie. equivalent to "<>0"), why not?
ReplyDeleteI regularly see creative re-interpretations ("=1", ">0", etc.) of the numeric to boolean convention.
Yes, its inline for Self <> 0. But my eyes just hurt when I read this. And I am not one of those "Oh noes, this is evil dotnetififaction!" kind of people. And btw while .NET has ToString for everything (which I find useful) it does not have these kind of methods for Int32 or the other types.
ReplyDeleteBut the TBooleanHelper.ToInteger implementation is worse imo: Result := Integer(Self);
I think i.IsNotZero would be much better than i.ToBool under many respects.
ReplyDeleteGiacomo Degli Esposti Guesz I'm a luddite but I'd prefer a free function. Of course, templates would make that easier...
ReplyDeleteif i.IsTrue then .. looks better for me
ReplyDelete