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

Comments

  1. Assuming it's implemented right (ie. equivalent to "<>0"), why not?
    I regularly see creative re-interpretations ("=1", ">0", etc.) of the numeric to boolean convention.

    ReplyDelete
  2. 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.

    But the TBooleanHelper.ToInteger implementation is worse imo: Result := Integer(Self);

    ReplyDelete
  3. I think i.IsNotZero would be much better than i.ToBool under many respects.

    ReplyDelete
  4. Giacomo Degli Esposti Guesz I'm a luddite but I'd prefer a free function. Of course, templates would make that easier...

    ReplyDelete
  5. if i.IsTrue then .. looks better for me

    ReplyDelete

Post a Comment