Saturday, May 29, 2004

What is a hack?

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.

  • Usually makes your code harder to maintain

  • Fragile code, breaks easily when the code it depends upon changes

  • Hard to port to other platforms

  • Refactoring, improving the design, is often a better solution

  • Pros:
  • No other way to perform a task - the alternative is to rewrite or re-implement OPC (Other People's Code)

  • Potential for improved performance

  • Curiosity, gaining a better understanding of the system

  • Its great fun!

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

    No comments:

    Copyright © 2004-2007 by Hallvard Vassbotn