A newbie's view of Ruby on Rails

(GeekStuff)

2009-01-18 13:17
Comment

I’m doing a project, and I think I’m going to try to do it in Rails.

Downsides: I don’t know Rails, and I’m pretty much a Ruby novice.
Upsides: It’s not PHP.

Since I have a fairly strong and diverse programming background, I think my experience of Ruby and Rails may be of interest to some readers, so I’ll try to update with impressions, code trivia, and such as I go.

Special thanks to fearoffish (an IRC nick) for some tips on books to start with.

If you’re a geek and you don’t know Ruby, I recommend it. From what I’ve seen, here’s how I’d suggest going about it:

1. Pick up a copy (paper or electronic) of Programming Ruby: The Pragmatic Programmer’s Guide. The link’s to a fairly old version of the book; they’re currently doing a revision to cover the upcoming 1.9.

2. Start reading… wait. Before I tell you: You may hate this document. If you hate it, that’s okay. Don’t read it then. Some people hate it. Anyway, start reading Why’s (Poignant) Guide to Ruby.

A bit of a digression is in order. The first time someone pointed me at Why’s guide, I read it for about three minutes, and got very upset and gave up. This guide was absolutely the worst way to explain the language to me, because it’s full of cutesy stuff, digressions, the sorts of apparently-random emphasis that makes me think of Dr. Bronner’s soap, and very little in the way of a very quick, technical, overview of what Ruby is and why I should care.

It made me think that Ruby was some crazy cult, like Dr. Pepper. It didn’t make me want to learn or use the language; it made me think the language was crazy.

But… It turns out that for many people, this guide is a good way to get into a receptive state to learn about Ruby. So give it a look.

3. Grab a copy (it’s already installed if you’re on a Mac!) and just start typing.

Ruby’s an expressive language. It’s not a language which makes any effort to keep you from being an idiot. It does little or nothing to protect you from your own stupidity. If you want to replace core functions of fundamental built-in classes, Ruby won’t even TRY to stop you. However, it is very good at letting you say what you mean, without having to say a whole lot more on top of it.

Rails? Uhm. I think Rails is a framework. Which is a fancy way of saying it’s a bunch of glue code, the intent of which is to make it easy to hook up database objects to code which wants to use them, and hide all the internals from you. Good idea.

Peter Seebach

Comment

---

Writing good change log messages

(GeekStuff)

2009-01-17 03:53
Comment

Ever wonder what that idiot was thinking when he checked in a change that completely broke a piece of software, typically right before a deadline? Ever wonder if anyone’s thinking that about you?

I recently read a draft book by Paul Myers, on the topic of content. And he has some great information about how to write articles, books, blog posts, and a lot of other stuff in this book (not currently available, I’m afraid — but keep an eye out).

One thing he didn’t cover, though, is changelog messages for a source control system. I suspect he didn’t cover it because a vanishingly small group of people, of whom he may not be one, have ever had to write such a thing. So, just because I think the topic’s interesting, here’s my thoughts.

First, identify your purpose.

The purpose of a changelog message is to explain to a future reader what the purpose of a change was. Simple. It’s always this; if that weren’t the purpose, it wouldn’t be a changelog message. But you have to keep it in mind. The purpose is not to fill in a checkbox on a process so you can keep your statistics up. It is not to keep the CVS server (or git, if you’re lucky!) from being lonely in the night. It is to explain the change.

Fulfill that purpose.

This is harder than it sounds to do well — but not too hard if you keep the purpose in mind.

It is not enough to identify the change. Explain the change. I’m sure just about every programmer has seen an example to the effect of:

// increment i
++i;

“Fix bug in kernel” is no better. So how do we explain the change? Start with the basics. What is the effect of this change? What were things like before? What are they like after? Are you fixing a bug or adding a feature? Why is this the correct fix?

Go a bit further, too.

In many cases, you’ll find that the bug was hard to fix. In those cases, be sure to at least mention the wrong turns, and why they were wrong turns. If you came into this utterly convinced that it was a fencepost error and the solution would be to add the obviously-required “+1” to an expression, only that didn’t help, mention this.

Don’t worry if this makes the message a bit long. The source code repository is not going to run out of room because of a twenty-line explanation at the top of a fix, even if the explanation is longer than the fix. Do worry that you’ll omit it and the next person to touch the code will end up reproducing your earlier mistakes before understanding the code.

The changelog is like a timestamped comment.

One of the worst things about writing up a detailed comments explaining what is going on in code is that future revisions to the code may make the comments invalid. What you really want is some kind of mechanism to let you put a comment on the code that is somehow tied to the code’s state at a given time.

That’s the changelog. Use it. Be verbose. Be descriptive. Explain not just what you did, but why. Explain what else you tried and why it didn’t work. Explain how you diagnosed the problem.

Sooner or later, you will be that idiot who checked something in that broke the software. What is most important is not that your coworkers not think you’re an idiot — I can’t help with that — but that they can find out what you were thinking without waking you up at 3AM.

Peter Seebach

Comment

---

Circuit City liquidating...

(GeekStuff)

2009-01-16 13:07
Comment [2]

Well, it’s not every day you hear about 30,000 people losing their jobs all at once.

The reality is, I’m amazed Circuit City held out as long as it did. They were already in trouble before the current economic situation. So I guess I’m not surprised. Indeed, I wasn’t surprised when they started being in trouble.

I sometimes went to CC, because they tended to have occasional deals buried in among a lot of things that weren’t good prices at all. Their selection was erratic; they might have a few things much better than anything comparable at Best Buy, and a lot of random junk. Their music selection was mostly astoundingly bad, with an occasional unexpected rare album. Their selection of “anime and sci fi” was smaller than my home collection by far.

The big weakness, though, was the annoyance value. For many years, there were no checkout lanes; instead, each area of the store had a separate checkout counter. If you went shopping around lunchtime, this meant that there were six counters, widely spaced out, of which only three had people. Finding someone to ring a purchase up was hard. Furthermore, they were by far the pushiest store I ever dealt with in terms of phone numbers; they refused to sell me something without a phone number on some occasions.

In general, the impression I got of the store was that they were simply incompetent. Many years back, I thought I’d apply for one of their store cards, since I tend to get a lot of electronics. The service rep I spoke to insisted that she couldn’t process my request because I needed to provide a full name — but I had; my first name is a single letter. After this went back and forth a bit, she claimed that I had no credit history and couldn’t qualify for credit. This is an innovative claim — I’d just bought a house, and I had a several-year credit history. In short, either their software sucked or she was lying. Either way, the net result was less interest on my part in dealing with them.

I once picked up a charge+sync cable for a Palm Pilot there. It didn’t actually allow communication — replacing it with a cheap cable I got elsewhere made it work.

My overall impression of Circuit City is one of crazy and ill-considered store design, bad service, and incoherent policies. I’m sad for the employees, but totally unsurprised to see the store fail. It was just plain poorly run.

Peter Seebach

Comment [2]

---

Trivia point about external RAID on OS X.

(GeekStuff)

2009-01-13 22:25
Comment

This may be of more interest to Mac sysadmins than to the rest of my readers, but it was really, really, really interesting to me, in that kind of “OMG did we just lose everything” way that software so often is.

You can boot OS X from a software RAID (a virtual RAID device configured using the OS’s software, rather than hardware RAID).

If you are using an Intel Mac, you must format the disks using normal GUID partition tables, then use the partitions on those disks in your RAID. Otherwise, there’s no GUID partition table and the machine can’t boot.

This is not immediately obvious.

While I’m at it, be sure to enable group/uid management on a disk (“vsdbutil -a /Volumes/Raid”) before trying to ditto a root filesystem to it.

Here’s hoping this saves you the several hours it just cost me.

Peter Seebach

Comment

---

Read these books.

(GeekStuff)

2009-01-11 11:04
Comment [1]

Here’s two books that you should read, even though you may have never heard of them.

Book number one: Darrell Huff’s How to Lie With Statistics. This is a widely-recommended classic, and it has survived the test of time. One particularly statistics-blind idiot I once had the misfortune to suggest this book too said that, being right, he had no need to lie. This rather misses the point; the goal is not to learn to lie, but to learn to detect it when other people lie. As Huff points out, “The crooks already know these tricks; honest men must learn them in self-defense.”

Book number two: You’re much less likely to heard of Warren Weaver’s Lady Luck, but honestly I think it may be a better book. (It may also be harder to find in print.) Lady Luck is an excellent introduction to the theory of probability in general. A topic you may not think you need to know much about, but in fact you use probability every day — or make a lot of very stupid decisions.

Statistics and probability are both fields of inquiry that many people find upsetting and uncomfortable. We like to imagine that, whether through science or religion, we can obtain certainty. We want to know what is true. However, this is not to be. What we get is instead the opportunity to have confidence of what is likely to be true. Will smoking give you cancer? Maybe. It’s not certain, by any means. But are you more likely to get cancer if you smoke than if you don’t? Yes.

Being able to think coherently about probability is not a necessity, but it is a great advantage in making informed decisions likely to lead to success. It won’t make you rich; it will increase the probability that you become richer than you would have been, though (assuming that’s even what you want…)

Peter Seebach

Comment [1]

---

Thoughts on ADHD, half a year in

(Personal)

2009-01-05 11:32
Comment

A little bit over half a year ago, I started treatment for ADHD. Medication is amazing, but it doesn’t fix everything (and no one, I think, really expects that it does). So a bit of an update may be in order.

Medicated or not, I’m still pretty forgetful. Unmedicated, my forgetfulness achieves epic levels. You know that thing where sometimes you’ll start to do something, but by the time you get there, you’ve forgotten what it was? Most people have this experience sometimes. For me, it’s practically the normal state of affairs. Being medicated changes that noticably.

I am apparently one of the folks who acclimates to methylphenidate. Nearly everyone does some; dosage is normally gradually adjusted to some stable level. In my case, there is no stable level; if I take 36mg/day, after a while it stops working. Increasing dosage makes it work again… for a while. Solution? Go off it for a while. I spent a month off my meds, most of which I spent on vacation. Now I’m trying to make a point of skipping the ADHD meds at least two days a week, which seems to help, although I will probably eventually need a slightly higher dosage anyway.

What fascinates me most, still, is the number of things changed by this that I don’t think of as ADHD symptoms. For instance, when medicated I have depth perception. I have always been able to tell how far away things were, but it was cognitive metadata about them; suddenly, on meds, things sort of “pop out” and look closer or further, instead of just being a knowable distance away. Very odd. Changes in how I hear things, and see things, are fascinating to me. My normal unmedicated perception seems to be time-slices; I don’t see movement, I just infer movement from the fact that things have come to be in new places. I always described this as seeing motion, but now I’ve had the very different experience of seeing things moving. I don’t know how to describe this difference.

Language is poor at communicating perception. My friend Dave is red/green colorblind, but didn’t know this until he was in his 20s. He can tell red and green apart most of the time by staring at them. It’s harder for smaller objects, and some red/green pairs are harder to separate. He can tell often enough to have passed tests and so on. And yet… He can’t easily pick out a hot pink frisbee on spring grass. So clearly, his vision is wildly different from mine, and yet, most of the time we can use words to distinguish things and they work.

(Interestingly, both his wife and I can generally tell, looking at two things, whether he’ll be able to tell them apart or not, but people who don’t know him can’t.)

Peter Seebach

Comment

---

What's this, a new blog?

(Personal, GeekStuff)

2009-01-04 12:46
Comment

To make a long story short, I’ve long sort of hated Movable Type. This isn’t all their fault; I figured it would be fine to just use the file-based database scheme, and maybe it’d work well normally for a small, low-traffic blog…

But comment spam meant that it was doing an INCREDIBLE amount of work. I spent a lot of time filtering and dealing with it, and… I just got sick of it. And I’m not a huge fan of Six Apart.

I was looking into Wordpress (which is highly recommended by many people, and which I’ve used), and I stumbled across references to an alternative called “TextPattern”. TextPattern looked interesting enough that I figured I’d just go wild, try it, and see how it looked.

It looked better and faster, so here we are. :)

Peter Seebach

,

Comment

---

More on the GameStop thing

(Personal)

2008-11-06 15:38
Comments

This is a followup to GameStop doesn’t like my email address.

I’ve done some calling around, and the more I look at this, the more I think this is actually harmful rather than merely stupid. The key issue is this:

In the event that the “card verification service” does not think an order looks legitimate, the order is not even presented to the credit card issuer, at all. Nor are they contacted. What that means is that the fraud prevention people who actually have the ability to, for instance, disable a card that is being used fraudulently, are completely denied any information about the suspected fraud. They don’t even get notified that someone tried to use the card at a given merchant.

The argument that, if you think a transaction is fraudulent, you should not contact the customer (because they might realize you were on to them and adapt their attacks), is questionable but perhaps plausible. The argument that you should not contact the issuing bank is perhaps less so. Unless you know that the issuing bank is itself a knowing party to fraud, it seems very unlikely that there is any harm to come from letting them know about fraudulent use of their cards.

The underlying model, I think, is basically incorrect. If you have some third party other than the card companies doing fraud monitoring secretly, and without contacting the card companies, you’ve created a huge potential for left-hand/right-hand problems, as well as an agency with absolutely no accountability for false positives. If a credit card company generates too many false positives in their fraud detection, the customer can call them and threaten to leave. This third party, though, simply has no reason to care; as long as the number is “small”, they have two defenses. The first is to say “hey, we’re saving you more than we cost you”, which may even be true. The second is to claim that they are not false positives. After all, how would anyone know? It’s very hard to prove that a given transaction isn’t “fraudulent” in some way without someone, at some point, contacting the bank (who can contact their customer). So if you make it a policy that you NEVER contact the bank, it becomes impossible to determine whether there’s a problem.

Sounds to me like bad business.

Update: I spoke with them some more, and I know have an inkling of what they were pinging off of; it’s inconvenient, but not totally crazy. And wonder of wonders, they think they can get my order reinstated! So that’s pretty nice of them.

Peter Seebach

Comments

---

GameStop: We don't like your email address

(GeekStuff)

2008-11-04 10:56
Comments

So, a while back, I placed a pre-order at Gamestop for the Wrath of the Lich King Collector’s Edition.

They cancelled it, and did not contact me. (This has happened to other people.) I finally got in touch with them, and the reason is that their “card verification processor” has decided that my email address is “suspicious”. So there’s a suspicion of fraud, and they’ve cancelled the order. (I can’t place it again; the Collector’s Edition is a limited-supply item which sold out within a couple of days.) They don’t contact the people affected: There’s a suspicion of fraud.

So. If you are in the habit of pre-ordering games, do not order them from Gamestop. They may, if their card verification system hiccups, cancel your order.

They cannot disclose who does this verification for them. They have no information about it. They also say it’s very accurate and that they trust it, and that they cannot take a customer’s word for it that the system is in error.

Update: I got more information, and they’re probably getting me some games afterall.

Peter Seebach

Comments

---

WoW, zombie armies, and me.

(Personal, GeekStuff)

2008-10-23 01:17
Comments

World of Warcraft remains one of my favorite leisure-time activities. This evening, I decided to go hang out with some friends online, and play World of Warcraft.

I’m what they call a “carebear”. There are two components of Warcraft; Player vs. Environment (PvE) and Player vs. Player (PvP). I only play PvE. Why? Because I have an interesting mental quirk; I can’t enjoy conflict-based competitive play. I will happily play games where players compete to achieve an end, but I really hate games where players attack each other. Something’s off in my head (I suspect it’s the autism thing), and ANY kind of conflict between characters makes me feel like there is conflict between players. I can’t play games like this with anyone, no matter how confident I am that they like me and it’s just a game; my brain just takes it wrong. To give a rough magnitude estimate, imagine the experience of having someone in a blinding rage shouting at you from close enough that it’s hard to focus clearly on his (or her, if you prefer) face. That’s about how my brain interprets ANY kind of PvP action. So I avoid it.

Warcraft offers both. Some servers, called PvE servers, have PvP as an optional component; unless you ask to enter PvP mode, or try to raid an opposing faction’s capital cities, you pretty much don’t see it. Other servers, called PvP servers (see the clever naming convention?) automatically enable PvP combat when you leave your faction’s home territories. This is implemented through “flagging”; a character who is “flagged” can be attacked by characters from the other faction. Other characters can’t; you can just walk right past people and they can’t hurt you. (Unrealistic? Maybe, but it makes the game fun for people who don’t feel like playing PvP, right?)

There’s currently a really awesomely-conceived “world event” going on. Normally, the World of Warcraft is pretty static; the same people have the same quests every time you see them. You play a character, you meet a guard, he’s looking for a missing friend, you find the missing friend. Start a new character, come back… Same guard, looking for same missing friend, missing friend is in same place. Well, okay, it’s large enough that people don’t mind too much.

In a world event, something actually changes. For instance, right now, there’s a zombie plague. The zombie plague infects players, turning them into zombies. Zombies are comparatively weak, but can swarm, and can infect other characters (such as non-player characters), or other players. The infected players become zombies, and so on. The zombies are weak, so people mow down hordes of zombies, and much fun is had.

Only there’s one tiny flaw. Zombies are able to attack any player. At any time. With or without the PvP “flag”.

And this means that, for the duration of the event, the game is completely unplayable for me, and because it’s a dynamic, active, event, they aren’t about to tell us how long it’ll be.

Annoying.

IGN wrote about it — and yes, they used my thread. Woot! (BTW, I got banned from the forums today; although Blizzard hasn’t said why, I’m assuming it’s because they were offended that I didn’t like their content.)

Peter Seebach

,

Comments

---

« Older Newer »