Archiv der Kategorie: Hacking

My code sucks.

Cha­sing a link via Twit­ter, I recent­ly read Your code sucks. Having gone over a lot of other people’s code mys­elf, and wri­ting code for long enough to have a good histo­ry of my own work to go over, it reso­na­ted with me. 

I recent­ly had the misplea­su­re of debug­ging a pie­ce of code that I wro­te almost ten years ago. It was, in many ways, pain­ful to read. Alt­hough I still use the same lan­guage as back then, things have way evol­ved: The lan­guage, for one. Deve­lo­p­ment tools. (Well, not mine: I still use Emacs.) But most of all: My know­ledge and my men­tal hori­zon in pro­gramming. I’ve loo­ked at various other things to enrich my skill set, brin­ging to my own coding habits tools that work well in other lan­guages. I also got to under­stand the tools I use bet­ter (espe­cial­ly data­ba­se tools – tho­se are so rich, and so few tools ever real­ly use them). So, with that expe­ri­ence in mind: My code does suck. But I much pre­fer some­thing that I wro­te ten years ago to be pain­ful to read, becau­se it means that I have lear­ned a lot. Even though I feel gre­at satis­fac­tion with the things I wri­te today, I am sure that in ano­t­her ten years time, I will look back at todays work and feel a slight sen­sa­ti­on of being asha­med of what I did. 

And this hum­bles me in rea­ding other people’s code. It does not hurt to assu­me com­pe­ten­cy in others; they may have dif­fe­rent rou­tes they take in sol­ving pro­blems. But if one gets to think like they do, under­stand why they wro­te the code the way that they did, that cer­tain­ly may lead to your taking away some­thing for yourself. 

Now, if only ever­yo­ne adhe­red to K&R inden­ta­ti­on, I could read all the other people’s stuff so much more easily …


For a pro­ject that we are cur­r­ent­ly imple­men­ting, we’­ve asked our­sel­ves what the best way to access the data­ba­se would be. So far, a num­ber of our pro­jects had been rea­li­zed with Pear DB, and that was most­ly okay. The cur­rent pro­ject needs to be reson­si­ve even under high ser­ver load, so we try to cut away all the slack we can. So we did a few benchmarks. 


PDO, in cer­tain cases, is up to 4 times as fast as Pear DB. 


In the office, we cur­r­ent­ly have about 120gb of disk that need regu­lar back­ups. We wan­ted to have a solu­ti­on that enab­les us to store off­si­te copies easi­ly and was­n’t too expen­si­ve. Tapes were out for hand­ling rea­sons – tho­se dri­ves that we were wil­ling to afford would have meant a sys­tem of cas­ca­ded incre­men­tal back­ups, making res­to­ra­ti­on of sin­gle files a tape-shuf­fling issue. DVDs don’t hold enough data and their sto­rage times are not yet ful­ly unders­tood, so that did­n’t qui­te sound so prac­ti­cal, either. 

In the end, we deci­ded to out­fit one of the older machi­nes around (a Pen­ti­um II) with remova­ble hard disks (nor­mal Wes­tern Digi­tal 160 GB dri­ves, fit­ted into run-of-the-mill alu­mi­ni­um mobi­le racks). We have two dri­ves fit­ted into a car­ria­ge, so there’s always one at home and one in the machi­ne. During the day, the appro­pria­te machi­nes copy their data onto that one volu­me over the net­work and I can take along the disk in the evening, brin­ging the other one next morning. 

Most of our machi­nes run Net­BSD so I’ll just quick­ly run down the very basic con­fi­gu­ra­ti­on, we have here, but it should also work with many other unix-like ope­ra­ting sys­tems. Ope­ra­ting sys­tem and all esen­ti­al stuff is on a disk that always remains in the back­up machi­ne, the back­up volu­me is a dri­ve off the secon­da­ry IDE controller. 

The machi­ne is only powe­red on when the disk is in, so there’s no cho­king on mis­sing disks – this could be avoided by using a hot­s­wap-enab­led IDE con­trol­ler, but cur­r­ent­ly, we don’t have that need. As soon as the disk goes in in the morning, the machi­ne is powe­red up, boots and shares the back­up volu­me via NFS. The other machi­nes (all run­ning Net­BSD) have that volu­me in their auto­moun­ter. Scripts are star­ted that use dump(8) to copy their appro­pria­te sli­ces onto the back­up dri­ve. As soon as they’­re all finis­hed, the machi­ne powers down again, wai­t­ing for the dri­ve to be taken out. 

And that’s all the­re is to it!

Pri­ce of the machi­ne: prac­ti­cal­ly not­hing, we had that alrea­dy. We even had an empty 4U 19″ enclo­sure, so it’s gone into the machi­ne rack.
Pri­ce of the dri­ve enclo­sures: 25 € each, making it 50 €
Pri­ce of the hard disks we’­re using today: star­ting from 80 €
That makes our con­fi­gu­ra­ti­on total 210 €. Not bad for 160 GB of back­up storage.