Skip navigation
ANNOUNCEMENT: community.oracle.com is currently Read only due to planned upgrade until 29-Sep-2020 9:30 AM Pacific Time. Any changes made during Read only mode will be lost and will need to be re-entered when the application is back read/write.
In this blog, I describe how the Racket language provides fun graphics and a nifty web framework. The  

In this blog, I address my grief with blog uploading, following Paul Graham's advice about choosing technology. ♦ 

Someone just complained on the java.net bloggers list about the wretched online blogging tool. Indeed, I couldn't imagine actually authoring in that thing. Instead, I paste in my HTML code, upload the images, and curse when I have to adjust the image URLs. Clearly, this is not the right way of doing it either. I looked at offline blogging tools such as Thingamablog , or ScribeFire. But I quickly realized that this was still a step in the wrong direction. Each of those tools has its own half-baked environment for authoring that may be fine for Aunt Tilly's recipe blog, but it just doesn't cut it if you write about coding.

A blog post contains HTML. I have an HTML editor, thank you very much, since I author just about everything in XHTML: web pages, slide presentations, blog articles, and even entire books.

As an aside, this often surprises my students. Why don't I use Word and PowerPoint, like everyone else? Well, as this classic article states: “When you choose technology, you have to ignore what other people are doing, and consider only what will work the best.” Wise words indeed.

In my line of business, character markup matters a great deal. When I write: “Consider a variable var of an type T1…”, I really care about the fact that var is written in monospace but that the two blank spaces to its left and right are not in monospace, and thatT  is in italics and not monospace, and 1 is a subscript and not in italics.

In Word, this requires lots and lots of repetitive mouse clicks and trial and error. For example, click between the T and the 1 and type a character. Will it be in italics? A subscript? Neither? Trying to design Word macros that reliably switch fonts on and off is an exercise in frustration—Word seems to think that font boundary locations are some kind of no-man's land.

Of course, in HTML, it is always clear where one font ends and another one starts. That's why I use HTML. It's not what other people are doing, but it's what works best. Why not some fancier XML dialect such as DocBook? Nothing wrong with that, but for me, HTML + a microformat is good enough. In fact, it's better since I have a wider choice of editors. For making PDF files, there isPrince, and for slides, there is Slidy. Since I am careful to produce XHTML, I can transform into DocBook, or SafariML, or PearsonML, or whatever.

Back to the blogs. I needed a tool that takes an XHTML file, uploads the images and the files using this wild and wooly XML RPC API, and munges the image source attributes in the process. I found almost what I needed in the AsciiDocproject—a Python program that uploads AsciiDoc or XHTML files to WordPress. Unfortunately, WordPress uses  a different XML RPC API than java.net.

I looked at the source of the AsciiDoc tool, and it uses regular expressions to manipulate XML, which isn't really my thing. I knew I could do betterwith Scala.

It was an easy matter reimplementing the tool in Scala. Except, I realized that, in order to share my creation with the world, I needed some configurability since I couldn't just bake my blogging password into the source. Ugh, that meant processing command-line arguments. But fortunately, the Scala infrastructure is getting better all the time. I googled for “getopts Scala” and found several  packages, a couple of which are in repos that sbt/Ivy/Maven can find. I picked one of those, added the repo to my sbt configuration, looked at the sample code, and tried it out in the Scala REPL. 30 minutes later, I was done with my command line processing.

The source for the blog upload tool is here. You need Scala and sbt to build it (see the README.html). Let me know if you are interested in a pre-built binary.

In this blog, I ponder why Ruby and Scala are easy to learn and complex to master, and how their cultures differ. ♦

The Lunar new year has passed, and a new semester has started at Ho Chi Minh City University of Technology, where I am spending my sabbatical . Last semester, I taught the standard undergraduate programming languages course, mostly using Scala. This semester, I teach a second course that is not required, so I can do any fun stuff I want. 

I am using Bruce Tate's excellent Seven Languages in Seven Weeks book for guidance (which I recommend highly). But I am deemphasizing syntax even more than Bruce does, and I diverge from his treatment by choosing some topics and languages that are more academic/cutting edge.

We started with Ruby, just as Bruce does. Why Ruby? It's an easy sale because of Rails.

For someone who knows Java and some functional programming (whether from Scala, Scheme, ML, or whatever), Ruby is pretty easy to learn. I was able to cover the basics in one lecture.

  • Duck typing
  • No braces but Algol-style if/loops/function definitions
  • Blocks
  • Arrays and hashes
  • Miscellaneous function stuff: optional (), optional return, varargs, named and default parameters
  • Class stuff: instance variables have @,attr_accessor,initialize,self

That's enough to be dangerous productive.

Then I prepared my lecture on metaprogramming, and I quickly said “holy cow!”. There are a dozen ways of doing the same thing slightly differently, and I was soon in a fog of mind-numbing detail and sample code that looked like random line noise. It took me a long time to pick a subset of the features that made this example work the way I wanted to.

That made me think about Scala. Why is it that Ruby walks on water but Scala tends to get a bad rapfor complexity?

It's a little difficult for me to make an exact comparison because Ruby doesn't even have a language reference manual, but it seems to me that Ruby and Scala are pretty comparable in their “complexity budget”. Ruby spends it on an intricate metaobject protocol, Scala on an intricate type system.

I went back to last semester's slides to review my Scala crash course, and it wasn't all that different:

  • var/val/def
  • Types after names
  • Anonymous functions
  • Arrays, lists, and maps
  • Miscellaneous syntax stuff: optional (), optional;
  • Class stuff: Fields give rise to getters/setters, primary and auxiliary constructors

And yes, that's enough to make you productive in Scala. You can merrily code along and use other people's libraries. Of course, you won't necessarily understand how they work under the hood, but then again, how many Rails users really know what makes ActiveRecord tick?

However, I sensed a significant difference in theculture of the Ruby and Scala crowd, at least as evidenced in the blog posts. The Ruby afficionados seem like a bunch of wizards trading spells. “Hey, try this one, it worked wonders for me!” The Scala discussions remind me of a faculty commons room, where everyone wants to show that they are the smartest one. “Well, if you would just take the monadic point of view, it would be obvious that...”

I exaggerate, of course, and I am glad that Scala attracts the smartest ones who, after all, build the stuff that we all get to use without knowing how it really works.