Dynamism Clarified

Today I watched a video of a presentation given by Allison Randal entitled Exploring Dynamism. It helped me put everything I know about dynamic languages in perspective. Allison is chief architect of the Parrot virtual Machine and employed by O’Reilly Media.

She made a point in the video that while theoretically, languages are either static or dynamic, in practice they exist somewhere on a spectrum between static and dynamic as extremes. She also discussed at length the various dimensions of dynamism including dynamic typing, dynamic dispatch, dynamic compilation and dynamic loading to name a few.

I thought it was brilliant how she discussed the pros and cons of these features quite clearly without bogging the discussion down with examples from any particular languages. This allowed me to think about her points in the context of languages that I know. She demonstrated a deep familiarity with a wide range of dynamic languages throughout her presentation. I was also impressed by the fact that she used her expertise in natural language linguistics to inform her model of computer language linguistics

If you are a fan of Ruby, Lisp, Smalltalk, or even Java, I highly recommend you watch the video. It was certainly well worth my time.

Ode to a Ruby Gem

This morning I was thinking about a project that I am doing in Ruby. I found myself thinking to myself  “I sure am looking forward to getting more intimately familiar with active-record.” Active-record is the Object-Relational-Mapping component of Ruby on Rails.

I love a package that makes you eager to learn more about it. Not to say that you have to be intimately familiar with active-record in order to use it. Rails is just so well thought out that studying the API is actually fun. And, Rdoc, the Ruby documentation package, makes writing extensive documentation of your code so easy that programmers usually do a pretty good job of documenting their code.

I have been using active-record in my Rails apps for several years now. The reason that I needed to delve deeper into active-record at this point is that I am getting data from an external source (I’m scraping it from a web page), parsing it using nokogiri, another fine Ruby package, and then caching it in a local database. Consequently, I am having to do some thinking about how to structure the data that I cache.

Let’s face it, I’m not really all that experienced at database architecture. I can hack a little SQL when I need to but I haven’t had to do a lot of data normalization since I studied databases in college. Rails makes it easy to play around with your schema until you get it just right. I don’t mean to gush or anything but Rails makes these things so easy that it feels like playing instead of work. In my case, I guess it is playing, at least to the extent that I am not being paid to do it. But that’s another story.

Happy (belated) New Year!

So, here’s my first post of 2010. A new decade dawns. What will it bring? I hope a renewed commitment to blogging. I guess that’s a bit optimistic given my track record to date and considering it’s January 12th and I’m only now writing my first post of the year.

I’ve been working on a Ruby project the past week or so. It is basically a script to scrape data from pre-formatted text on a web page, cache it to a local database, then use it to generate animated plots to visualize how it changes over time. It sounds kind of pedestrian but is actually quite fun and is giving me an opportunity to build my Ruby skills on a task that I more or less understand instead of trying to build them while inventing something entirely new.

If I would just write for ten minutes a day to start with I would be in the habit in no time. Sigh!

Web Development is Just Plain Fun!

I’ve been reading a good book lately. It’s called RESTful Web Services and it’s by Leonard Richardson and Sam Ruby, O’Reilly Media, Inc, May 8, 2007, ISBN 0-596-52926-0. It got me past an old obstacle that I basically ignored when I initially encountered it, which is how to access the web through a proxy from Ruby. I updated my Rails homepage, a private affair intended to give me quick access to a number of links that I access frequently. While I was at it, I figured out how to display the RSS feed of this blog in the center column of the homepage.

So, how does this make me feel? Totally empowered and back on my game. I haven’t done any web development in so long that I was beginning to think I wouldn’t be able to catch up with all the new developments. I guess I knew better deep down but it was still exhilarating to finally update my homepage after literally years of not changing anything on it but the content.

I also started looking in to Amazon Web Services but that’s a topic for another post.

Powered by ScribeFire.

Arduino Mania Strikes Elkton

It all started innocently enough. I had $50 worth of Amazon gift certificates so I bought an Arduino Duemilanove from Hacktronics with part of the money. It came and I was thrilled to start blinking LEDs with it right out of the box. I wrote a little program that flashed “SOS” in Morse code. My wife said, “That’s kind of depressing.” So I changed it so that it sent “LOVE” in Morse code instead.

I don’t know why I am so surprised when things work the way they are supposed to. I think it probably goes back to all the times I built electronics kits and had to troubleshoot them for days to get them to work (if they ever worked at all). In any case, the bug had bit me. I started scouring the Internet for Arduino based projects.

One of the reasons that I was drawn to the Arduino in the first place was the concept of shields. Understand that this was not a new concept to me. The robots at work had been expanded through the addition of daughter cards that plugged into the motherboard. But the Arduino had dozens of shields that interfaced to all kinds of interesting hardware. And the best thing of all was that they were affordable on my next to non-existent budget.

I decided that I was going to build a robot from scratch. I had built a BOEbot and I still love to tinker with it but I had the urge to create a unique robot that was my design from the ground up. Oh, alright. I intended to assemble it from parts but I intended to build many of the boards as kits and assemble all the various pieces to make a unique final product. And what is really exciting is that it wasn’t just possible, it was down right easy.

I decided to build my robot around a chassis consisting of a Clementine tangerine crate that I had saved. I decided to use Google SketchUp to build a scale 3D drawing of the crate so that I could better visualize how I planned to transform it into a robotic vehicle. I managed to draw the crate itself fairly quickly but I’m still working on drawing the rest of the parts of the robot.

I drew up a prioritized list of parts that I thought I would need for the robot. At the top of the list was a Proto Shield. A Proto Shield is a board that has many uses but is often used as a place to mount a mini breadboard for experimenting with various hardware interfaces. The other major item on the list was a Motor Shield. The Motor Shield that I bought has connectors for 2 PWM servos and can control up to 4 bi-directional DC motors.

While I waited for my new hardware to come in, I decided to play with the hardware that I already had. I took one of the Infra-red receivers that came with my BOEbot and an old Sony CD player remote that I found laying around (the CD player had gone to hardware heaven years ago) and decided to see if I could get them to work together using the Arduino as the controller for the IR receiver. I got the circuit hooked up pretty quickly. Note: when building a circuit on a breadboard of one battery operated robot for control by another battery operated device, make sure you use a common ground. I eventually decided to just use the USB power from the Arduino.

Now I was ready for software. I Googled Arduino and IR and found RTFA‘s video on YouTube. I followed the link to his site and downloaded his code as a starting point. I hacked it to work with the particular remote that I was using and before my Proto Shield had even arrived I had created my first Arduino based hardware hack.

Then the hardware arrived. As I was soldering the power plug on the end of the wires coming out of the  9 volt battery holder with switch that I had bought, I decided that I was going to need a better soldering iron than the little pencil style iron that I had used for 30+ years.

The two criteria that I had were that it had to have a switch so that I didn’t have to bend over to plug it in and unplug it every time I used it and it had to have a shielded stand so that I could safely set it down while it was hot. The next day, I want to my friendly neighborhood Radio Shack and decided that the difference in price between the iron that met my minimal requirements and one that was variable digitally temperature controlled was small enough that I couldn’t justify not buying the fancy one.

It took me two evenings working about an hour an evening to assemble and test the Proto Shield. It took about 5 minutes to move the IR receiver circuit over to the Proto Shield and get it working.

Stay tuned. More mania is on the way.

Squeak Revisited

I can’t remember exactly when I discovered Squeak but it was probably the late 90s. Even in it’s earliest releases, it was awesome. In case you haven’t heard of Squeak, it is a modern implementation of Smalltalk, based on Smalltalk 80. It was written by Dan Ingalls, Alan Kay, Ted Kaehler, and Scott Wallace at Apple in the 90s to explore Alan Kay’s idea of the Dynabook.

Smalltalk is the epitome of object oriented systems. It is, in fact, one of the most copied languages around. For example, the NextStep library was based to a large extent on the Smalltalk library. Objective C draws many of its OO concepts directly from Smalltalk. To someone like me, who has been doing OO programming for something like 20 years, Squeak is like coming home.

I’ll have to admit, Smalltalk is hard to get your mind around. I have been playing with Squeak off and on for years. Mostly, I’ve marveled at the rich applications that came bundled with the package. Each new distribution brought more nifty graphical applications that, more than just being examples of how to write applications in Squeak, were incredibly useful in their own right.

The thing that has changed recently for me is that I discovered the online book Squeak By Example. This has broken down all of the last mental barriers that were hindered me in developing Squeak applications on my own. It is an excellent tutorial for anyone with any knowledge of programming at all. I wonder if it isn’t a great book for people that have no knowledge of programming at all. But that’s a topic for another time.

Squeak has rekindled the utter joy of programming in me. I highly recommend that you download it and Squeak By Example, or SBE as it refers to itself, and have fun. Set aside a good chunk of time. You won’t want to put this one down.

Drupal Resolution

I finally figured out how to configure PHP on my server. It was documented in my provider’s help desk pages. I guess I won’t move yet. I will probably wait until I can afford to buy a slice and keep this site. “Don’t fix something that’s not broken” I always say. I promise I’ll write a post that is about something more substantial than my web hosting configuration adventure real soon now. In the mean time, at least I’m posting more frequently.

Drupal Woes or To Slice or Not To Slice

The domain name finally propagated and I tried to install Drupal. Now, it complains that one of the PHP configuration variables is set to an unsafe setting and refuses to let me install until I fix it. This is infuriating. I spent about an hour researching the issue and discovered that there may be a way that I can resolve the issue on this server but it entails another round of emails with tech support. I have hit my head on this problem enough times that I’m tempted to buy a 256M slice from slicehost and move everything, my domains, this blog, etc., over there. Don’t get me wrong. I like my web hosting provider. I think I’ve just moved beyond the services that they provide. I suppose I could ask if they provide a similar service to slicehost before I just jump ship. Food for thought.

More on the Process of Programming

I was thinking today about programming. In particular I was thinking about programming languages. I came to the realization that the elegance of a program depended upon not only the abstract clarity of the algorithm itself but also upon the the appropriateness of the programming language used to express the algorithm. Hence, like natural languages, certain algorithms will be more elegantly expressed in certain programming languages than they will be in others. Now I need to see if I can rustle up some examples to support my premise. Stay tuned. Yet more to follow.

Blogged with Flock

Tags: , ,

A Short Essay on the Process of Programming

I approach programming as an exploratory process. I can’t seem to bring myself to sit down and plan a program out in minute detail beforehand. The truth is, any program that I understand well enough to plan out in minute detail beforehand, doesn’t interest me in the slightest. I want my programs to teach me something I didn’t know when I started writing them.

Consequently, I usually start out with some vague idea for a program. I write the shortest little bit that might work and compile and run it. Even better, I use an interpreted language like Lisp or scheme or ruby so that I can skip the compile part. I love dynamic languages!

At first, I find myself exploring the boundary between the language and the environment. For example, I have spent hours exploring the Dir module in ruby. I have spent similar amounts of time exploring similar functionality in Common Lisp. Knowing how to traverse the file system in a given language is an important detail.

Another facility that I often dwell on is the reflective capability of a language, that is the ability of a language to know or discover details of its structure. For example, most symbols in ruby have a method methods that returns an array of methods that the object implements. methods is a reflective method. It allows the programmer to discover details about the programming environment dynamically at run time. Reflection is also called introspection.

Java implements reflection, demonstrating that languages not typically considered dynamic can be introspective too. The clever trick to Java reflection is that Java doesn’t create data structures to describe itself until you actually need them. This adheres to one of my favorite principles that states “you shouldn’t have to pay for features that you don’t use.” I’ve heard this principle called parsimony.

The underlying theme to these language features is that they all help make a language more adaptive. One of the key characteristics of human intelligence is our ability to distance ourself from a situation and analyze it with detachment. This is an important part of our ability to adapt to rapid changes in our environment. The ability of someone to reason about their relationship to their environment is essential to intelligent behavior.

Now I’ve really tipped my hand. The romantic notion that has captured my imagination is the quest for emergent intelligent behavior or Artificial Intelligence as it is commonly called. I try to avoid the term Artificial Intelligence because I find that neither the word Artificial nor the word Intelligence lend themselves to unambiguous definition, much less objective measurement. In fact, many of the great debates in the field revolve around this shortcoming.

To be continued.