Search Results: "Matthew Palmer"

23 August 2006

Wouter Verhelst: Accept to gettext

In 2003, I needed to write a PHP site that would need to be internationalized, and decided to use gettext() for this purpose. While PHP has proper support for gettext, it unfortunately does not have any builtin way to easily convert the data in the Accept-Language and Accept-Charset HTTP headers into something that can be understood by gettext. So I sat down, and over the course of an afternoon, I wrote 83 lines of PHP code (excluding comments) that would do just that: parse the above two headers, and return a gettext string which represents the best match out of a set of strings specified. It's pretty easy in use, and was written quite generically, so I put a GPL tag on top of it, put it online, added a comment to the documentation of the gettext stuff in the PHP manual advertising the URL, and stopped thinking of it. The project that I wrote this file originally for eventually wasn't even finished; today, I don't even recall what it was. In early 2005, I received a mail from Matthew Palmer thanking me for the code, and telling me that he'd incorporated it in IRM of which he's part of the development team. Which reminded me of its existance. For a short while. Today, I was cleaning out my INBOX, and stumbled upon this old email again. Which got me curious, so I started googling for those 83 lines of code that I'd entrusted to the Free Software world three years ago. I must say I'm pleasantly surprised. My file accept-to-gettext.inc seems to be used in a variety of free software projects, including of course IRM, but also the GnuCash website, or in this french educational thing called SLIS. It seems to be quoted in its entirety on some turkish PHP-related forum. It has been adapted to support different translation systems. And so on... the list is rather long. Can't say I'm not proud. And yet, the code contains a rather silly bug: the assumption that character set encodings are somehow linked to translations. They are not; gettext is perfectly capable of transparently transcribing one character set to another. Oh well...

30 July 2006

Matthew Palmer: Shell Scripting: Good; Sane Tools: Better

While David Gibbons' little shell snippet to add unknown files to an SVN repository is nice:
 svn status   awk '/\?/  print $2 '   xargs svn add
You can do better if your revision control system can answer the questions you really need answered:
 bzr add $(bzr unknowns)

11 July 2006

Matthew Palmer: It's All So Simple When You Know How

As a followup to my Dapper is teh suck entry, it appears that my egregiously slow system is known bug. Of course, it'd be better if it were a fixed bug, but at least it's trivially work-aroundable (echo 1 >/sys/module/processor/parameters/max_cstate -- down from it's default, on my system at least, of 8). Apparently there's some "issues" with the SMP-compiled kernel on uniprocessor systems, and hitting that tunable down masks the problem, whatever it is. It's funny -- just the other day I was having a chat with the other sysadmin at a place I'm contracting at about the vagaries of SMP kernels on non-SMP machines, and he was amazed that you could have a modern system that didn't play nice with an SMP kernel. Now, it seems, I'm a walking, cursing example of the issue. I don't mind, though -- I'm playing Oolite at full speed again, so I'm happy.

Matthew Palmer: User Interfaces as Slideshows

Backstory: I recently found a new game. It's called Oolite, and is (probably unsurprisingly) a clone of that great old spacefaring game, Elite (for BBC Micro and C64, amongst others). This game (unlike the original!) uses OpenGL and hardware rendering, so it was a good motivation to get accelerated rendering going on my laptop (never bothered before; it's unlikely that DRI is going to make an Xterm run any faster, after all). The problem with DRI under Ubuntu Breezy on my laptop is that it makes the machine unstable. Every couple of hours, my screen would freeze, and I'd get a lovely collection of randomly-coloured 80x25 text-mode characters on my screen, flashing madly at me. That's the signal for "game over", apparently, and I'd have to reboot. Incidentally, this used to happen, but very rarely, before I turned DRI on, so it's not really DRI-specific, but it went from occasional irritation to regular irritation. End backstory.
So it was time to upgrade. "Dapper's Out", thought I. "May as well see what all of the fuss is about". I think the phrase "oops" correctly describes the result. For reasons which I have not fully determined yet, my system is now Dog Slow. (That's the technical term, anyway; I've got a few more colourful phrases for it that I'm using privately). What was, previously, a nice quick Xterm launch is now a slowly progressing set of concentric rectangles culminating in the eventual, lacklustre, appearance of a terminal window. Oolite, my new obsession, is like playing Quake3 (the last OpenGL game I really got into, many years ago) on a P-II 300 with no 3d graphics card -- here a frame, there a frame, oh, by the way, you died a couple of minutes ago. (And yes, before you ask, glxinfo says "direct rendering: Yes".) This isn't an old machine -- it's a Thinkpad T43, with gobs of RAM and a 1.7GHz processor. It ran Breezy like a charm. Now, my machine looks like a powerpoint presentation. I've got to put something onto my wife's "new" (P-III 700) laptop -- lord only knows what it'll think of Dapper. Other strangenesses I've noticed so far include: Ultimately, I think that the cause of my problem may be closely related to that last point. I need to find out what's chewing my machine's CPU and kill it dead. Oh won't that be fun. Well, enough moaning. Time to find the cause(s) of these problems and nail it/them to the floor.

3 July 2006

Matthew Palmer: Shittyrail does it again!

(Caution: Rant ahead. At least it's short.) It's obvious that they're putting the extra funds they're getting from yesterday's ticket price hike to good use -- this morning, my train was cancelled. These trains are pretty packed by the time they get to the city anyway, and now we're going to have twice as many sardines in the can. You'd think that, for at least this week, they'd try that bit harder not to piss people off too much. Or perhaps they're just packing it all into one chunk, figuring that there's some sort of upper-limit on people's irritation and it can't get worse beyond a certain point of irritation.

8 June 2006

Matthew Palmer: [Ruby] Blocks as Resource Management

One of the really neat things about Ruby is the extensive use of blocks (closures, I think the rest of the world calls them) in the standard library to control the allocation and deallocation of resources. Take the following snippet:
 File.open('something.txt') do  fd 
   # Manipulate the file through 'fd'
 end
 # File handle is now closed
There's no way that you can escape from that block without the file being closed (well, in theory, you could lose the file handle if there was an exception thrown in the block, but the File::open method can take care of that internally by catching, closing, then rethrowing). I've loved this feature since I first saw it -- "holy crap!" I thought to myself, "I never have to call close again!". And I was pretty well right -- I think I can count (in unary, not binary!) on one hand (well, I'd use grep wc) the number of times I've used IO#close in my Ruby code. The funny thing is, though, that I don't think I've used this pattern in my own code enough. But I just had an epiphany whilst waiting for a train home -- and I think I'm cured. Take this hideous piece of test code I had laying around in an app I'm working on at the moment:
 def test_something_funny
   faux_path_on
   d = Domain.new('127.0.0.1', 'somethingfunny.com')
   faux_path_off
   
   # assert writ large
 end
Domain::new calls out to a shell command (dig(1) to be precise -- take a guess at what I'm writing <grin>, and yes, it will be released shortly) but for test purposes I can't run dig (because I'm not guaranteed to have all the infrastructure available for a real dig to succeed). So I have a flimsy mock of dig in a directory in my test suite, which is where faux_path_on sets ENV['PATH'] to look at. This is, of course, pretty untidy, because when (not if!) I forget to call faux_path_off, everything goes to complete poop, and my children will have two heads or something. The much cleaner version is like this:
 def test_something_funny
   d = faux_path   Domain.new  
 
   # Assert ahoy!
 end
And my faux_path method (I've even saved a method!) is as simple as simple can be:
 def faux_path
   realpath = ENV['PATH']
   ENV['PATH'] = my_fake_path
   rv = yield
   ENV['PATH'] = realpath
   return rv
 end
I also have a trickier faux_* method, which sets a couple of environment variables which tell my mock nsupdate(8) where to write the data it gets sent from my application -- again, it's a block-taking method that sets the environment, yields, reads in the data from the temporary file, cleans it up, and returns the contents of the aforementioned file. The power of the Ruby is growing within me, I can feel it. And I like it.

Matthew Palmer: A Fool And His Money are soon parted...

... but not nearly soon enough. The Daily WTF is almost always worth a read -- it makes me feel better about my lot in life. Today's entry, though, shocked me more than a little. How do people this dumb even breathe? Certainly, they don't deserve to be in control of a business.

Matthew Palmer: Inadvertantly Appropriate

Seen on the way to work this morning (for some sort of art show):
From the affordable... to the collectable!
I'm not sure that what they meant was "the stuff you can afford isn't worth keeping", but I'm pretty sure that it's the truth.

24 May 2006

Matthew Palmer: Testing the Testing of Your Tests

I'm writing an application in Ruby that makes heavy use of XMLRPC (the application of XMLRPC-over-Unix-socket fame), and so I'm using Mock Objects to mock out the XMLRPC client proxy and provide an interface that doesn't involve having a whole other infrastructure running on my laptop so I can run my test suite. For those who don't know, mock objects are objects which look and superficially act like the real objects you might use to communicate with an external service, but don't actually do the communication -- instead, they return canned responses to your calls. Why is this useful? Well, imagine that the real object talks to a SOAP service on the 'net (such as the Google search API). It means that every time you run your test suite, you need access to the Internet. The external service may also cost something everytime you talk to it -- or it may be impossible to use to test, since there's statistics generation or something going on that means that hammering it for test purposes is just impractical. In addition to returning values to your application, mock objects will usually record what has been called, so that after your test run is complete, you can also verify that all of the methods you wanted called have actually been called. This means that you can have a good idea that what you wanted to happen to the service actually would have been done. Handy. Some people have a (justified) ditrust of Mocks, because it's easy to make a mock object that doesn't perform like the real one (and hence invalidate your tests), but they provide a necessary evil in cases where you just can't use the real object when running your test suite. The XMLRPC proxy I'm using has a bit of a quirk. Everything runs through one method on that object -- XMLRPC::Client#call(). This seems really limiting, especially in a wonderfully dynamic language like Ruby. In reality, it's not too bad -- it makes the object interface easier to mock, and you couldn't emulate the whole thing with method_missing anyway, because you can have various Ruby-illegal characters in XMLRPC method names. The downside to this all-in-one-method thing, though, is that simply verifying that #call() has been invoked a dozen times doesn't really tell me much about whether the mock was used the way I wanted it to be used. My chosen mock object suite, Test::Unit::MockObject, whilst otherwise excellent, is (or rather, was) missing the ability to verify the arguments that are passed to your calls -- you can say "I need methods x(), y(), and z() called", but you couldn't say "I need the call y('foo', 'bar', 42) made". Of course, this change the mock object class is non-trivial, and needs to be tested itself (it'd be pretty lame if a class intended to facilitate automated testing lacked a test suite of it's own). I added a bunch of tests to the test suite, and got some good results. I had a couple of false starts, where I wasn't checking most of the corner cases (where bugs lurk in the shadows), but eventually I got a test suite that was fairly complete, which drove the new features I needed to a good place. So I carted my newly enhanced mock object class across to my production project, and off I went. Except that I was getting some downright weird failure messages when my code wasn't invoking the mock object the right way. Why? Because I hadn't tested that my failure messages were appropriate. Why was that? Because the assert_raise assertion in Test::Unit doesn't have a facility to make sure that you're passing back the right exception message, only that you're passing back the right exception class. Whisky, Tango, Foxtrot? Over. (This space intentionally left blank for me to insert the correction to this claim that the lazyweb is sure to provide) So I had to write a new assertion (assert_exception_message) which checked that both the right class and the right message came back. This code, of course, needs to be tested too, because otherwise you can't be sure that your test code is performing right. At this point, I was writing test code to test a new assertion I'd written so I could test the mock object class I had modified so I could test my application. At this point, things got a bit "meta". It got a bit difficult to separate out the tests from the tests' tests. But I fought through the brain melt, and shortly thereafter came out the other end with a properly working piece of actual application, and all was well in the world. By now, a certain Mr. Tendys is probably rubbing his hands with glee, as he gets ready to espouse at length about how this whole post just proves how utterly useless test-first programming (or even testing in general) is for producing economically-viable software. Let me analyse what I "spent" on getting all this functionality, though -- about 3 train trips home -- maybe 4 hours of time total, including writing the extra tests in my application to use the wonderful new features I'd made. That's not much, in the grand scheme of things. I've wasted that much time in a day skiving off work in the past because I was frustrated with what I was trying (and failing) to program, usually because I was swamped with bugs. What did that four hours of my time buy me? Heaps. I can now better verify my software works as anticipated. I have confidence that my software is a lot more robust than it was before. My tests identified several issues that passed my eyeball check, but blew up when I tried to actually use them in a particular way. But with the help of my tests, I identified the problems quickly and went on my way. Since I was working in a localised area of the application, I was immediately familiar with the code, and could stomp the bug almost immediately. If I'd only done end-to-end testing at the end of development (or worse, released it with the bugs still in there), the debugging would have been much harder because I'd forgotten little details about the code. I reckon that benefit, alone, has probably saved me 4 hours already, since I've spent whole days hunting down little bugs in an ad-hoc fashion in the past. I'm fairly sure most any programmer can empathise with me there.

Matthew Palmer: Trains: Inverse Hibernation

So it would appear that, now that the hot weather is over and blessed winter is upon us, the air-conditioned trains that I dreamed of so much and so rarely saw over summer are now out in force. Such a cruel, cruel world we live in.

14 May 2006

Matthew Palmer: Curious Perversions in Software Engineering

I've been ill with flu the last few days, so I've been doing very little other than sitting huddled in my recliner, with a large, warm blanket over me, and my hot water bottle (AKA the laptop) to work on. As a result, I've been doing a fair amount of random coding, and I've come away with a larger-than-average amount of... weird shit. It maybe the flu, the strong drugs I've been taking to keep the symptoms under control, or maybe just the phase of the moon, but I haven't coded up this much madness in quite a while. Let me take you through them. The Proctologist I've been writing some software which has to talk to an XML-RPC server. Not so weird. However, because the system lacks any inherent security, the (strongly) preferred method of communicating with this server is via a Unix socket. That's right, I'm doing XML-RPC over HTTP over... a Unix socket. That, you may think, is weird. Well, it is, but it isn't the curious perversion in and of itself -- for a start, I didn't write that monster, and I'm only blowing my own trumpet in this article. No, the perversity is in how I wrote *my* software to deal with it. See, I'm using Ruby for this software, and the standard Ruby XML-RPC client uses the built-in Net::HTTP library that comes with Ruby (which is a killer little HTTP library, BTW). Because the authors of Net::HTTP were lacking in imagination (or crack pipes) they didn't think to include the native ability to talk to Unix sockets. I mean, really -- isn't that the most important feature in a HTTP library? I think we all know the answer to that. Anyway, despite the lack of forward planning (and crack pipes) on the part of the Net::HTTP authors, I needed to get it to talk to a Unix socket. I could have done the long-winded thing and spend a pile of time putting in handling of pipe:// (crack or otherwise) URLs, but then I would have also had to add support for it to the XML-RPC client library (which did URL validation before passing it on -- good for it). And really, I don't think I could have handled the guffaws of laughter when I attempted to submit the patch upstream. Instead, I put Ruby to it's perfectly-suited use. I simply created the XML-RPC client object (which created the Net::HTTP object internally), then inserted my gloved finger and replaced the default TCP socket object in the Net::HTTP object with a specially crafted Unix socket object pointing to the correct place. "Dear god almighty!" I hear the practitioners of good software engineering practice exclaim. "Doesn't Ruby have protection against such atrocities?" Why, yes, it does. All of the objects I had to play with are private instance variables of their parents, and I can't get access to them normally. However, classes in Ruby are never closed, so I just reopened them and added accessor methods (which, in Ruby, is as simple as attr_accessor :http) so I could do my nasty little thing. I'm quite happy to take the heat for doing what I did. It breaks encapsulation, and makes everything that little bit more complex. But, on the other hand, it let me get the job done -- the language gives you full protection until you say "may I?" and then it gets out of your way. Personally, I reckon that's a nice tradeoff between C-style full control (where even the best programmers blow their foot off on a regular basis) and B&D; languages where you'll never shoot yourself in the foot, but instead you'll gnaw your leg off in frustration. Russian Dolls I'm doing a bunch of interesting things with the Xen hypervisor for work. Of course, you need to have a way to test all this stuff, and despite a number of hints, work still hasn't gotten me that fully-kitted out dual-core Opteron that I want to test (and transcode all my video <grin>) on that I always wanted. So, instead I've installed Linux in a qemu image, and then put Xen on that. Surprisingly, it's worked really well -- I've got Xen running quite happily in the virtual machine, and I can create and run Xen domUs (the guest VMs) in the usual fashion. Now all I need to do is install UML in a Xen domU, and then run some vservers inside that UML, and I'll have the full collection...

11 May 2006

Matthew Palmer: The Pain of CFEngine

So it seems that Steve Kemp is finding out that, whilst being a brilliant idea in theory, CFEngine is just plain weird in practice. I was the person who originally encouraged Steve to look at Puppet when he was originally talking about this stuff about a month ago. I was arguing from a position of weakness then, as I'd never tried Puppet then (although I was already eminently familiar with CFEngine and it's issues). Since then, I have started using Puppet on a project for a client, and let me just say that it is "all that and a bag of potato chips". Luke Kanies, the main man behind Puppet, is immensely supportive, quick to work up new features when suggested (< 24 hour turn around, in some cases) and really knows his systems-management stuff. The configuration language itself is quite easy to learn, it's wonderfully extensible, and the system as a whole doesn't have nearly the same number of "WTF?" moments as CFEngine (and Luke has already, in the week or so I've been using Puppet, fixed up two of them based on my suggestions). There's only one thing in CFEngine that I use that Puppet doesn't have, and that's editfiles. This is by design, apparently -- there is no consensus, even within the CFEngine diehards, that editfiles is a good thing, and Luke isn't really keen on implementing it (it's a big feature, and there's known better ways of solving most of the problems that editfiles solves anyway). I still feel that it's useful to use editfiles in some circumstances, but not having it certainly hasn't cramped my Puppet style excessively so far. Oh, Steve -- about Ruby being "un-perl" -- that's not a bug, it's a feature!

2 May 2006

Matthew Palmer: I think it's time for #wimbledon...

Between myself and new DD Ben Hutchings, I think we have enough wombles to make a fair showing. <grin>

19 April 2006

Steve Kemp: You ve got to manage

Large Scale Automation I’ve been revisiting CFEngine recently in anticipation of installing it on around 50 notes. Matthew Palmer has given me a lot to think about, suggesting that maybe CFengine isn’t the right tool for the job and suggesting I look at Puppet. It seems very new, and I’m not overly fond of the Rubyness - but otherwise it looks good. There are some things that CFEngine gets right, and some things it gets wrong. One of the biggest “right” things is the split of the code: That strikes me as being a perfect split. The “script” file which is executed cfagent.conf is really a ruleset which is executed once on each host. The rest of the CFEngine setup is mostly concerned with distributing this file, handling updates, logging, security etc. If I were to code a similar system that is exactly how I’d seperate it. Now we come to the rules themselves. What do we do inside them? Well in my use of it to date I’m mostly doing a small number of things: So those are my primitives. They can actually be reduced further. Assume that the central server runs a HTTP server - then “copying a file” becomes “execute a command (wget/curl)”. None of these jobs is complex. None of them are things that couldn’t be written with a simple scripting language such as perl, lua, etc. It is almost tempting to write a simple rule-file-intepretter/parser. But down that path lies madness. I’m going to install Puppet tonight and play with it. Gotta love Xen :) If that works out nicely I might switch to using it, despite my concerns that it isn’t mature and is Ruby based. If it doesn’t it becomes a choice of writing a simple intepretter + deamon which accepts SSL connections with client certificates, or living with CFEngine.

7 April 2006

Matthew Palmer: Stunning. Simply Stunning.

Rails is the framework that just keeps on loving. A new feature in the recently-released Rails 1.1 is an integration testing framework. The general idea is that your unit tests make sure that your data model and validation work, functional tests make sure that business logic is specified correctly, and then integration tests tie a whole typical user session together, to ensure that your whole app holds together nicely in real-world usage situations. Basically, think of integration tests as an automated "click around" to make sure everything's working -- and, like everything that's automated, you can do it quite regularly without getting RSI, and it'll never make a mistake. Now, automated integration testing is pretty cool, there's no doubt. But there's more to this than meets the eye. You can also use the integration testing features in rails to test drive your entire Rails application from the Rails console. Big geek points to Mike Clark for the tip.

5 April 2006

Matthew Palmer: Vista Demo with OS X

This may be old news to the rest of the world, but I just got around to watching the mashup of the Windows Vista preview presentation audio put to a screencast of a Mac OS X desktop. If you haven't already seen it, I highly recommend taking a look. It's quite funny just to listen to the guy raving about all of these great new features (to be released next year) being demonstrated on a totally different, already released OS. Beyond that, though, the video makers have taken time to inject a bit of extra humour into the video, with the little touches (like their choice of photos).

4 April 2006

Matthew Palmer: A Poem for Anne

In a fairy castle,
Just beyond my eye
My baby plays with angel toys,
That money cannot buy
Who am I to wish her back into this world of strife?
No, play on my baby,
You have eternal life.
At night when all is silent,
And sleep forsakes my eyes;
I'll hear her tiny footsteps,
Coming running to my side.
Her little hands caress me,
So tenderly and sweet;
I'll close my eyes and
Breathe a prayer,
Embrace her in my sleep.
Now I have a treasure,
I rate above all others;
I have known true glory,
I am still her mother.
Author Unknown

Matthew Palmer: Rewriting in Rails -- A Practical Examination

[Note: this article was mostly written some weeks ago; I left it in my "to be edited" box and then promptly forgot about it. So any and all temporal references are way out of whack. Since originally writing this article, I have commenced an incremental rewrite of an in-house business management application from crazy-PHP (a common -- some may say overwhelmingly so -- dialect of the language noted for it's complete lack of any sort of good software development practices, such as the creation and use of functions (!)) into Rails. Articles on this effort will be appearing presently.] Almost immediately after I'd finished writing my previous discussion on why rewriting software is evil, I decided to make a little experiment. What I did was take a fairly well factored PHP application, and rewite (a portion of) it in Rails. My intent in this was not to produce a production-quality rewrite. I have no interest in proliferating yet more functionally equivalent clones on the world. Instead, I undertook the work simply to get a feel for (a) writing a whole, traditional, Rails app in a short space of time, (b) how quick Rails really was to produce an application, and (c) whether wholesale rewrites really are as boring and life-sucking as I imagined them to be. My methodology was this: with a small amount of knowledge of the target application (SysCP), the existing database schema and templates, and a weekend, rewrite as much of SysCP as I could in a close-as-possible reproduction of critical SysCP functionality. My summary results are: rewrites are as boring as I thought they would be, Rails is powerful but fairly complex and slightly buggy when you get down into it (especially if you're working from an existing -- possibly suboptimal -- database schema), but overall, Rails is Way Good Stuff. On the boredom aspect -- I had two days to write code. I had some domestic duties to attend to (walk the dog, visit the hardware store, help my wife with attaching a new bag rack to her bike, mow the lawn, etc) but on the whole, it was dedicated to programming. I've spent whole days (hell, 40 hour marathon stretches) cutting code before. I knew this wasn't a six-month deathmarch, but only a weekend experiment. Despite that, I feel that my motivation levels were lower than they normally are when coding. I can only imagine what it must feel like, two weeks into several months of hard core coding, knowing that you'll end up with what you had before, functionally speaking. If you are going to do the rewrite thing (and may the Flying Spaghetti Monster have mercy on your soul if you do), then pick the right project. SysCP is large masses of tangled PHP (is there any other kind?) but it has a fair amount of local and global structure once you get down to it -- for instance, it's quite well factored into business logic and display, and the code is broken down fairly logically by action handler, so you get entire source files that look like this:
  if ($action == 'edit')
   
    // 150 lines of twisty passage PHP
   
  else if ($action == 'new')
   
    // Another 150 lines
   
  // repeat for another few actions
and so on. The nice thing about this is that, if you have to look for how something works, you can almost certainly find it in one place in the source. Deciphering it might be another matter, but at least you've got something to start from. As I mentioned, the display in SysCP is pretty nicely split off from the logic -- a large number of templates, with common header/footer files, with some small parts in common templatettes. Some HTML is still generated within the actions, but due to the above action-based structure, it's usually fairly easy to identify all of the HTML that will be associated with a particular action and turn it into a coherent Rails template. I would dread doing a rewrite of the presentation layer of, say, IRM. It's idea of well-factored presentation is to separate print statements from logic by a blank line. To my great shame, I've had the reins of IRM for a year, and it's still this bad. I claim it's because I hate HTML coding with a vengeance, but I think I'm actually just scared to try and tame that particular monster. (Update: Martin Stevens has been doing some good work turning IRM's HTML into Savant templates. The only downside is that I can hear his manic laughter -- caused by IRM's insanity slowly infecting him -- all the way from England, and it's keeping me awake at night). I also had to re-learn that most hated but most important of lessons -- that, no matter how much reading you may have done, until you've cut chunks of code in a language or environment, you have no idea how it actually behaves in your brain. Specifically, I spent a fair amount of my alloted rewrite time learning a few little lessons in how Rails actually behaves, and all of it's cool little features. Of course, everyone is going to have this pain, and I've suffered it in every language that I've done any appreciable amount of programming in, but it's always a shock to the system that -- after all this time programming -- a new language still makes my brane tingle curiously for a while. Luckily, I'd read and digested all of both the Pickaxe (Programming Ruby) and AWDWR (Agile Web Development with Rails) so I knew what was possible, I just usually wasn't sure how exactly, so I spent a lot of time with my head in the books. Rails' little foibles also bit me in the bum more than once. For example, I spent over an hour (a no foolin' hour) trying to hunt down what I was doing stupid in my code to make Rails completely forget about the value of a couple of my fields. The answer turned out to be to restart Webrick (Rails' internal webserver for development testing), and the problem cleared right up. You could hear my screams of anguish from the moon (even through the vacuum of space -- it was a lot of anguish). Rails isn't the Final And Ultimate Solution To The Webapp Problem, but it's a good start. There is near-zero administrative bumf when you're writing a Rails app. Rails is fairly intelligent about working out what you want done from the world around it. Code generators (which produces sensible, minimalist templates -- not the ugly, unmaintainable behemoths produced by Visigoth Studio, which has given the whole code generation world a bad name) handle a lot of the low-level "oh bugger, I have to add a new file" feeling. It's very, very anal about project structure, but (in contrast to many other bondage-and-discipline frameworks I've looked at in the past) this structure seems almost comforting (maybe I'm just getting old and turning into a satisficer). What all this means is that you (a) don't write much code unless it moves you toward your goal, and (b) Common structure means that any Rails app will be fairly familiar to an incoming programmer. Unfortunately it also means that cunning wankers will, sooner or later, work out a whole pile of ugly tricks and contortions to get themselves out of Rails' comfortable-but-no-doubt-incompatible-with-many-people's-ways-of-thinking straitjacket, which I will (sooner or later) end up maintaining. Like many of Rails' (and Ruby's) features, though, I don't see them being any more abusable than most features of any programming language or environment -- and at least they're powerful and useful (unlike, say, register_globals, magic_quotes_gpc, magic single-character variables, mandatory indenting, or banning tabs as indent characters -- I thought I'd spread the slagging amongst lots of languages). Productivity-wise, although I was only just kicking off my Rails webapp knowledge, I felt I was doing fairly well. From experience, what I produced in my weekend was roughly on par with what I could produce in PHP in the same amount of time, had the situation been reversed. Considering that I have about 3 weeks of Ruby/Rails knowledge, and about 5 years of PHP experience, I think that's a big win. (Update: I've since produced a DNS management applet for work in about 6 hours billable time, and a virtual mail account application in about 12 hours, both using Rails. There isn't a hope in hell that I could have performed a similar feat in PHP, especially with the same amount of inherent flexibility that the Rails solutions contain). Overall, my impression of wholesale rewrites as being soul-sucking experiences stands. I suggest they be approached with the greatest of care, and only be permitted after an appropriate period of psychological counselling. There is plenty of code that needs rewriting (but why do I always have to find it?) but replacing it by doing an rm -rf on the source tree and starting again is not the answer.

3 April 2006

Matthew Palmer: A Rebuttal to "Copy and Paste"

Kai, the Unix way to Copy and Paste is far less of a pain than you seem to think it is. To wit:

Matthew Palmer: Demanding Gets You Nowhere

Wow, some people need to learn how to ask questions. Just saw a posting to a mailing list that said (paraphrasing):
I need detailed instructions on how to do easy task foo, and then fairly involved task bar. I want the whole command process including how to do trivial thing X, unnecessary thing Y, as I tried and could not get it work properly at all. And also irrelevant question Z.
Now, I don't know about you, but a flat-out demand like that doesn't exactly give me the warm fuzzies and make me want to help -- in fact, it makes me feel like a CentOS developer. Practically speaking, I know (roughly) the answer to this person's question, but it'd take me a couple of minutes to check I had the right answer, and to write it all up. Unfortunately my motivation levels for unpaid, gratuitous assistance just dropped to zero (coincidentally, as I was reading his message). Time to give the Internet a healthy dose of the "How to ask questions the smart way" salts, methinks.

Next.

Previous.