Bob Martin’s eliminate boolean arguments tip – an example

I don't always agree with Bob Martin's Clean Code Tip #12: Eliminate Boolean Arguments - probably because the mathematician in me believes that there are such things as functions of a boolean value - but I came across an example in a WinForms app today where I'd apply it.

void FindApplicant(int id)
{
    processUIChange(true);
    applicant= getTheApplicantFromDataLayer(id);
    processUIChange(false);
}

turned out to mean:

void ProcessUI(bool processing)
{
    if(processing)
    {
      this.Enabled=false;  
    }
    else
    {
       ... do a whole load of stuff
    }
}

which would have been easier to read as:

void FindApplicant(int id)
{
    DisableUIWhileUpdating();
    applicant= getTheApplicantFromDataLayer(id);
    UpdateUIAfterDataChange();
}

void DisableUIWhileUpdating()
{
    this.Enabled=false
}
void UpdateUIafterDataChange()
{
    ...do a whole load of stuff
}

C# : To return a comma delimited list from an array or collection of strings

Don't:

            var description = new StringBuilder("");
            foreach (var item in productItems.Where(x => x.ItemType == type))
            {
                description.Append(item.Description + ", ");
            }
            return description.Remove(description.Length - 2, 2).ToString();

Do:

return string.Join(", ", productItems.Where(x => x.ItemType == type).Select(x => x.Description).ToArray());

because the first example fails when your collection has no elements.