9.06.2009

Don't look back, don't look forward. Look at where you are.

Yesterday was my last first gameday ever. The last time that I will ever, as a student and as a member of the Trojan Marching Band, experience the thrill of that very first day of USC football. There are more gamedays to come of course, but only a handful of them, and there is nothing like the first game: No substitute for seeing the Coliseum full of cardinal and gold, for the first time since a November or December game that seemed like years ago.

There are going to be a lot of "last" moments this year, and I know that at certain times, it's going to be tough not to get a little disappointed. From my very first band camp, I could already tell how important the band was going to be, and I knew the years would fly past me way too fast. I was right.

I was going to write a whole post about not taking things for granted, because if you do they will be gone before you know it. And I do think that every single day, you should think about all the great things in your life, and how lucky you are to have them. I was going to list all the things that I'm grateful for, from big things like being admitted to USC, to small things like the amusing little running jokes we have in the band, and everything in between.

But I'm beginning to think that won't be an issue for me this year. I'm beginning not to worry that I will take anything for granted. The greater risk for me, I think, is that I will go too far in the opposite direction. That I will spend too much time thinking about how quickly it's all slipping away from me; picturing what it will be like when I march my last step on the field; anticipating how that last finals week in May will feel; picturing commencement and realizing that I may be seeing some people for the last time.

So my goal is to strike the right balance. For every great moment that happens this year, I will mentally detach myself, just for an instant, to realize how lucky I am to be part of it. And then I will try to let the instant pass, clear my mind, and simply live in that moment. It's all about finding the right balance between reflecting on events, and simply living through them.

Fight on, Trojans.

8.11.2009

My email to the National Organization for Marriage.

I will let you know when I get a response. Should you become inspired to write your own email to NOM, the address is contact@nationformarriage.org

On Tue, Aug 11, 2009 at 6:47 PM, Tyler Breisacher wrote:
Hi there!

I've been reading the material on your website, and I'm particularly interested in the "talking points" page on your website. I'm a Californian and I was very involved in the gay marriage battle in this state last year. It's great to see the best arguments against gay marriage summed up in one place. Of course, this issue is far from settled, and is still being debated all over this state and country, so I want to continue to be as informed as possible in the event that the issue comes up when talking with my friends and family. In particular, I have a question about this point:

“Religious groups like Catholic Charities or the Salvation Army may lose their tax exemptions, or be denied the use of parks and other public facilities, unless they endorse gay marriage."

Of course it's usually hard to prove or disprove statements about what "may" happen so normally I would accept this as a very real possibility. But as Californians we have the unique perspective of a state that had gay marriage for a few months last summer, before we restored the traditional definition of marriage. I think pro-gay activists might jump on this point: "No one will lose their tax exempt status. Gay marriage was legal last year, and no one lost their tax exempt status, did they?" I wouldn't know how to respond to this. Do you have any news stories about churches losing their tax exempt status over this issue, either in California or elsewhere? I seem to remember a case from New Jersey but my understanding is that it was a fairly complicated situation, so it would be nice to see all the facts of that case laid out somewhere.

Whenever I'm discussing this kind of thing with my friends I like to be armed with as much information as possible, so if you could point me to more information on how gay marriage has negatively affected churches I would greatly appreciate it.

Thank you!

Tyler

8.09.2009

TDD with Infinitest

As I posted last time, I'm writing a game in Java called Flood It, copied from inspired by the game of the same name by Lab Pixies. I encourage you to play it and if you find any bugs, or would like to request enhancements, add an issue in the issue tracker. In fact, if you do play it, you'll probably understand this post better.
One of the most important classes in the game is called Grid: It represents the big grid of squares and also keeps track of which ones are in the upper-left group. Because it's so important, I decided to write some unit tests for it, because that's supposed to be the best way to write great code and all that. I'm also using a great little tool called Infinitest which continuously runs your tests for you in the background, all the time. What happened just now is, I think, a great example of why everyone says unit testing is so important.

The constructor for Grid takes a width, a height, and a number of colors. It picks some colors and then populates the grid with a random assortment of squares. So far, so good. But I'm trying to implement an undo/redo feature so I think I'm probably going to need to override clone(). In this case, the constructor will fill the grid with a bunch of incorrect squares, only to have the clone() method overwrite all that data. I decided not to worry about it. Here was my original clone() method:

protected Grid clone() {
Grid clone = new Grid(this.getWidth(), this.getHeight(), this.colors.size());
clone.colors = this.colors;
for (int x=0; x<getWidth(); x++) {
for (int y=0; y<getHeight(); y++) {
clone.data[x][y] = this.data[x][y].clone();
}
}
clone.update();
return clone;
}
The update() method just checks for any squares that may have suddenly become part of the upper left group because the player changed the color of the group, and adds them to the set. Can you see the bug yet? There are actually two bugs, very closely related. I might have caught both of them eventually by playing the game itself, but this method isn't called anywhere in the actual game yet so that might not be until a few days from now. Luckily, I thought to write a unit test:


private void testClone(Grid orig) {
Grid clone = orig.clone();

System.out.println("Original:");
System.out.println(orig);
System.out.println("Clone:");
System.out.println(clone);

assertEquals(orig.getWidth(), clone.getWidth());
assertEquals(orig.getHeight(), clone.getHeight());
assertEquals(orig.getColors().size(), clone.getColors().size());
assertEquals(orig.getNumInUpperLeftGroup(), clone.getNumInUpperLeftGroup());

for (Color color : orig.getColors()) {
assertTrue(clone.getColors().contains(color));
}

for (int x=0; x<orig.getWidth(); x++) {
for (int y=0; y<orig.getHeight(); y++) {
Square origSquare = orig.get(x,y);
Square cloneSquare = clone.get(x,y);
assertNotSame(origSquare, cloneSquare);
assertTrue(origSquare.sameColor(cloneSquare));
}
}
}

Actually, it was the comparison of the toString() outputs that led me to the first bug. Then I decided to add the getNumInUpperLeftGroup() method and use it in the unit test, which led me to the second bug. Which is why you shouldn't put information in toString() that's not accessible somewhere else. But anyway. The first bug was that clone.update() was not adding anything to the upper left group. I knew this because the toString() showed squares in the upper left group as capital letters and others in lowercase. In the clone, it was all lowercase. What was wrong with the clone's update() method? Nothing, actually. For a Grid constructed normally, the last thing in the constructor is upperLeftGroup.add(get(0, 0)); and then update(); My new grid needed that first square to "seed" the update method. So I added clone.upperLeftGroup.add(clone.get(0,0)); to the bottom of the clone() method, before the update, and ran the test again. This time the toString() outputs matched perfectly, but the test still failed.

I leave it as an exercise to the reader to find the second bug. And by that I mean I'm tired of typing so I'll post it later. But suffice it to say that without this unit test having caught the second bug, I might have had some very strange behavior that only showed up in a very particular case. It might have gone uncaught for weeks and when I did find it, it would have driven me crazy and taken me quite a long time to figure out.

This is why everyone says unit testing is so important. I think I get it now.

8.06.2009

New project: Flood It

Through a stroke of luck, I managed to gain possession of an iPhone for a few days, and I downloaded a game I really liked called Flood It. Knowing I'd only have the iPhone for a few days, and not knowing whether any implementations of the game existed online anywhere, I decided to try and make my own, and try to learn a little about Swing and GUI programming as I go.

If you have Java, download it and play it and let me know what you think. Hopefully I will continue working on it at least a little every day so try it out and if you have any suggestions or bug reports, put them in the issue tracker (I don't know if you need a Google account or what).

Enjoy!

7.20.2009

Windmills do not work that way!

Not everyone is a scientist, but there is a certain amount of science that everyone should know. If I were going to start a new blog where I explain scientific topics in laymen's terms, with the goal of improving the general public's scientific literacy, I would call the blog "Windmills do not work that way." Maybe I will do that someday. Like I'll maybe update this blog more often some day.

The line comes from the episode of Futurama I'm watching right now.

6.29.2009

OpenCongress.org

A group called the Sunlight Foundation is trying really hard to take the Good Idea That Everyone Agrees On, that the activity in government should be open and visible to everyone, and turn it into a Cool Website You Can Actually Visit.

It's called OpenCongress.org and it's as Web-2.0-y as you could possibly want. You can leave comments and discuss bills. There's a Facebook app. You can track things. Etc., etc.

Check it out!

6.28.2009

Stonewall

As you may know, today is the 40th anniversary of the Stonewall riots, which are often seen as the beginning of the gay rights movement. I was going to try to do a little reading on the history of the movement, and talk about how far we've come and how much further we have yet to go. But my friend Kyle basically did all that already, so instead, I encourage everyone to read his excellent post.

6.23.2009

Real-life Version Control

I had an idea today, about Version Control. Since probably half the readers of this blog don't know what that is, maybe this quote from the Subversion Book will help:
Subversion is a free/open source version control system. That is, Subversion manages files and directories, and the changes made to them, over time. This allows you to recover older versions of your data or examine the history of how your data changed. In this regard, many people think of a version control system as a sort of "time machine."
Subversion, and all the other version control systems out there, were generally designed by programmers, and they tend to also be used by programmers. This is because they tend to include tools that are good for writing code, like "diff," and that programmers are the kind of people that like to find technological solutions to problems.

Other people may have their own methods for version control, usually with pretty bad big-O complexity. Which is computer-science-speak for "wastes hard drive space, and runs slowly." Have you ever seen something like this on your computer?

project052809.xls
project052909.xls
project052909 - 2.xls
project053009.xls
project053009 fixed.xls
project053009 final.xls
project053009 with changes.xls
project053109 with changes 2.xls
project060109.xls
project060109 - new.xls
project060209.xls
project060209final.xls
project060209 really final.xls
project060209 FINAL VERSION.xls

... you get the idea. You don't want to lose track of old versions, because every time you delete
or change something, you know that you might later change your mind and want to revert back to that point. Well that's the whole point of version control, except that it's automated so you don't have to keep changing filenames. Plus it's done in a very clever way so that if you have 25 versions of a 400MB file, it probably won't take 10GB of file space to do it. If you like, you can have multiple people accessing the same repository, which means no more emailing the same file back and forth with minor changes. Even more exciting: You don't need anything fancy like a system administrator or knowledge of how to use Linux.

Anyway, the idea that I had today was "What if other types of engineers could use version control? What if we could version-control real-life things?" So I had an idea for a cute little video that could be used to demonstrate the functionality of version control systems. As far as I know, no one has yet created such a video. And by that I mean I looked on youtube for a few seconds and didn't find anything. Here goes:

A girl opens a drawer and gets out a blank piece of paper. A little blue question mark appears, hovering over the corner of the paper. She gets a pencil and starts drawing a picture of a tortoise. After a little while, it looks like a cute little tortoise, not bad for a first draft. She looks at the front of her desk and sees a little machine with several big friendly buttons on the front. She presses one that looks like a green arrow. Suddenly,
something pokes out of the top of the machine, and a laser shoots down and scans her new drawing. The laser mechanism retracts back into the device. The girl looks down and sees the the blue question mark has been replaced by a green circle.

The girl now cheerfully grabs a bunch of permanent markers from a cup on her desk, and begins to color in her drawing. As soon as she starts drawing, the green circle floating above the corner of the drawing turns red. She keeps going until the tortoise is looking rather adorable, and pushes the green button again. The device laser-scans her drawing, the circle turns green again, and she walks away, satisfied with her new drawing.

Cut to her friend's house. Her friend sits down at his desk, with no paper or drawing of any kind. But he does have the device. He presses a gold button on his machine, and suddenly an exact copy of the girl's drawing appears on his desk, with the green circle hovering above it. He grabs an orange marker and a black marker and starts drawing a tiger, standing behind the tortoise. The circle turns red. The tiger is, of course, ferocious. But it is also very badly drawn. Not seeming to mind, the boy hits the green button proudly. His drawing is laser-scanned and the hovering circle turns green.

The girl now comes back to her desk, and the drawing still looks like it did when she left. She hits a button on the version control device and it instantly changes to include the tiger. She picks up a black marker and adds an outline to the tiger to make him look less sloppy.

Etc. Eventually there would be a part where something goes terribly wrong, and they use version control to undo the changes. Anyway, that's my idea...