And just what is “this”?

I’ve just spent about three hours debugging JavaScript. If you’ve never debugged JavaScript yourself, let me assure you, it’s a real pain. Rejoice that your life, whatever its disappointments, has not led you to this pass. If you have, and you know my pain, let me share some hard-won insight and advice. For instance, “this” may not mean what you think it means.

Continue reading

Getting It Done

I’m a self-taught web programmer, and I’ve noticed that to a degree all technical books, inevitably, present best-case examples, in which programming is starting from scratch, and the project is fairly simple and well-defined. That’s a reasonable fantasy to use for didactic purposes. After all, it would be distracting for an author, or a reader, to address the points of a programming language or framework or whatever the topic of the book may be if the author had to make the scenarios in which the knowledge is put to exemplary use realistic. It goes without saying, though, that actual experience is different.

I’d like to offer a little peek, then, into my own application of some new technology I’m trying to master–Web 2.0 techniques using Javascript–to a project that seems typical of the kind of work journeyman programmers like me tend to do–a small online store and content site with a small budget. The interesting thing about the work is the way I’m using a fairly inflexible but fully-featured online store package as a CMS and publishing system to produce skeletal HTML and then layering over that somewhat HTML a platform of unobtrusive Javascript and CSS that handles layout, presentation, behavior, and occasional asynchronous communication with the server.

I’m hoping that writing about it will bring my own thoughts into focus and might help other programmers confronted with applying technical knowledge to their projects’ actual conditions.

Continue reading

An Unexpected Crime Report

It’s been a while since I’ve gotten back to working on my crime tracker. In the meantime, an interesting crime report came to our email boxes: a robbery on an illegal gambling house. The report got my attention for three reasons: 1) Apparently the operators of the illegal gambling house chose to call the police after the robbery, 2) The report does not give the address; it just describes the location as a nearby residential neighborhood, 3) The robbers took, along with other things, the victims’ pants.

Points 1 and 3 are interesting as sociological data about criminal behavior, but point 2 is a challenge to my data model. I can’t enter a report for a report without a location: a latitude and longitude. I’ll have to think about how to address it.

Continue reading

The Algebra Study Group

HOST: Next up on our program, we discuss the findings of the Algebra Study Group, the bipartisan panel convened this year to review the math-class policies of eighth grader Timmy Morgan. We will be joined by several members of the committee and ask what their consensus opinions are and whether they think Timmy will take up their recommendations.

For some time now, much of the public have felt Timmy Morgan’s algebra grades have been sliding, and many are calling for a change in course, whether that means studying more, reapplying study time to more effective methods, or even, some say, dropping the class altogether. The situation got worse this November, when Timmy’s midterm exam results came back. The results have been read as a repudiation of Timmy’s stubborn insistence that his study methods are working. A growing majority of Americans, polls show, think Timmy deserves to be grounded until his grades improve. In light of this development, the country has been waiting anxiously for the release of the Study Group’s report. It was delivered to Timmy last week, and released to the world shortly thereafter.

Here to discuss the group’s findings are former Virginia Governor Charles Robb, former representative Lee Hamilton, former Secretary of State James Baker, and former Supreme Court justice Sandra Day O’Connor. It’s a distinct pleasure and honor to have you as my guests.

GUESTS: Thank you.

HOST: Secretary Baker, you’re an old friend of Timmy’s family, of his father especially. It’s public knowledge that father and son have disagreed to some extent on the best approach to the algebra class. His father’s high school math teacher recently published an op-ed piece in the Times calling on Timmy to change course. How did you view your role in the study group, and how did you define the outcome you desired, given your closeness to the family?

BAKER: Well, my ties to the Morgan family do go back a ways. That’s public knowledge, I suppose. But this is a critical matter. I made it clear to Timmy that I was going to be as objective as possible, not necessarily taking his dad’s side but looking at the situation as it lay, even if it meant grounding or less computer time. I owed that to him.

HOST: Ah huh. Representative Hamilton, this was a bipartisan group. How well did democrats and republicans get along working together? Timmy’s grades are a topic of intense partisan debate, in Washington, on talk radio, and in the blogosphere.

HAMILTON: These are polarized times. Democrats think Timmy ought to be taking piano lessons, and traditional conservatives are maybe dissapointed that Timmy didn’t try out for the football team, as he promised he would last year. But I think all of us understand how important it was that we work together and try and find solutions, not talking points or positions, but solutions, for Timmy and the American people. Democrat or Republican, I think both sides of the aisle can sympathize with Timmy when he explains, “Math is hard. I’m working hard.”

HOST: Representative Hamilton, a lot of people expected a bold recommendation from the group. A lot of people in your own party hoped you would recommend dropping algebra altogether, even though opponents of that strategy called it “cut and run.” How do you respond to those who might say the report doesn’t go far enough?

HAMILTON: We don’t think dropping algebra would be the best way to go. It would probably leave Timmy’s math standing in chaos and jeopardize his college application prospects. We do recognize that Timmy can’t continue to devote as much time and effort to algebra as he has been. His other subjects will ultimately suffer as his mental capacity is stretched. There will have to be a drawdown of study time, especially with looming challenges like Spanish I and American History looming on the horizon.

ROBB: If I may make a comment?

HOST: Go ahead, Governor Robb.

ROBB: We looked seriously at the withdrawal option, and we agreed, democrats and republicans, not to recommend it. It’s better for Timmy, and better for America, to stay and finish what Timmy started as best he can. Now, we did make a number of recommendations that Timmy and his advisors have not heretofore seriously discussed.

HOST: If I may cut in, Governor Robb, I was just getting around to asking you about one of those recommendations, a controversial one, that Timmy talk directly to neighboring students with an interest in algebra, such as Brian and Mary about helping him study.

ROBB: Indeed. We think that direct talks with these math brains might lead to insights and opportunities for joint studying and maybe even structured tutoring. We know Timmy has differences with these two, accusing them, at times, of busting the curve and intentionally being know-it-all math weenies, but it’s time to focus on the goals and tasks at hand.

HOST: Indeed, Timmy has called Brian “Brainiac” and “Brain-o”, and he usually refers to Mary as “The Lesbo.” Justice O’Connor, do you really see direct communications becoming a possibility given how far apart Timmy and these two are?

O’CONNOR: It’s definitely going to be a challenge. Arguably, both Mary and Brian are happy to see Timmy floundering. They’d like very much to use his troubles to cement their control over the algebra class, where they already enjoy increasing influence with Mrs. Fletcher. Timmy is especially upset over Brian’s alleged project to build a mathletes team from the class members, a move Timmy says would be, quote, the gayest thing ever, and would make their class such a total laughingstock that it would be like dropping a bomb on them. And he accuses Mary of dominating the girls who sit nearby and thus preventing him from getting a date to the fall dance. But as Secretary Baker says, just because someone’s your enemy, it doesn’t mean you can’t talk to them.

HOST: Indeed, and Brian’s comment that Timmy is “The Great Satan” hasn’t helped either, I’m sure.

Let me also ask, Secretary Baker, do you think Timmy is going to take these suggestions seriously? There have been indications lately that he is lukewarm to them, at best. He was overheard in gym just yesterday saying he was going to get other opinions and weigh them all deliberately, beginning with his World of Warcraft and Second Life allies “SekataryDeth” and “GangstaBone”.

BAKER: Timmy has the right to consult whomever he desires. We understand that. He’s the decider.

HAMILTON: I’d like to add, however, that Timmy must act soon, regardless of what decision he wants to make. If he doesn’t, he’ll likely end up grounded, and he may even lose the trip to Disneyworld he was promised for his birthday next spring.

HOST: Indeed, it is a critical situation. Your Honor, gentlemen, I thank you for your time, and I express America’s appreciation when I thank you for your service as well.

GUESTS: Thank you.

O’CONNOR: It was a pleasure to join you.

Crime in College Park

We’ve had a little bit of a crime wave here in College Park in the last month. Although things have quieted down recently, for a while it seemed my wife’s email account was getting daily reports of a UMd student getting robbed at gunpoint or jumped. Campus and county police have flooded the area, at least by day, and temperatures have dropped, so maybe that has driven the criminals out. But not before we’ve been privileged to enjoy some painfully funny public relations and press coverage, and not before I was inspired to come up with a Web 2.0 crime tracking tool. Read on for more.
Continue reading

Spam Poetry

I’m not the first to point this out, but among the hundreds of pieces of spam that accumulate in my Junk folders, which I occasionally sift for valide messages that got marked as spam incorrectly, a few real gems of drivel, nonsense, or prurience turn up. Such a treasure has shown up in my inbox today, a Dadaist poem, or possibly an e. e. cummings tribute, ostensibly about topics in computer programming but actually signifying nothing. Read on for the sound and the fury of spam poetry.

Continue reading

What I’m Reading: Ruby Month

October is Ruby Month for me. September was kind of Ruby Month too, but the past is past. Read more for descriptions of Dave Thomas’s Programming Ruby: The Pragmatic Programmers’ Guide and Bruce Tate’s Ruby on Rails: Up and Running. I think they’re both fantastic books for intermediate programmers discovering ruby and rails.

Continue reading

The Ruby Pattern Spy, Part II

Getting a Little Organized

I’m mostly a self-taught pogrammer, so I tend to cite books as influences. One book that has influenced me a lot is Test-Driven Development By Example, by Kent Beck. Beck is a big proponent of XP, and in this book he walks his readers through the process of writing tests first, and then coding just enough to make the tests pass. The book convinced me to trust test-first enough to give it a fair and thorough try-out. It was hard to write that first test that really only tested for the existence of a class and method. But once I started working this way, I found myself not only testing before I coded, but thinking before I coded too. “This method I’m proposing should exist… is this the right signature? Could it be simpler and more flexible?”

So I’m going to do the same thing with this Pattern Spy. I’m going to add a method to my test script that uses some application code, an object of class PatternSpy.

require 'test/unit'
...
def test_spy
pspy = PatternSpy.new(Regexp::new("", Regexp::MULTILINE),
"www.michaelharrison.ws/index.html")
assert_not_nil pspy.spy
end

This test obviously fails because there’s no PatternSpy yet. In crafting the test, though, I’ve expressed my desire to be able to instantiate a PatternSpy object with a Regexp object and a string for the URL to examine. I’ll need to handle that in the initialize method. I also want a ‘spy’ method, and I want it to return something if the Regexp matches the URL, or nil if it doesn’t.

Coming up: First Code