Search Results: "Matthew Palmer"

12 December 2007

Matthew Palmer: E-Commerce, thy name is mud

So much for the idea that you can buy anything you like online, whenever you want. My laptop's screen has been acting dicky lately, and research suggests the most likely candidate is the backlight inverter. Luckily, there's online guides that show me (with pictures!) how to get at that and get the FRU number off it. Easy so far. Now I just need to find a new one. $SEARCH_ENGINE to the rescue. Plug in the FRU number and up come pages and pages of results. Oh goody, I should have no trouble here. Except that, when I visit this myriad of sites, there's a lot of similarity in pricing and content (not the look of the sites -- no, they're all completely different -- just the prices and textual descriptions). I've only managed to identify four separate stores, from visiting a good couple of dozen search results: My choices, then, are: extortion, impossibility, slow extortion, or probable scam artist. What a set of choices. So, I've come to the conclusion that e-commerce is a complete and utter joke unless you're in the US. So much for the global market and all that bollocks. Back to shopping the old-fashioned way for me.

5 December 2007

Matthew Palmer: Strategists and Tacticians

Like most things, the scale of decisions that have to be made by a person or organisation fall across a wide spectrum. At one end, you've got the fine-detail work: lines of code, individual config settings, IP addresses, that sort of thing. This is crucial work, because it's this detail that ultimately produces saleable results. Travelling all the way to the other end, there's the "big picture" decisions: the "visionary" stuff. What market segment will we target? What will we do (in large-scale terms) to get there? I am convinced that individuals naturally gravitate towards one end of this spectrum or the other, depending on their psychology. While people usually can work at all scales, they have a "most comfortable" point where they work the most naturally. The further away from this point they are pushed, the less comfortable and effective they are. No level of thinking is better or worse than the other; they're just different. While "large scale thinker" and "small scale thinker" could be taken as being insulting, I certainly don't mean it that way. I should point out that "Strategy" isn't (just) about setting goals. A strategist isn't someone who comes out with grand pronouncements like "By the end of next year this company should be providing telecommunications services to 20% of the Fortune 500" without knowing how to get there. That's not a strategist, that's a poor-quality management consultant. People whose only skill is making vague pronouncements should just be taken out and shot. They're not doing anything useful for anyone. A strategist is someone who is good at planning the goal of "20% of the Fortune 500". They're thinking about the big picture issues, without getting bogged down in the minutiae. A tactician, given the job of planning something at the macro scale, will chase some good idea down an intricately detailed rabbit hole, and miss the other dozen or so large issues that need to be considered. The strategist's planning needs to stop at a certain level and let other people take on the detail work. Conversely, a good tactician can focus on the individual details without getting distracted by the big picture. A strategist put into a tactical role will miss all the important minutiae because they're working out how their little part fits into the big picture, instead of working out how to make their little part work, in and of itself. It's important, for individual happiness, to try and work out what level you're most comfortable thinking at, and then trying to find a job that puts you there. It's almost as important to make sure that the people who are working at the more and less detail levels around you are equally comfortable. Take, for example, the micromanager. We've all either been there ourselves or have heard multiple stories on the subject. I think the micromanager is nothing more than a person who wants to work at a smaller scale than they're being forced to by their organisational rank. Since they can't do the detail work any more, their only outlet is working vicariously through their subordinates. Voila! Instant micromanagement. An even more painful case of micromanagement would be when the subordinate wants to think at a larger scale than the superior. In that case, the subordinate will naturally be thinking large scale, and will miss the details. To the small scale thinking superior, that is incompetence, and will naturally be dealt with by more micromanagement. In reality, both parties are incompetent at their jobs, and they should really swap roles, so that everyone is in their element. It would be nice if companies stopped thinking hierarchically in this way -- that a more "senior" person has to think at larger levels. Just because you've been somewhere longer (or have been working in an industry longer, or got higher marks, or whatever), it doesn't mean that you're more of a strategist. This is probably the Peter Principle restated: people get promoted to a level where they just can't comfortably think at the necessary scale any more. If instead people were put into a planning hierarchy based on their natural scale of thinking, we'd all be a lot better off. There'd be a lot less power games, though, which makes me think it's not going to happen any time soon. A business, at whatever size it might be, needs an appropriate mix of strategists and tacticians. A really small business (1-10 people) can get away without needing large scale thinkers, in the same way that a really small boat can get away without needing a rudder or pilot. If a really small boat gets itself into trouble, everyone on board can grab an oar or bucket and help get the boat out it's predicament -- it's small and nimble enough to be able to do that. As the company expands, though, it's important to make sure you've got some strategists around. If you don't have anyone to keep an eye out for problems and plan around them, your small-to-medium sized boat is likely to have a hole punched in it by a submerged rock. Even if somebody on board happens to notice the rock before you actually hit it, once you get to a certain size you can't physically stop or turn the boat in time. If you don't understand the growth issues in the company, you might not even realise that you're no longer the nimble and low-inertia dinghy until you're up to your knees in sea water. Although an obvious solution to this problem might be to say that all businesses should be small and nimble ones, it's as impractical as saying that all boats should be dinghies. A fleet of dinghies isn't going to be able to support the worldwide sea freight market, and a fleet of small companies doesn't have the necessary resources on hand to take on the big projects that are so often needed. Also, a dinghy is at risk of being swamped by one freak wave, while a larger ship can weather significant storms without going under. Regardless of the size of the business, there always needs to be a good supply of tacticians. A boat (of whatever size) full of people who are all looking out for rocks isn't going to go anywhere, because nobody's making the thing move. Similarly, a company full of strategists isn't going to be doing any of the day-to-day work that actually earns money, and no money means no company. The single most important thing, though, is be self-aware enough to know what sort of person you are, and try to find something that lets you work at the level you're most comfortable at. Otherwise you're just setting yourself up for unhappiness.
(I'm not really sure why I'm suddenly writing management blog posts; this idea of "levels of thinking" just came to me and I figured I'd put it out there. If it makes you feel more comfortable, there's a fairly transparent mapping of these ideas to the practice of software development, although I'll leave the execution of that mapping to the reader. Comments are welcome.)

29 November 2007

Matthew Palmer: Stupid

I think these log messages really speak for themselves:
2007-11-29 13:17:10,6,smsd: I have to send 2 messages for /var/spool/sms/checked/smsgw.out.CWlda8
[...]
2007-11-29 13:18:54,4,smsd: Sending SMS to 0421XXXYYY on GSM1 failed
2007-11-29 13:18:54,6,smsd: Deleted file /var/spool/sms/checked/smsgw.out.CWlda8
"Retries? We don't need no stinkin' retries!"

11 October 2007

Matthew Palmer: EBay Sez: Linux is for scammers

In what I can only assume is a case of "graphic design spec gone horribly wrong", EBay has decided to portray our lovable penguin friend as the mascot of the online scam artist: Linux is for scammers, says EBay (Click on the image for a full-size version) Personally, I think the scam artists' best friend is a Windows machine, as it provides a rich source of untraceable connectivity, but my guess is that Microsoft has scarier lawyers. I don't know how long the image has been up there for, but I'd imagine it won't last long. Linux users may not be that numerous, but we're a noisy lot. <grin>

3 October 2007

Matthew Palmer: That Didn't Take Long

Although I predicted that I'd be a busy boy with my bushfire brigade on Tuesday, I wasn't expecting to get our first "Bush Alight" fire call so quickly. But, yesterday (Wednesday), a few minutes after 1800, off goes the pager, and off I go to the station. Thankfully the high winds that had been a major feature of the day had settled down quite a bit, so it was relatively easy to control and stamp out (we were back at the station by around 2015) I still found it a little overwhelming -- "I'm supposed to help Stop This Fire". At a couple of hectares in size, it wasn't too massive, and it wasn't visually "spectacular" (like the fires you always see on the news) but still... given that my only experience of fire in the past has been small campfires and the occasional bonfire, having an area the size of a football field in front of you glowing with embers and flaring with small clusters of flames, it was certainly a very different experience. The heat, the smoke, the noise (those truck pumps are loud), and the adrenalin, it's a hell of a mix. Being that I'm the newest and least experienced crew there, I got given the unglamourous but important job of controlling traffic, as we had one lane of the one-each-way 100km/h road closed to give our crews more working space around the trucks. Let me just say that I now have an infinitely greater respect for road repair crews, and I think that every person should do an evening of traffic control with a group of their mates on the road behind them, so that they know what it feels like outside their car. Car drivers do the darnedest things. So, I've popped my bushfire-fighting cherry now, and I'd be more than happy if there's nothing more impressive than that awaiting me for the rest of the season.

2 October 2007

Matthew Palmer: That ain't no *disco* inferno

We're a third of the way through spring, and already we're hitting temperatures that would be a respectable mid-summer day. Tomorrow has also been declared a Total Fire Ban day in our area. That's probably nearly unheard of, especially given the large amount of rain that we've had over winter. I think I'm going to be a busy boy this summer. The bush around our town last had a bushfire through it seven years ago, and there's a regular seven year cycle of major bushfires. We're due for it. As this is my first summer as a qualified bush firefighter, I'm a bit twitchy about what the continued hot, dry weather may bring. Here's hoping it's not too horrific.

29 September 2007

Matthew Palmer: The Plain Text PDA

(or: Why Everyone Should Learn Some Basic Programming) I am an organisational disaster area. I just can't remember "event oriented" information (like "I need to do $foo" or "I need to do $bar at $time"). I think I've accumulated such a huge collection of technical trivia that it's taken over the event planning part of my brain -- although, since I've never been able to remember event oriented information, even before I became a computer geek, it's more likely that I was just built without that bit of the brain. So I guess I'm the perfect target market for some sort of external brain pack (a la "Ratbert the Consultant"). I've tried paper-based organisers (the mighty Filofax), a few pre-written apps, and I even bought an SL-C3200 Zaurus a while ago (although, to be fair, that was really just for the hack factor, regardless of what justification I may have given to others at the time). None have worked, for various reasons. I can't grep paper, and Other People's Apps bug me because they've got their idea of workflow, and I've got mine, and when they don't match up (and they never do) I just get irritated -- not to mention the fact that the ubiquitous relational database, while wonderful in some ways, does tend to get in the way of ad-hoc faffing with your data. But this article is a success story, not a rant (gasp!), so it's safe for you to assume that I've got something that's working for me. My method is real simple -- plain text files, managed by vim-outliner and a simple shell one-liner I've named 'pda', which just runs vim ~/pda/$1.otl. At the moment I've got a monster todo.otl, which is my world's todo list, and a deeply underused calendar.otl. I'm also using vim-outliner to do some project planning, which has been moderately successful, although I'm a bit freaked out by the idea of trying to manage a large-scale project using it. The really, really cool part of this whole shebang, though, is that because all of my data is (structured) plain text, writing little programs to parse the data and do funky things with it is dead simple. For example, in my project outlines, I put estimated, actual, and remaining times in for all tasks (a la Joel Spolsky's Painless Software Schedules) so I can keep track of my estimates and where they differ from reality (because one day I'd like to not Suck at estimating times, and feedback is the only way I'm going to do that). So, about an hour's worth of Ruby gave me "estimator", a script that reads all that data and does a pile of mathematical gubbins about how far over my estimate I am so far (or under estimate, if that were to ever happen), the percentage of the project complete (based on the estimates and number of tasks completed), and things like that. Similarly, today I wrote a small script (run out of cron in the wee hours of the morning) to read my calendar and send me an e-mail if I've got anything in there for today. Since I practically live in mutt, a morning e-mail is going to be far more effective than my trying to remember to check my calendar every morning (especially since, at present, I'm not using the calendar as often as I should, so there's even less motivation to check it). This, in my opinion, is why everybody (literally, every single person) should learn to program at some fairly simple level, like learning to read and write. By using plain text and small scripts, I've got a workflow that works for me, and it's cost me less time than I'd spend learning some large pre-written app and putting all my data into it. Being able to manipulate data like this is, I think, a fairly important tool in the modern world, and I don't think it should be left to any sort of priesthood of developers -- it should be as universal as most countries try to make literacy and numeracy.

20 September 2007

Matthew Palmer: Suing over Software

Colin Charles, writing about how "Linux isn't ready for the laptop" (no link -- I don't link through FeedBurner's shite):
However, I should caution all these companies from even going near Linux with a ten-foot pole. Quite simply, this is because Linux doesn't work. If their product doesn't work as advertised, what are the chances of a customer possibly suing them, for a product that isn't fit for purpose?
Puhlease. As Microsoft has convincingly demonstrated over the years, the chances of a consumer suing over non-functional software is zero, even after being shit on from a great height for nearly two decades.

18 September 2007

Matthew Palmer: Documentation: The Chicken and the Egg

The other day, as I was putting a couple of pages of documentation together for a company-internal development project, I got this terrible feeling of malaise about what I was writing. "Why the hell am I bothering writing this lot? It's a given that nobody's ever going to read it." Why? Because nobody reads documentation. Funnily enough, I tend to work the other way, too. While I will often go looking for help through Google, checking for assistance in structured, project-produced documentation (manuals, et al) is usually one of the last things I'll try. Why? Because nobody writes documentation. Now, given that I feel minimal motivation to write documentation because nobody reads it, and I don't usually read documentation because nobody writes it (probably because nobody reads it), an obvious question comes to mind: did one of these states come first, which then caused the other? Are we in an ever-deepening spiral of shite docs, the logical end of which is just giving up and reverting to code reading and experimentation?

14 September 2007

Matthew Palmer: Free To Good Home...

Slightly used Leopard main battle tanks. One owner, always garaged, great for soccer mums and men with very small penises.

30 August 2007

Matthew Palmer: "Printer Friendly"

Obviously some people have a much, much better printer than me, because the "Printer Friendly" link I just clicked on took me to a page with a flash ad at the top of it.

24 August 2007

Matthew Palmer: APEC Provocateur?

So it would seem that the forces of "justice" in Canada might not be above a little shit-stirring to cast their opponents in a bad light. Considering all of the hoo-hah around the security of the upcoming APEC meetings in Sydney, I wonder if the local constabulary has any similar plans? Remember, if you're planning on protesting the senseless waste of money that is APEC, carry your ID at all times, to prove you're a legitimate protester and not a security shill! <grin>

14 August 2007

Matthew Palmer: Dangerous Merging

Andrew Cowie, talking about Orthogonal Patches, believes that having your revision control system assume that patches which are the same text is the same is a good thing:
If X = B [in the java equals() sense], and if Z = D..E, it's no problem, because when the day comes that X and Z are merged to some branch which happens to be the public mainline, and you later pull from that public branch, then X and B will "contend" and merge without conflict, and likewise Z will merge without conflict. It's all the same text. Mission accomplished.
If you think this is right, "think about two different patches each adding a new keyword and also changing the line #define NUM_OF_KEYWORDS 17'' to #define NUM_OF_KEYWORDS 18''." (example taken from the darcs manual, because I'm not going to come up with a better example than that).

8 August 2007

Matthew Palmer: Just so I'm not accused of being a coward...

Since MJ Ray seems to think that anyone who doesn't vote for him but doesn't tell him why is a coward, I'm going to be up-front about it so I can't be accused of cowardice. Elections are all about everyone making their own decision, for their own reasons, in the hope that the aggregate of those decisions will produce a useful and workable result. (Whether that happens in reality is a whole other issue). The individual's decision is a statement of their opinion, nothing more. Adding confidentiality to the voting process is meant to remove any pressure from the voter to make a decision on any basis other than their own opinion. Complaints about it like this from a candidate is pretty weak:
There seem to be some 30 or 40 voters who really dislike me, but didn't tell me that straight, preferring to be silent then vote me down. Are you cowards, or what?
Given this outburst, I'm hardly surprised that people weren't keen on telling Mark upfront that they weren't going to vote for him. (As a disclaimer, I didn't vote in the SPI election, because I don't have a specific opinion on any of the candidiates' suitability for office on the SPI board.)

22 July 2007

Matthew Palmer: Why I'm Afraid of Flying

I'm happy to admit it -- I have a fear of flying. Strangely enough, though, my anxiety levels peak somewhere between 3 hours and 30 minutes before the plane takes off. Once we depart the terminal building, I'm fine -- the takeoff, cruise, and landing hold no fear for me, in fact I rather enjoy it. When I have the money and time, I plan on learning to do it for myself. The thing that does freak me out, though, is aptly described in this article. The idea that I could possibly suffer a similar fate, or worse, concerns me. The arbitrary nature of security screenings, and the fact that I cannot, through my own actions, ensure that I will not suffer at the hands of a security service when I have done nothing wrong really scares me.

17 July 2007

Matthew Palmer: The Trials of Browsers

Since I'm a member of the set of people "somebody better suited to explaining it" mentioned in Silvia Pfeiffer's "A Long Story of Logins", I suppose it falls to me to explain what the hell we actually did to make the thing work. A quick recap, for anyone who hasn't read Silvia's article: the Vquence website is a very AJAXy, Web 2.0 style video socialisation site. Since we want the site to be available to all as much as possible, we don't lock any part of the site away behind a "login required" page unless we absolutely have to. An unpleasant side effect of this is that, when it does does come time for you to login, pushing you off to a separate "please login" page is going to be, well, a pest. There's all sorts of state about what the user is up to (it's a web-based video mashup creator, after all) that we need to submit -- but only after the user has logged in. Enter the realm of the Web 2.0 Login. Instead of sending the user to a login page, getting them to login, and then redirecting them back to where they want to go, you just have some sort of popup form that, when submitted to, does a background request and logs the user in behind the scenes. This isn't a new concept by any means -- for example, try voting up or down a link on reddit when you're not logged in. However, most sites that implement this sort of thing (based on our brief informal survey around the office) don't protect the password information in any way -- it goes over the wire as a plaintext HTTP request. We don't like this, so we wanted to send the login form over HTTPS. And there began our problems. The trivial implementation of a Web 2.0 Login page is as you'd expect -- the AJAX stalwart, XmlHttpRequest, POSTing to a handler somewhere that validates the login, sets a session, and sends back some javascript to change the page layout a bit to show you're logged in. We had this working nicely, until we started testing on our staging environment, where HTTPS comes into play... You see, XmlHttpRequest doesn't like making a request to a domain other than the one that the main page comes from -- for security. It also thinks that the same hostname via a different protocol counts as a different domain, for the purposes of this security check. (I can see the theoretical reasoning for it, but it is a bit weird for HTTP to HTTPS transitions) So if you want to POST to https://www.vquence.com/something using XmlHttpRequest, you need to be doing it from a page which is retrieved from somewhere in https://www.vquence.com/ as well. We considered just turning on HTTPS across the board, but that would have all sorts of unpleasant ramifications, so we decided against that. But the problem remained, how do we get the user's credentials to our server in a secure manner with a minimum of unpleasantness? We came up with all sorts of options. This is where the infamy of "bug #93" started -- it's a monster of a bug log. Lots of it is me going "we could do this, but it'd suck, or we could do this, but it would suck". Finally, Silvia (I think) suggested we look at using an iframe. "Eeew" was the general response, but it might at least give us a way to set a part of the page to HTTPS, which we could use as a launching point for our XmlHttpRequest call. While researching how to make this all work (I had, to my great pride, never inflicted an iframe on the world before), I managed to come across a few articles on how you can use a hidden iframe to handle requests instead of using XmlHttpRequest. Basically, the trick is that you do a regular POST on your main page, but set the target of the form to a hidden iframe in your page. A general discussion of the principle is available At the Apple Developer site, and there's also a Rails plugin that implements the concept rather nicely. When I found these, I briefly danced for joy. My quest was over. POST to the iframe, the iframe get some JS back from the server, JS mangles the main page's layout to show the user is now logged in... aaaand profit. Like fun it was. My implementation was short and sweet -- a true work of genius (if I do say so myself). Everything worked like a charm. Until we got it back into staging. Then cross-domain security bit me again. Naturally, if you don't want XmlHttpRequest calls to perform cross-domain, you probably don't want iframes for different sites to be manipulating each other's content either. That's exactly what happened -- the iframe can't manipulate the main page's layout as we need it to. Why I didn't think of this before I charged mightily ahead I don't know. My only defence is that I've never claimed to be a web development guru. Sneaky tricks will defeat any security measure, though. For instance, we control both sites (http and https), so we can send the user back to the unsecured site after login and then that location (still in the hidden iframe) can manipulate the main page layout. Redirect to the rescue! That worked really well in Firefox, even with HTTPS in staging. We were saved. At least until IE came along. Bloody Microsoft, ruining all my cunning plans. IE complains when a HTTPS site redirects (using the Location HTTP header) to a HTTP site. You apparently can't turn this off. I was shocked that Microsoft cared so much about their user's data security -- it's certainly not the first thing I think of when I think "Microsoft". My faith in the world was restored when Silvia pointed me to a workaround for the problem -- if you send the redirect in a <meta http-equiv="refresh"> tag instead of a Location header, IE is more than happy to let it pass. Because obvously a chunk of HTML that says "HTTP equivalence" is completely different to a HTTP header. Sheesh. To snatch defeat from the jaws of victory, after all this brilliant hacking, I managed to make a newbie error with the contents of the http-equiv by setting the content to "0;http://www.vquence.com/blah" instead of "0;url=http://www.vquence.com/blah" (note the url=, because I sure didn't). IE complained by looping infinitely on the source URL, while Firefox just made sense of it and did the right thing. I managed to waste most of an hour of three of us over that little stuff-up. Go me! (Sorry about that guys, by the way) Feeling very chuffed, I went home for the evening. The next morning saw a browser compatibility defect in my queue -- Safari didn't like the new setup. Instead of doing the right thing, clicking on the login button would create a new tab instead of logging in. The fix? Changing the style of the hidden iframe from "display: none" to "width: 1px; height: 1px; border: 0" did the trick. Fark. So much for "hidden" iframes. What's particularly funny is that Apple's own tutorial on hidden iframes says to avoid "display: none" because NS6 doesn't like it, but doesn't mention it's own glaring deficiency in this area. So, what are the lessons learned?

9 July 2007

Matthew Palmer: Hell is other people('s code)

I've been working (part-time) on an existing Rails application for the last month or so, getting comfortable with it, modifying some sections to support needed functionality, and beginning an all-out, carpet-bombing "shock and awe" assault on it's test suite. However, a significant portion of the system is (or rather was, since I've already gutted a lot of it) a chunk of rather messy and unpleasant auto-generated code. I've always been a bit iffy about code generation tools, ever since my first encounters with them whilst working on some $DEITY-awful access application years ago. (First encounters with anything Microsoft usually have that effect on me, though). Since then, I've never found any reason to change my mind, and dealing with this particular chunk of auto-generated code has pushed me over the edge into "wild-eyed extremist" territory. Please note that when I say "code generator", I'm talking here about programs or wizards or whatever that create a block of code that you're then expected to tweak to suit your conditions. If it's just a mechanical transformation of an input format to an output format, where a human is never expected to maintain the output by hand, that's not code generation in my book -- that's just a compiler being used for it's intended purpose. I like compilers. I'm fairly sure you do too. Code generators, though? EVIL. Consider what you get out of your generator: A big blob of code in your application that you then have to understand and maintain. It's like you gave a commit bit to some random person who dropped a 5000 line change into your tree and then ran away into the night, cackling. If there's bugs in the generated code (and remember, there's always bugs in software), when they get fixed upstream you're up the creek unless you haven't modified the code at all (and thus can regenerate), or you're willing to apply the necessary patches to your modified version, often by hand. Hand-patching is error-prone, and if you've modified the code at the same place that has to be patched, things can get unpleasant. In the case of the generator I'm dealing with at the moment, I'm not even blessed with it being decent code. It's ugly code, in every possible sense of the word. There's inconsistent formatting, poor commenting, it uses some totally whack coding constructs[1], the hard-coded text strings are ungrammatical, it's got very few (and poorly covering) test cases, the methods are huge and unwieldy, and it's got security bugs (not so hot for something that's supposed to be guarding your application). In short, it looks like some quick-and-dirty internal hack that escaped one night and is now wreaking havoc on the world. There's probably some really good code generators out there. I've been poking around a bit, and there's some written for Rails by people who I know produce good code. However, no matter how good the author of the code generator is, the very best you can hope for is solid, clean code that is the equivalent of some portion of your application having been coded by some member of your team who you (and nobody else) has ever met, who didn't follow your team's coding conventions, and who has never looked at any other part of your application to make sure that everything hung together in a consistent manner. Which you now have to maintain. I've read a lot of books, articles, blog posts, and mailing list messages, and participated in no shortage of "why software sucks" discussions with other programmers, but I've never heard anyone advocate that the way to clean code, minimal bugs, and happy programmers was to drop a big chunk of unknown code right in the middle of things. Before you start charging up the e-mail-delivered tasers, ready to fry my delicate braincells for the twin crimes of Xenocodophobia and a vicious case of Not Invented Here syndrome, though, please understand that I'm not against code reuse in the right place. That right place is a library, component, or other abstract, documented, fairly static, and presumably-replaceable chunk of code. By using a library, you get a relatively simple interface to somebody else's complexity. This is a good thing, for all the reasons that everyone should already be able to recite. Items such as a comprehensible interface, minimal learning curve, and so on. Things you don't get with generated code because, pretty much by definition, the entire chunk of code is you "interface". There are some times, though, when what you want to do can't be done in a library. Either the thing has too many tentacles to be able to easily encapsulate behind an abstracted interface, or you need to modify it's behaviour in too many places to be able to get away with a few simple callbacks to get the job done. Hence, it might be tempting to fire up the code generator to get yourself out of a hole quickly. Don't do it though. Don't succumb to the temptation of saving yourself a little bit of time by firing up a code generator. What you're doing there is just making pain for yourself, by inheriting a big chunk of code that you don't fully understand, probably doesn't solve your problem particularly well, and which you (or whichever poor slob gets the job after you) will have to maintain into perpetuity -- most likely by gradually rewriting large pieces of it so that it fits your application better. The output of a code generator is likely to be the least maintainable code in your tree -- either by virtue of the fact that it's crap code, or at the very least because you just don't understand it. The general principle of good codebase hygiene is that you get rid of unmaintainable code quickly, so it doesn't infect everything else (a la the "broken window theory"). With that in mind, why would you ever consider deliberately introducing a huge chunk of unmaintainable code into your application? The closest I can come to a defence of code generators is something like Rails' scaffolding, where the controller and views for a set of simple CRUD operations on a table are auto-generated. The key word there, though, is scaffolding. It's very name suggests that it's temporary, to be replaced with something more robust and useful as soon as is reasonable. The default scaffolding is ugly as sin, besides, which encourages you to replace it, and -- as of Rails 1.1 (I think), there's a 'scaffold' method which creates the scaffolding output at runtime, so you never, ever need to generate scaffolding code any more. Anyone planning on producing any significant piece of their application through the use of code generators is, in my book, committing a crime against software decency.
1. My favourite whack code construct thus far has been this gem:
 case somevar
   when 17
     do_something_here()
 end
Because, you know, if statements are for people who know how to program, or something.

Matthew Palmer: Britney Spears explains Garbage Collection

... in song, no less! And for the few people in the world who haven't seen it before, Courtney Love explains the basics of BGP.

7 July 2007

Matthew Palmer: Exceptional Flow Control

(or: finally, a use for ActiveRecord#save!) I recently found Rescue To The Rescue!, a short article on structuring your Rails controllers differently. Today, I started using it in some code I was writing that I think really benefitted from the change. The code was a big case that did things like this:
 case some_variable
   when 'X'
     process-based-on-X
     if save
       post-processing
     else
       throw_an_error
     end
   when 'Y'
     process-based-on-Y
     if save
       some-other-post-processing
     else
       throw_an_error
     end
   when 'Z'
     process-based-on-Z
     if !save
       throw_an_error
     end
 end
In each case, the pre-save processing was unique, and -- more importantly -- the action to take after a successful save was different, so I couldn't just save-and-handle after the case statement. However, the throw_an_error code was the same in each case, so I just changed the code to do this:
 begin
   case some_variable
     when 'X'
       process-based-on-X
       save!
       post-processing
     when 'Y'
       process-based-on-Y
       save!
       some-other-post-processing
     when 'Z'
       process-based-on-Z
       save!
   end
 rescue ActiveRecord::InvalidRecord
   throw_an_error
 end
My mind was blown. Soooo much clearer now. I have an "everything's OK" code path, and a "bugger me, something broke" path, cleanly separated. But something didn't feel quite right... And now I know what it is. I'm bothered by the fact that I'm sailing very close to using exceptions as an ordinary, every day flow control mechanism. I think I've convinced myself that, in this case, it's OK, but I'm a little concerned that I might go power-hungry and start using it in places that it really isn't warranted. I guess I'll just have to keep an eye on myself. Just remember, everyone: save! isn't a dirty word!

6 July 2007

Matthew Palmer: Well, that was surreal

I just got a call from a "Katherine" at Mantech IT (or Mantec -- they can't seem to get their domain name synced up with their business name), claiming that they've previously supplied Java developers on contract to "your organisation", and having another one to palm off onto us. Now, anyone who has the slightest bit of knowledge of the company I work for would know that's a laughable proposition. We Don't Do Java. We also don't do enough software development that hiring programmers of unknown capability from a dodgy agency is an effective proposition for us. With my "WTF?" antennae twitching, I asked what company she thought I worked for. She mumbled something that could have been plausible, but I didn't really catch it. I said "pardon?", and she said "oh sorry" and hung up. Suffice it to say, I don't think that Mantech is a company you want to be dealing with (either as a candidate or a company) if this interaction is anything to go by. Sigh. Yet another "all recruiters are scum" data point. I'm getting quite a file by now.

Next.

Previous.