A programming approach for nonsmooth structural optimization