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."