Copy And Paste / RYRY

Written by David Frampton @ 10:27 am, June 23, 2009

I have heard that copying any part of your code and pasting it somewhere else in your code is bad. The argument usually goes along the lines of ‘You needed it twice, so you should make a function’. OK, I’m thinking that maybe seems kind of reasonable, but I have to ask. WHY? ‘Because then when you need to make a change to that functionality, you can make it in the function, instead of two places in your code.’

OK so if both callers of that code need the same change, I can change it only once, instead of twice. Great! So making a whole extra function, making it callable from both places, passing in all the crap it needs from both places means that on the off chance that both of those use cases change in exactly the same way, I need only change the code in one place?

I don’t think so. I’ll change two places. In fact more than likely I’ll change one place. Or maybe I’ll change one place to do something a bit different, and then change the other place to do something completely different. And, I can do so and not worry about affecting anything else.

Screw DRY. I say repeat yourself, and then repeat yourself again.









The California Gold Rush

Written by David Frampton @ 8:54 pm, June 18, 2009

Way back in 1848 (give or take 160 years), gold was discovered on a large estate in Cupertino, California. This estate was owned by one Mr Appleton.

Mr Appleton decided to mine the land in a very unique way. He invited miners from all over the world to work a claim for a mere $99 a year. In exchange for this cheap entry fee, the miners could not sell the gold themselves, but instead handed it over to Mr Appleton. Mr Appleton would then deal with the shipping and selling of all the gold, and give the miners 70% of all profits.

This deal was fantastic, and the estate turned out to be very, very rich in gold, so miners flocked in faster than Mr Appleton could collect the $99 fees. Everyone who had even seen a pick axe in a store was now a miner and a new claim was staked every ten minutes, twenty four hours a day for the entire first year.

But it wasn’t just individual miners working the estate, it was also noticed by the bigger, more established mining companies like ‘Mechanical Arts’ and ‘BottleCap’. These larger firms began to use their huge quantities of geologists and miners to find the best claims and quickly suck the gold out. Unlike normal mining operations however, their distribution mechanisms and relationships with the merchants were of little use here. Individual miners could work rich claims right next to these big companies on a utopian level playing field, the likes of which had never before been seen.

It wasn’t all plain sailing, however. Mr Appleton had some curious whims when it came to the quality of the gold he would accept. On one particular occasion Mr Appleton quietly changed his standards, and one sneaky snake oil sales man pounced on the opportunity. The salesman employed a miner to mine dirt instead of gold, and Mr Appleton just started letting it though. The merchants were momentarily confused by this new ‘gold’ so at first paid just as highly for it. After a while, though, they realized its worth, and though any nuggets shaped remotely like human genitalia or colored similar to Mr Appleton’s own prize nugget were rejected, dirt was let through where it accumulated in huge unwanted piles around Mr Appleton’s store houses.

Mr Appleton also had some rather unusual communication policies with the miners. When Mr Appleton forgot to pay the miners or was still pondering whether to accept the nugget that looked a little like a nipple if you tilted your head to the side and squinted just right, he could be contacted only by telegram. The problem was that all responses were typed by one of a dozen monkeys trained to give one pre-formatted response. On one occasion over a thousand miners cornered a representative of Mr Appleton on a stage where they attempted to ask questions, but the representative sprinted off the stage and escaped behind the curtains.

There was still money to be made however, and over time many miners became very wealthy from Mr Appleton’s estate. Though the easy pickings were gone, there was always a handful of miners pulling thousands of dollars worth of gold a day from their claims. Despite whimsical and sometimes completely non-sensical management, the gold rush on Mr Appleton’s estate changed the mining industry forever.