When to charge by the hour
Most professionals ought to charge by the project, because it's a project the customer wants, not an hour.
Surgery, for example. I don't want it to last a long time, I just want it to work. Same with a logo or website design.
Or house painting. The client is buying a painted house, not your time.
One exception: If the time is precisely what I'm buying, then charging by the time is the project. Freudian therapy, say, or a back massage.
Another exception: If the client has the ability to change the spec, again and again, and the hassle of requoting a project cost is just too high for both parties. A logo design, for example, probably starts with project pricing, but if the client keeps sending you back for revisions, at some point, they're buying your time, aren't they?