Sunday, December 30, 2012

What makes a language?

I've been thinking a bit about what makes a computer language. None of these thoughts are probably original, I only think they're worth writing down for me because I haven't picked them up from elsewhere. As I try to learn to use scala (not just write a simple program in it) this issue is substantially in the fore.

So here goes.

A language seems to have at least three important aspects: the language syntax itself, the environment (hardware/virtual machine/operating system) where programs in the language will execute, and the cultural norms built around the language. Each of these have a significant impact on the final utility of the language. And it isn't clear if any one of these has primacy over the others. I'm not going to dwell on any of these aspects, only present them through example.

For learning scala I've chosen to implement a simple program that merges data from two CSV files and then performs some calculations. The program's simple enough that, had I just wanted to solve this problem, I would have proceeded through trial and error to complete the program, using whatever tutorials are available out there regarding the language itself. In doing so, I would only have learned a bit about the language. I would have experienced the impact of the environment only minimally. I don't think one really experiences that until one implements a truly substantial piece of software. And I would have learned very little about the language ecosystem. I could implement such a project entirely through eclipse and the scala plugin.

Put another way, this would be a depth first approach to learning a language: learn one aspect of the programming language really well. Then backtrack, and learn another piece, perhaps re-implementing the original program with the new found knowledge.

Another way to approach learning a language, which I think is much more effective for an experienced programmer, is much more akin to best first search. I've written substantial code in Java, enough to know reasonably good programming practices. My goal is to produce scala programs of comparable quality. To do so, I have to find the parts of the scala language and ecosystem that will let me develop a program that's comparable in quality to my java programs.

If the goal is to practice test driven development, for example, I might learn enough of scala and ScalaTest to write a failing test case. And I'd learn to write and execute the test cases through eclipse. I'd also want a build tool that doesn't rely on my IDE. In the case of scala that would be sbt. These few tools would give me sufficient scaffolding to learn more of the language. And so on. My goal after all is to not just learn to program in scala, but learn to produce a high quality program using scala.

Tuesday, December 11, 2012

Scala + Eclipse + sbt

As much as I'd like to use emacs for scala, I'm wary of using packages for a fast changing language that haven't seen any recent changes. As far as I can tell, the emacs package for scala hasn't been updated since some time in 2011. And we're nearly at 2013.

So, eclipse it is.

The next problem was getting emacs to recognize and work with a scala project correctly. I like my emacs+ extension, so I haven't updated eclipse from indigo to juno. I installed the scala extension for eclipse. I installed sbt. And I set up a simple hello world application following the sbt tutorial.

I then installed sbteclipse in sbt, and generated an sbt project. The resultant project had a funny name with the source file in the wrong place. Apparently the scala ide for eclipse doesn't like source files in the package base.

To get a nicer looking project you need a build.sbt in your project. This seems to be the minimum:

name := "hello-world"

Also put a package declaration in your hello world program, and have the source file reside in the corresponding directory.

I've also found manually creating an eclipse run configuration doesn't function correctly. Eclipse isn't able to find candidate main methods automatically, as it does for Java programs. And then I found the easy way: with your main file open, click on the run command. Voila!

To find my way around I've found a simple github project to use as a guide. The language itself seems to have adequate tutorials to get started, but understanding the scala ecosystem is taking some time and effort.

Starting with Scala

I'm currently starting with Scala development. I'm sad I didn't make enough headway with Clojure. The tutorial is a pretty good overview of the potential power of the language, and I'm looking forward to diving in and putting together a little project. Here's what I have so far:
  1. Install scala.
  2. Play with the scala repl.
  3. Search online for a csv library, and discover an opencsv wrapper.
  4. Learn I know nothing about the library distribution culture around scala, and find something called sbt.
  5. Realize that scala development is equally feasible in emacs and eclipse.
So, emacs or eclipse? Given the portability and transparency of an emacs based development environment, I am strongly leaning in that direction. The downsides? Configuration is more complicated. And eclipse has really nice support for java development, which I've never tried with emacs. In theory sbt should make switching between the two environments relatively. Maybe I'll give both of them a spin.

Sunday, June 24, 2012

Lein, noir and emacs

I like emacs, and I like the support emacs provides for lisp languages, including clojure. I'd like to have my clojure instance running as an inferior process as I develop my application. And given that I'm playing with web apps, I'd like that process to also include noir, my (tentative) web application framework.

Step 0: My Dev Environment

My primary box is windows 7, but I don't want to develop in windows for various reasons. So I have virtualbox running ubuntu, where I have installed emacs 24.

Step 1: clojure-mode in emacs

In emacs 24, run M-x package-list-packages, and install clojure-mode. After that, M-x clojure-jack-in starts up an inferior clojure process, and connects emacs to that process.

Step 2: Create a noir project

Install lein 2. Then,
$ lein new noir my-project
creates a new project. This is a complete web application with some sample pages.

Step 3: Load the project in emacs

Once again, run emacs and open the project.clj for my-project. Then M-x clojure-jack-in. Load your web app into clojure with:

user> (require :reload-all 'my-project.server)
nil
user> (my-project.server/-main)
Starting server...
Server started on port [8080].
You can view the site at http://localhost:8080
#<Server org.eclipse.jetty.server.Server@5c67718d>

I had to look at the server.clj generated by noir to find the precise calls I had to make. I imagine these would be subject to change as noir evolves.

Noir

I've recently been working on getting a simple web app working with clojure. The first step was to pick a web framework. Having no real reason to pick any one in particular, I used the rigorous process of googling "clojure web framework" and picking the first web application. That turned out to be Noir. The simplicity of getting started on the first page looked nice, but not reality.

I was working with clojure 1.4.0 and lein 2. The process on Noir's front page is for clojure 1.2.1 and lein 1, which I either missed or they missed. After trying a bit, I posted on the forum, and got some quick help. With lein 2, creating a new project is more like:

$ lein new noir myproject

There are at least a couple of more steps before I feel I've got the dev environment going:
  1. Write a `hello world` app.
  2. Develop through slime/swank.

Tuesday, June 12, 2012

macfuse is dead, long live macfuse!

I had used macfuse several years ago, while I was at SRI. I have a mac again, but macfuse is now defunct. A new project has forked from macfuse, OSXFUSE. Here's hoping it offers all the same functionality...