The Massachusetts law, signed by Governor Deval Patrick Aug. 3, requires creditors to take “commercially reasonable” steps to avoid foreclosing on certain mortgages if by modifying the loan the lender would realize a greater return­ than it would in a foreclosure.