It really depends. In general I prefer charging by the task but that assumes a well-scoped and predictable task. That works for some things and not for others.
Of course, there are a number of professions (law, accounting, etc.) where hourly charges are absolutely the norm. I've done some legal work and it was in some ways very nice to get paid whenever you were "on the clock."
I agree with Alan Weiss, lawyers are unprofessional and mostly terrible at maximising income. They charge 1:1 hours to fees which is a bad deal for a professional.
The legal work I did was for an expert witness case as a subject matter expert (not a lawyer). There is no way we could have/would have agreed to a fixed fee up front unless it was for a really outrageous amount. (Well, it ended up being a pretty outrageous amount anyway but there's no way we could have reasonably scoped the work.)
Most of the work we did in general was for specifically scoped deliverables and we actually tried very hard not to do day rates, much less hourly rates, but this was one case it really wasn't avoidable--and, of course, was the way the white shoe law firm operated.
The point is that we would have had no way of pricing "value" up-front. It wasn't our primary business (which we mostly did price based on value). So charging $500/hour (or whatever it ended up being) made a lot more sense for everyone than just throwing a $100K invoice out there when we really didn't have any idea what sort of time commitment we were looking at.
Of course, there are a number of professions (law, accounting, etc.) where hourly charges are absolutely the norm. I've done some legal work and it was in some ways very nice to get paid whenever you were "on the clock."