For criticisms of things like code (or art), I think of that as "criticize the thing and not the person".
Bad: "You don't know what you're doing. This is poorly-written code that will perform badly on bigger datasets. "
Good: "The runtime of this code is prone to grow exponentially. A different algorithm will get around this. "
As much as possible I try and criticize from the viewpoint of wanting to make the work better instead of from wanting to bring down the person that did it.
Edit: To add - I will very possibly be _wrong_ about the definition of better, which is something else I try and keep in mind.