Using Javascript to order the client around

May 17, 2009 at 10:00 pm (Java, Javascript, Ruby, Week 8) (, , , , , , )

Micah and I spent most of Friday working on a lightweight messaging system that’s going to allow us to push messages from server to client, even though the client is basically a web browser. Since HTTP is basically stateless, we’re doing it with AJAX requests (Javascript, with some help from JQuery). And in order to keep it really simple and flexible on the client side, we’re developing something like a message queue on the server, which builds up Javascript for the client to execute whenever it’s ready (this way the server keeps track of time-sensitive issues, and the client doesn’t really have to hammer the server to stay updated). It’s a pretty cool idea that Micah had; he likens it to us putting food on a plate (at the server), and when the client’s hungry, he comes along and takes the food that’s there and eats it (executes it in the browser). We’re using the command pattern to fill up the plate of Javascript.

The lunch & learn was a bit more technical this week (after last week’s great Star Trek excursion), but still great fun. Doug presented a prepared code kata: TDD factorials in C++. I had already seen a little of CppUTest from pairing with Doug earlier in the month, but he went a little more in depth explaining the syntax, which we had just kind of touched on before. He’s teaching a TDD class this week, which I’m sure will be awesome for anyone lucky enough to attend.

Eric Meyer presented the development of a story using acceptance test driven development (ATDD) with Cucumber. He and I had worked with it a good bit while developing our Rails app (which by the way has been live for awhile now): a job board for software craftsmen, so I knew the syntax and structure already. Eric used a great technique to get the story done quickly and correctly while doing a good bit of live coding as well: git tags. He had about 8 steps to the development of the story that he had practiced, and each one was tagged, so that he was free to code in a normal way and know that we could fast-forward to the next step at any point. I’d like to learn more about version control (both Subversion and Git), but it’ll just have to go in the bucket of stuff to learn with everything else!

In less technical news, I finally got a Cubs hat. Look out Chicago, now you might have to hear me say “Y’all” before you know I’m not from around here.

Advertisements

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

Week 5, Weekend

April 26, 2009 at 8:20 pm (Reading, Watching, Week 5) (, , , , , , , )

I’m constantly amazed by the amount of information available online to help people improve and learn. To my wife’s chagrin, I spent several hours watching video lectures by Hal Abelson and Gerald Jay Sussman (from a 1986 course presentation at Hewlett Packard) and by Douglas Crockford (at Yahoo, I believe).

These aren’t directly related to my assignments for the apprenticeship, but I’m learning a lot. The Abelson/Sussman lectures (also on Google Video) are based on their book, The Structure and Interpretation of Computer Programs (SICP), which I understand was the introductory course at MIT for many years. I recommend the 256k mp4 versions if you’re downloading – the 64k are too hard to make out, and the high-res ones are huge! The language, Scheme, has got some pretty cool features, but to be blunt, the parentheses are pretty ugly. The really interesting part of this language, so far, is that functions are first-class objects, which can be saved into variables, passed into other functions, etc. This isn’t a completely foreign concept to me, as Ruby has closures like Procs and lambdas, but I think it’s the area of Ruby where I feel the least comfortable. Another pretty crazy thing is the way control structures like loops must work: recursion (a function might call itself with a modified index). I feel like I’d have had an easier time beginning to understand the minimax algorithm if I’d watched these videos first – the tree structure in particular was clearly explained, in one example, as it related to recursion.

I’d seen Caleb Cornman‘s tweets about the Crockford videos (they’re also available for download from the YUI Theater site), and realized (for the umpteenth time) that even though I’ve written a decent amount of Javascript in my day, I know basically jack about how the language works. I’ve generally just let the Rails helpers, JQuery, or Prototype to do the dirty work for me, hacking in the rest as needed. So that can work, as it does for many others, but trust me when I say that you don’t want to be debugging ugly Javascript. I’m a little weirded out that I just happened to be learning about lambdas and Lisp, and Crockford mentions several times that how Javascript is the first language with lambdas to really hit the mainstream. Javascript has no concept of classes, only objects! I’m surprised, but intrigued to learn a lot more about the subject. Currently debating whether to start with Crockford’s Javascript: The Good Parts (recommended highly by Jim Suchy) and David Flanagan’s Javascript: The Definitive Guide (the only book Crockford recommended other than his own). The local library has the 4th edition of the Flanagan book – I wonder how much has changed in the most recent (5th) edition… Anyone familiar with these and have advice?

I spent some time during and after each of the videos fooling around with practicing Scheme and Javascript, in Emacs and Firebug (a Firefox add-on), respectively. I’m starting to get the hang of Emacs, which is encouraging. I’d need to do a lot more reading and practicing to get as good with it as I am with Vim, but I feel like I should at least have a rudimentary knowledge of how to get around in Emacs, since it’s one of the most-used editors on Unix machines (and has such strong Lisp integration).

I also did a lot of reading, from Refactoring by Martin Fowler et al., and a book I’m reviewing for the Pragmatic Programmers. I won’t say much about the review book, but it’s very good so far, and I think it’ll turn out wonderfully. They were looking for someone who wasn’t an expert, and as I told Micah, that’s me!

Refactoring is so much more readable than I’d imagined. I had always thought of it in the same category as the Gang of Four Design Patterns book, which I flipped through once at a bookstore and found it to be far beyond my understanding. I think at this point it’d be easier, but Refactoring is extremely clear and easy to read. I wish I’d read it sooner, because it describes a lot of the things I’ve done to clean up my Tic-Tac-Toe (and to make changes to it as they came up). The automated tools in IntelliJ made the process easier, of course, but I’m also discovering that some of my bigger changes could have been made much easier by applying the steps in the refactorings catalog.

It’s always a good sign when you’re excited to get back to work and do some coding, but I’m wondering if I should be doing more actual coding at home. I may get into some Limelight Tic-Tac-Toe tonight – I think that things should fall into place more quickly now that at least some of the game logic is hooked up between Java and Ruby.

Permalink 2 Comments