Before we move on to even dirtier and more dangerous hacks, lets first define what constitutes a hack. IMO, a programming hack must fulfil the following criteria:
A hack uses a non-sanctioned way of performing a task - it bypasses official and documented APIs. It uses a "clever" and non-intuitive method to perform a task that would otherwise be hard or impossible to do.
The general advice is to avoid hacks in production code. Hacks can be very useful as short-term solutions during research and development, but is best replaced with refactored code and design before going to production. That said, most real-world software contain the odd hack or two.