Tip #209: Who’s your sister?

When it comes to the coding, not always but often, less means better, faster and more manageable code. I’ve recently come across of someone else’s (could it have been me 4 years ago?) piece of work updating bulk email setting for the contact:

Contact contact = 
        "contact", contactId, 
        new ColumnSet(true))
contact.DoNotBulkEMail = true;

Sigh. The “all columns” sin aside, the retrieve is absolutely unnecessary. You know what to update, why wouldn’t you just send that information over and let the server do its job?

   new Contact()
      Id = contactId,
      DoNotBulkEMail = true

And no, “new” operator will not create a new contact record. Always remember, brevity is the sister of the talent.

Leave a Reply

Your email address will not be published. Required fields are marked *