The pack-unpack hack
Hacks should generally be avoided. Generally, if you need to use a hack, you’re probably going against the design/purpose of the framework/language. There is likely a better way of doing it. You just have to find it.
Unfortunately, hacking the code seems the quicker and easier solution. In the long run, it’s not.
Often, I’ll get a feeling that what I’m coding is hackish. I stop, take a step back and look at what I’m trying to do. Usually, especially with views and controllers in a Rails project, I find myself doing the pack-unpack hack. This is where I add something extra in one section of code (pack) that I then need to deal with in another bit of code (unpack).
In views and controllers, the usual culprit is creating a local variable in the view to hold some data that I tack onto a link in order to pass the data to a controller. Once in the controller, I then extract this data for use with whatever I’m trying to do. Definitely a hack!