The big dummy moment and first remote pairing

May 19, 2009 at 8:47 pm (Java, Javascript, Ruby, Week 9) (, , , , , , , , )

This morning I finished up most of a task from our biggest story, with some pointers from Micah. The big dummy moment came at the end of the morning, when I spent about an hour debugging why Javascript wasn’t working properly in our customized Webkit browser, and after going through everything I could think of, I realized that the browser had cached the Javascript file! Ack. So, my choices were to figure out where the cache was and clear it, or to do what Rails has always done for me behind the scenes to prevent caching: append a question mark and a big number to the filename. We’re using Sinatra, so I wrote a simple helper that does the latter:

def no_cache

Pretty simple, but I’m not sure I like the way it looks tacked onto the end of the filename in the Erb templates; that may need to change to take a parameter…

I spent a little time in the afternoon working on a JRuby bug that the JRuby team posted on their Twitter feed. The problem was with Array#pack, which I’d never used before (and quite honestly, still don’t entirely understand). It takes a formatting string and packs an array into a string. There was a problem when the asterisk (*) was used in a format string like “A4N*” – it’s supposed to take all the rest of the parameters from the string, but it was taking too few. I tracked it down to a change in value of a local variable (listSize). It was hard to spot, because I wouldn’t have expected the list size to change, so I wasn’t looking for that. Lots of System.out.println’s and compiling ensued. It really gave me an appreciation for Ruby’s interpreted nature. I’m sure there’s a way I could’ve streamlined things, but it was taking me 30 seconds to build the project each time, which is an eternity when you’re just debugging and adding print statements (and especially if you’re not too sure of what you’re looking for).

Micah and I did some remote pairing in the late afternoon, which I’d never done. We used iChat, which was really pretty awesome. We had some problems with audio volume and crashy programs, but all in all, I think it was pretty successful. Micah came up with a new data structure to eliminate some network traffic in our application, and we implemented it, simplifying code and adding a feature along the way. This was code I hadn’t seen before, but it felt a bit easier to get around – partly because it’s just simpler, and (hopefully) partly because I’m getting better.


Permalink Leave a Comment

More fun with JRuby (but for real this time)

May 14, 2009 at 10:19 pm (Java, Ruby, Week 8) (, , , , , )

Well, I knew I would see some benefits from my seemingly unproductive work yesterday, but I didn’t imagine that I’d be able to have a patch together today. It turned out that with the knowledge I gained yesterday, along with some smarter strategies, I was able to fix the issue with spaces in directories housing jarred gems that was haunting me. It wasn’t easy, but I tracked my way through the JRuby source and submitted a tested patch to the JRuby issue tracker. We’ll see; maybe it’ll get accepted, or maybe there’s something I haven’t thought of that’ll hold it back. Either way, I gained a lot of confidence, and I’m excited about taking up Charles Nutter’s call to fix RubySpecs in JRuby. Very timely!

I was also in on some meetings with the rest of the development team Micah and Doug are working with. They’re based remotely (Doug just flew back into town after working onsite with them), so we did some teleconferencing using Skype for video chat and Adobe Connect for screen sharing. It’s pretty amazing technology, and while I can’t discount the great value you see from working side-by-side all the time, I’m impressed that it’s so easy.

Micah and I did some CSS and Javascript (JQuery) work towards the end of the day. He’s not a fan of the CSS float attribute, so I had to convince him that it was worthwhile for the layout we were working with. Of course, there are generally multiple options, this case included, but I think we ended up with a good starting point for a screen we were laying out. JQuery’s AJAX capability is pretty awesome. We used JQuery.getScript(), which fetches a script from a URL and then loads and executes it (with an optional extra function parameter to run afterwards). It basically does the work that we would’ve had RJS do in a Rails application, but it seems much cleaner to me. We still have some thinking to do about how the performance is going to be in our particular case (1 web request per second will almost certainly be too heavyweight), but it’s a great start. The other big question mark for our current task is to what extent we’ll be able to test it. Luckily, resident TDD Javascript expert Jim Suchy is going to help us out with that. Thanks Jim 😉

Permalink Leave a Comment

JRuby struggles yield rewards

May 13, 2009 at 9:21 pm (Java, Ruby, Week 8) (, , , )

I was a bit cranky when I left work today, because I wasn’t able to track down the problem I was working on. I spent hours looking for the solution(s) to some outstanding JRuby issues with jarred gems, (one related to spaces in directories and one related to nested jars (like Hpricot and Limelight both have). And I got nowhere. Nothing to show for my efforts. I went down a ton of paths, tried logging, and added stack traces, but to no avail. The solution exists in the code, but the codebase is large, and I just wasn’t able to wrap my brain around the problem. And that sucks.

But in every situation, there’s an opportunity for learning. Eventually, on the way home, I relaxed and looked for the lesson in my failure today. I didn’t fix the issues, true. There’s no metric that I know of that says something positive came out of my work today. But I introduced myself to most of the filesystem-related components of the codebase, and I saw the mappings JRuby provides from Ruby methods to Java methods. (Annotations to the rescue for those Ruby methods like []= whose names would be illegal in Java!) I really internalized some keyboard shortcuts in IntelliJ. I learned a new trick where you press Command and hover over a method call to see information about it and the object it’s defined on.

Most of all, I learned what not to do when presented with a big codebase and a specific-sounding problem. I just jumped in, looking at the first place I saw referenced in the issue comments, and logging things, working at a micro level basically all the time. It wasn’t I got home that I realized I needed to step back and look at what was really happening on a larger scale – the context. I should have realized my problem during the day when I tried to explain the problems I was having and couldn’t really do so – next time I’m having these kinds of frustrations I’m going to pull the old rubber-duck trick (explaining the problem to a rubber duck or other inanimate object). If I can’t, something needs to change in my process.

Permalink Leave a Comment

Exploring Limelight

April 28, 2009 at 9:44 pm (Limelight, Ruby, Week 6) (, , , , , )

I spent the day continuing and accelerating my learning in the Limelight GUI framework. I’m sure I’ve mentioned before, but everything you write is Ruby code (there’s Java behind the scenes, so you run your applications with the JRuby interpreter and gems. Limelight is still very young (pre-1.0), and as with any framework, it takes time and advice to learn how the framework wants you to code. I ran across a couple of things that I felt would be more intuitive with a slightly different API (mostly styling-related), and Micah agreed and had me report them on the project’s Lighthouse page. There’s not a ton of tutorial documentation on Limelight so far, but here are the most important ones I know about already:

  • Installing Limelight
  • Calculator in 10 Minutes Screencast – Micah walks you through building a lightweight calculator application
  • Tutorial #1 – there’s a slight tweak you need to do to get it working this way, at least on the latest Limelight version
  • A Cook’s Tour of Limelight – great deeper-level overview of the parts of Limelight (Production, Props, Scenes, Players, Stages)
  • Style Attributes – similar to CSS style attributes, but with some awesome additions like built-in gradients and rounded corners (there are plans for drop shadows as well)

I’m sure as time goes by, there will be a lot more available, especially as JRuby gains in popularity. Keep your ears open!

I got the Tic-Tac-Toe game working with human players, which was a big step. There are still some kinks to be worked out with the “Play Again” process (I think my Java code is left waiting for input), but I’m excited to have it working, and to have spent the day getting better and more confident with BDD. Once I’ve patched those up, the real work will start on this assignment: styling it up, adding some effects, and in general just making it really presentable, with relation to the UI and design. I know my designer pals would be scared to hear about me designing anything, but I’d like to add some more design skill to the old bag of tricks, so I may be hitting them up for links to design blogs and other learning resources.

Permalink Leave a Comment

Week 5, Friday

April 25, 2009 at 10:22 am (Java, Limelight, Ruby, Week 5) (, , , , , , )

I took the steps necessary to have no parameters in the constructor for my Tic-Tac-Toe view class, so that we could implement the interface in JRuby during our Randori session over lunch. I’d spent a little time thinking about what it would take, so it wasn’t too bad. I had three parameters initially: a Controller, a PlayerFactory, and a Board.

Well, the PlayerFactory was only really being used in one method, and all we really needed there was an array of Strings that showed the types of games that were available, like “Computer (X) vs. Human (O)”. So I changed that method to take an array of strings, and changed uses of that method to pass in information from the PlayerFactory (they were all in the Controller, so no new package dependencies resulted).

Also, since the Controller already had a reference to the same Board object as the View, I just added a getter called getBoard() on the Controller, and used that to set the Board on the View rather than the constructor.

The last thing was taking the controller out of the constructor. The View needs the Controller, for sure, so I added a setter on the View, which any class that instantiates a View would need to call right after creating it. I don’t much like this, since I had to change all my test class setups, and it’s more work for anyone wanting to implement a View, but I think it’s necessary to make the connection to Ruby code.

I also started with the Limelight props and styles being built already, so for the Randori, we focused on implementing the View interface in Ruby. We worked in IntelliJ, and there were a few tongue-in-cheek complaints about that (from Textmate fans). I definitely don’t know IntelliJ as well as I know Textmate or even Vim, but the big plus it has for me is the ease of refactoring, and the color-codification of things that are not going to compile or run properly. At any rate, we got a lot done. After a bit over an hour, with rotation of pairs every 5 minutes, we almost had a running Limelight application that used two computer players. I just had to change a couple lines right afterwards to get it to work as expected.

I have to say, I was initially skeptical when Micah told me we could use my Ruby version OR Java version of Tic-Tac-Toe to implement it in Limelight. I knew my Ruby version worked, but looking back, I knew its OO design was weak; I don’t think there was any kind of display class at all, so I’d have had to change a lot – I may still do that. But to use Java classes in Ruby code? That sounds crazy, but honestly, it wasn’t too bad. But I guess the person showing us how to do this has written a framework using Java and Ruby, so you’ll have to decide for yourself:

require '/Users/colin/IdeaProjects/TicTacToe/tttt.jar'
module Board
def scene_opened(e)
@view = new View(self)

class View
include Java::trptcolin.baseGame.View
# implement methods

Now, it may only be this easy because we’re doing it through Limelight, but either way, I think it’s pretty nifty.

I felt a lot less embarrassed about my abilities during this Randori than at the last one, where I was basically useless. This time I had a lot of domain knowledge to offer (since I wrote the Java code and the Limelight props), but more importantly, I had a better idea of what to test when I was at the keyboard. I still felt slower than everybody else, but at least this time I felt like we were more or less on the same page.

Permalink Leave a Comment