Analysis and design of optimal discontinuous finite element schemes