Saturday, April 17, 2010

Moby Scheme - The Funnest Way To Develop Android Apps

Grant mentioned that there was a new release of Moby - the platform that allows you to develop Android apps in a Scheme - available. When I last played with Moby, I was impressed - and now I'm even more so.

Trying It Out

Writing Android apps in Moby couldn't be easier. Despite what the docs imply, you don't need to use GIT, or run the compile from the command line. You just write your source code in DrScheme and hit Run, and all the work is done magically for you.

Here's a trivial Hello World app:

#lang planet dyoo/moby:2:34
;; The above line will automatically setup the moby environment
;; downloading everything you need.

;; Moby uses the World (http://world.cs.brown.edu/) style programming
;; model. This will define our state.
(define-struct world (font-size color-index))

(define colors '("#FF0000" "#FFFF00" "#FFFFFF" "#00FFFF" "#0000FF"))

(define (pick-color index)
  (list-ref colors (modulo index (length colors))))

;; This function will be invoked to draw our UI,
;; which is just an HTML document.
(define (draw w)
  (list (js-div '(("id" "main")))
        (list (js-text "Hello World"))))

;; This will be invoked to style the HTML document above.
;; Notice how we use the state of the world to decide
;; what our style should be.
(define (draw-css w)
  `(("main" ("background-color" ,(pick-color (world-color-index w)))
            ("font-size" ,(format "~apx" (world-font-size w))))))

;; This functions is invoked as the application proceeds in time.
;; we use it to increase our font size.
(define (tick w)
  (make-world (modulo (add1 (world-font-size w)) 36)
              (world-color-index w)))
  
;; This function will update our world to use the next color index.
;; This data is used during the styling of the document.
(define (next-color w)
  (make-world (world-font-size w)
              (add1 (world-color-index w))))

;; Kick the program off, telling the system to use the callbacks above.
;; Our basic behavior:
;;  (1) every half-second, increase the font-size by 1 pixel
;;  (2) when the device is shaken, change the background color in use
(js-big-bang (make-world 0 0)
             (on-draw draw draw-css)
             (on-tick .5 tick)
             (on-shake next-color))

The first time you run this program, there's a significant delay, as the Moby framework is downloaded from Planet Repository. You're then taken to a screen where you can run your app in a web browser, download a JavaScript version of the app, or an Android version (.apk).

After getting the functionality right in the browser, I downloaded the .apk. I also downloaded the latest SDK from Android, and then ran the following commands:

  adb get-serialno     -- confirm that the android phone is detected
  adb install moby-play-debug.apk -- install the app

And that's it! The app was found on my main menu, and I ran it. There was a long delay between starting up the app, and having it run, but it does work. Even the shake functionality works as expected.

Impressions

I'll start with the cons: you're programming in the Advanced Student Language, which can feel limiting; and there's no sane error messages when testing your apps; and the workflow between writing code and deploying it to the your phone seems clumsy and slow. But with all that said, on the plus side, this is tremendously fun!

I mean seriously, I hammered out this little app in just a few minutes - and creating other apps that more functional should be just as easy. I love the World style of programming, as it gives you both modularity and simplicity. Even programming in Advanced Student Language is kind of fun, as you're forced to break down your apps in a more modular way.

The bottom line: Moby isn't ready yet for production apps, but it is ready for those who want an easy way to program their Android phone. As a tool for eduction, and getting folks excited about programming, it seems like a home run. I sure hope it continues to evolve, I think it has huge potential.

4 comments:

  1. That is pretty cool. Do you know if full PLT is the goal on Android?

    ReplyDelete
  2. Robert -

    Hmm..that's a good question. I don't really know. Personally, I think I'd be satisfied with the Advanced Student Language, especially if the process was bullet proof.

    The only thing the ASL seems to be missing is some kind of include mechanism. I think it's essential to be able to write reusable code and include it in a common file.

    Other than that, simple is good.

    ReplyDelete
  3. a ping pong program with wescheme cloud :

    http://www.wescheme.org/openEditor?publicId=beech-hoops-whirl-route-slept

    moby is fun

    ReplyDelete
  4. JV - Thanks for sharing!

    ReplyDelete

LinkWithin

Related Posts with Thumbnails