Orthonormal polynomial bases in function spaces