Archive for June 2006

Magic moments

I love it when I get into the coding groove and things just magically happen. This afternoon I spun together the new search interface I’ve been procrastinating on at work, and everything just came into place beautifully. And the interface design and graphic design even ended up being rather pleasing, too. Moments like these make coding worth it. :)

Now to spend the next hour or so working on Beyond…

Saving Active Record

Finally figured out the elusive bug that’s been bothering me all day. In my code, I create an instance of my Family class (this is as I’m importing a GEDCOM into the database), which basically creates a record in the Families table. I kept trying to set the instance’s husband_id and wife_id variables (which map to columns in the table), but inevitably they’d end up as null. So I tried “script/console” and set the variables there. It did change the variables, but the database remained unchanged. (”script/console” is pretty darn nice, I must admit.) I’d been under the impression that changes made to Active Record objects would get made in the database as well, but I began to suspect that my assumption wasn’t quite correct. Having created a fam object via fam = Family.create(:file_id => 1), I decided to see what methods it had. fam.methods gave me a long list, and voila, among them I noticed one called save. Sure enough, fam.save did the trick. :)

RailsConf 2006

I’ve been reading about RailsConf today. Dang, it sounds like it was really quite cool. I really liked Paul Graham’s keynote, “The Power of the Marginal”. And DHH’s announcement about Active Resource (like Active Record but for web services) sounds exceedingly interesting. Can’t wait to try it out.

In other news, I’m about to find out just how cool generators are. I was going to write a login/authentication system for Beyond, but then I came across the various login generators. Happiness. :) I’m tired of reinventing the wheel, so this is very nice.

Hopping on the rails

I’m finally starting to understand Rails! :)

Now that school’s out I don’t have any homework breathing down my neck, so this morning I got up early and decided to write a Rails app that takes a GEDCOM file (using an existing GEDCOM-to-XML parser) and imports it into a Beyond database.

Instead of using the traditional scaffolding (which is the easy way to get started with Rails), I decided to go it on my own, creating the necessary models and controllers and views through “script/generate,” and then link them together. In the process, I’ve learned a lot about how Rails works. The whole MVC thing makes sense now, and I see how I can stitch the pieces together to get what I need.

About the only real difficulties I ran into were from naming fields “key” and “object_id”. I wish there were a document somewhere that told you what field names to avoid. There probably is and I just haven’t found it yet. Anyway, after a while I realized that “object_id” was a Ruby method and rel.object_id was giving me a long funky number because of that and not because something was wrong with the database. So that was nice.

Oh, and I discovered config/routes.rb, which answers a lot of the questions I’d had about URL mapping (i.e., where the “/controller/action” URL actually comes from, and how Rails knows about it). Very cool.

Anyway, I’m really, really glad I’ve gotten past the initial bump in the road. This is where the fun begins. :)

filicio.us

I’ve been bemoaning the lack of a nice web app (or any web app, for that matter) which I could use to access my S3 storage. Then today I found filicio.us. It’s new and simple, and it actually works. You can check out the demo if you’d like.

I’m missing folders, though. Tags are nice, sure, but for files it’d be nice to keep a hierarchical structure. (JungleDisk lets me do that.) Or at least I think it would be nice; I’m prepared to shift my paradigm if necessary. But even so, it still seems like having lots and lots of files would make the hierarchy nice. We’ll see. I’ve got a ton of files to upload (3rd party backup, just in case :)) and the thought of losing the structure is slightly disturbing, but then again with a quick search, it may not make a difference. I’ve gotten used to Gmail’s labels instead of folders, come to think of it. Here goes. :)

Functional programming

Today I came across Functional Programming for the Rest of Us, via Digg. Great article providing a nice overview of functional programming, including higher order functions, currying, lazy evaluation, continuations, pattern matching, and closures. And I’ve got to say that I’m finding functional programming pretty darn cool so far. I’m going to have to look into Erlang and Haskell. “Rock solid” systems? Definitely piques my interest. I wonder how Ruby fits into the FP paradigm. I know it does metaprogramming and closures, but I’m not sure on the other stuff. Anyway, I’m really looking forward to the next article, which the author says will probably cover “category theory, monads, functional data structures, type systems in functional languages, functional concurrency, functional databases and much more.” Good stuff. Drool.

And now that finals are over I’ll have more time to learn Lisp/Scheme via SICP. Speaking of Lisp, the same guy who wrote this functional programming article also wrote a great article on The Nature of Lisp. Here’s the quote that hooked me:

I was baffled. Many extremely intelligent people I knew and had much respect for were praising Lisp with almost religious dedication. There had to be something there, something I couldn’t afford not to get my hands on! Eventually my thirst for knowledge won me over. I took the plunge, bit the bullet, got my hands dirty, and began months of mind bending exercises. It was a journey on an endless lake of frustration. I turned my mind inside out, rinsed it, and put it back in place. I went through seven rings of hell and came back. And then I got it.

The enlightenment came instantaneously. One moment I understood nothing, and the next moment everything clicked into place. I’ve achieved nirvana. Dozens of times I heard Eric Raymond’s statement quoted by different people: “Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.” I never understood this statement. I never believed it could be true. And finally, after all the pain, it made sense! There was more truth to it than I ever could have imagined. I’ve achieved an almost divine state of mind, an instantaneous enlightenment experience that turned my view of computer science on its head in less than a single second.

So yes, I’m definitely going to keep hacking away until I “get it.” Can’t wait for that moment of enlightenment. :)

Visor

Discovered Visor a few minutes ago. It’s a cool app which lets you assign a keyboard shortcut to pull down a terminal from the top of your screen. I set my shortcut to Ctrl-\, since Ctrl-F1 (the default) is an awkward combination to type. Note that to install it, you’ll need to install SIMBL first. But it’s not hard. This is really cool. It’s from the same people who wrote Quicksilver. (Speaking of which, I still haven’t started using Quicksilver, but I need to…)

Structure and interpretation of computer programs

I started reading Harold Abelson and Gerald Jay Sussman’s Structure and Interpretation of Computer Programs, the classic MIT computer science textbook. It’s good! And they use Scheme, which is very cool (although it’s certainly unlike most other programming languages). I started learning Lisp a long time ago but time has erased most of it from my mind, so it’s nice to review. (I’m not exactly sure what the differences are between Scheme and Lisp, but at this point they’re negligible. At least I think they’re negligible. Maybe I’m wrong.)

The KLOC is ticking

Came across this interesting bit from the Broken Windows Theory post of a Windows product manager (bold has been removed):

Vista is said to have over 50 million lines of code, whereas XP was said to have around 40 million. There are about two thousand software developers in Windows today. Assuming there are 5 years between when XP shipped and when Vista ships, those quick on the draw with calculators will discover that, on average, the typical Windows developer has produced one thousand new lines of shipped code per year during Vista. Only a thousand lines a year. (Yes, developers don’t just write new code, they also fix old code. Yes, some of those Windows developers were partly busy shipping 64-bit XP. Yes, many of them also worked on hotfixes. Work with me here.)

Lest those of you who wrote 5,000 lines of code last weekend pass a kidney stone at the thought of Windows developers writing only a thousand lines of code a year, realize that the average software developer in the US only produces around (brace yourself) 6,200 lines a year. So Windows is in bad shape — but only by a constant, not by an order of magnitude. And if it makes you feel any better, realize that the average US developer has fallen in KLOC productivity since 1999, when they produced about 9000 lines a year. So Windows isn’t alone in this.

Only 6,200 lines of code a year? Whoa. Suddenly I feel productive, even above average. :) I wonder he got this number… (6,200 seems awfully small.) Wikipedia has an article on LOC, but nothing about the national average. Hmm…

Ben’s Bylaws of Blogging

I felt like writing a list this morning. And I did. It’s on Top of the Mountains at
Ben’s Bylaws of Blogging. Feel free to leave additions in the comments.