Knuth Bug, Call by ?, OpenExp

A few interesting things:

A bug in Knuth’s Art of Computer Programming

I opened it up yesterday to see if he had anything relevant to some code I was writing, and a bug crawled out (and I squashed it). I thought to myself that it’s not often that people find bugs in Knuth’s books…

Hecl and SourceForge

We’re still debating how Hecl ought to work in terms of call by {reference/name/value/whatever}, which has proved to be very interesting, and require some healthy mental gymnastics to think about it all. Unfortunately, as of late, SourceForge has been rejecting email from gmail. How annoying is that?!

Hecl @ OpenExp

I want to the OpenExp conference in Cerea on Sunday to give a talk about Hecl. That area of Italy is sort of like the Nebraska of Italy. Wide, flat, and not a whole lot there (although this being northern Italy there are still lots of little towns). In any case, the talk when ok, although I don’t think I got quite as many people as I could of… it’s frustrating trying to think of a title or some means to convey to people that here is a technology they can use to do something cool (write programs for their cell phones) very quickly and easily. The people that were there seemed to “get it”, though.

openexp

Tomorrow, Sunday the 1st of October, I’ll be at the openexp event to talk about Hecl. Hopefully I’ll also get a chance to catch up with various people in the Italian open source scene who will likely be there.

Who calls what how?

We’re having quite an interesting discussion on the Hecl mailing list about the semantics and syntax of the language (since it’s in its early days, we get to do that!). I have some questions for those of you reading this, if you have time to comment.

Hecl inherits a lot of things from Tcl, which is both a simple, and amazingly flexible language. One of the things that Tcl lets you do is modify the value of a variable. For instance, set x [list 1 2 3] ; lappend x 4;. However, what is at times confusing for people is that to get the value of a variable, you place a dollar sign in front of the variable: lindex $x 0 would return 1 for instance. To some people this is all quite intuitive, because commands that modify the variable take its name, which is then looked up in a hash table and fiddled with as needs be. So we have constructs like if { $n == 10 } { incr n }. To other people, especially those who come from the Perl and PHP worlds, variables always have a $ in front of them, so the Tcl way of doing things doesn’t make as much sense. Even for experienced programmers, it can at times require a moment to recall how a particular command works. lappend foo ; lrange $foo ; lset foo ; lindex $foo and so on. On the plus side, this is all very easy to implement, and really isn’t that difficult to figure out.

One avenue I’ve pursued with Hecl is to be able to pass references around, instead of variable names, so that all commands just take “a variable”: lappend $foo x instead of Tcl’s lappend foo x, and so on. For the moment, I’ve also enabled proc’s (user defined commands/functions) to receive references to variables passed to them, so they can modify them. This is both powerful, and dangerous:

set x 1
proc foo {v} {
    set v [* $v 10]
}
foo $x
puts "foo is $x" ;# $x is now 10

(Well, not exactly, but that’s the general idea). We are considering ideas like marking the variables that may be modified in the proc definition to reduce the danger of people shooting themselves in the foot. In any case, it increases consistency, because commands that modify values always take a $variable. That still leaves commands like set foo 10 (others are proc, foreach, and catch) that take variable names to be created, rather than $variable $references, so perhaps to someone who comes from the world of PHP, it’s still not as clear as it could be.

We’re also considering some radical changes, for the sake of not excluding any particular direction: taking a more lisp/ruby/python like approach, and not using dollar signs for variables (except perhaps in string interpolations). This has some slight disadvantages in terms of requiring quotes around more things (in Tcl, you don’t need to quote single world strings). This might result in code that looks something like this:

proc test {name code result} {
   catch code res
   if { eq res result } {
       ok name
   } else {
       fail name res result
   }
}

proc testfiles {files} {
   global ok
   global failed
   # clear success/error list
   set ok [list]
   set failed [list]
   foreach f files {
   puts "Running $f"
       source f
   }
}

Which isn’t bad, although in some places, I think the added syntax of $ helps to make it clearer, at a glance, what’s what. eq $res $result is just that much quicker to pick out. This is especially true if you stash a command name in a variable.

In other words, set p puts ; $p "hello world" might be a bit a bit clearer than set p "puts"; p "hello world", but… it’s definitely “eye of the beholder” territory, and depends on what you’re used to!

In any case, it’s been a very interesting process, and I’ve greatly enjoyed the company of Alexandre Ferrieux and Wolfgang Kechel on the list, as well as my friend Salvatore Sanfilippo. They’re all very bright guys with good ideas, which makes for lots of thought-provoking discussions.

Where you come in, if you’ve made it this far… is what kind of syntax and semantics you prefer, and why? Call by name? By reference? Modifiable values? Tell me what you think!

Rails pagination with N results

For a site I’m building with Rails, I wanted to paginate the results of a database query with the built in pagination utilities. However, out of the box, paginate doesn’t take a :limit option, because that’s used to get a certain number of results per page. This is the workaround I put together. Perhaps there are better ways, but this was quick and efficient.

In the controller:

class StoreController < ApplicationController

   # This is for Pagination.
   DEFAULT_OPTIONS[:first_n] = nil

This lets you use a new option to paginate, :first_n (which isn’t the best name, but was the first thing that popped into my head).

Now, you override this method:

  def count_collection_for_pagination(model, options)
    unless options[:first_n].nil?
      return options[:first_n]
    else
      return model.count(:conditions => options[:conditions],
                         :joins => options[:join] || options[:joins],
                         :include => options[:include],
                         :select => options[:count])
    end
  end

So, if you only want N results, you then do:

@prod_pages, @products = paginate(:products, :condition => condition, :first_n => 100)

Seems to be pretty quick and simple, so it works for me, although I’m sure a Ruby expert could make it look even nicer.

Preliminary MIDP2.0 Support for Hecl

Wolfgang added preliminary support for MIDP2.0 to Hecl this afternoon. It’s exciting news, because it’s a big chunk of very useful code – MIDP2.0 is what most fancier phones have – in other words, it’s what other geeks are running. Hopefully this will increase Hecl’s appeal to that crowd. Naturally, the code was just checked in, so it’s probably only suitable for those willing to hack on it and get involved right now, but hopefully we will cut a new release that includes it “soonish”, depending on the amount of free time I have.

Thanks!

American Economics Association

It’s obvious from my writings that I have developed an interest in economics, which developed out of a curiousity about the workings of free software business – how were we to make money creating free software? While that’s still an open question, the tangent has been a fascinating one that I’m glad I followed. My work with the Tcl programming language further encouraged my interest as I sought to reconcile the language’s extremely high quality and versatility with its falling popularity. If the answer wasn’t a technical one, it had to be some squishy, human factor… economics and marketing.

In any case, one of the things that has frustrated me about economics compared with my native territory of free software is the relative paucity of on line information, and almost total lack of quality sources of feedback (discussion groups or the like where serious discourse is the rule, rather than quackery or debates that quickly degrade into political rants). Not having the time, nor at present the inclination to sidetrack to the point of pursuing a degree in economics, which is the most obvious way of coming into contact with a lot of thought on the subject, at the recommendation of professor Stephen J Turnbull, I signed up to the American Economic Association, which sends out several hefty academic journals every quarter.

Some of the math is a bit daunting, but there is quite a bit of material on various topics, and I think many others (there seem to be a fair amount of open source people with at least a passing interest in business and econ) who want to see something “closer to the metal” would find these journals worth their while, and it’s not very expensive to sign up.

Summer vacation

I’m back in Italy after a wonderful vacation in Oregon. I had a nice time in Portland at OSCON, and got to meet a bunch of people I most likely won’t see for a while, which is always fun. In particular, David Jones of OFBiz was impressive in his determination to do anything and everything to make that project a success. It would have been nice to spend a bit more time at OSCON, but vacation called. On the negative side, I’d kind of forgotten how these things at time break down into cliques, but c’est la vie. It reminds me that I prefer the inclusiveness that is at times more present in Italy.

Going a bit off topic from the topic of this journal, “computer stuff”, we went all over Oregon… Portland, the Gorge, Mount Hood and Timberline Lodge, the central coast, Eugene of course, including a wine tasting trip along the applegate trail, Waldo Lake, Paulina Lakes, and over as far as Fort Rock and the high desert, which was quite a spectacle for us city dwellers acustomed to being surrounded by people.

One of the great things about Oregon, and being on vacation there, is the bookstores. Powell’s is probably the world’s largest physical bookstore, and the separate technical shop is larger than all but the largest bookstores in Italy. I couldn’t resist buying a bunch of books there, and at the Smith Family Bookstore in Eugene, which has loads of used books at good prices. I bumped into Russ Nelson, of the Free Software Business mailing list, in the Economics section of Powell’s, which was an interesting chance encounter.

Amongst the books I picked up:

The Paradox of Choice: Why More Is Less

A good read, but it could have been condensed significantly and still got its point across. I think there is a lot to be learned in this book for us programmer types, who tend to be very much ‘maximizers’ in what we do. I’ve written about this some here:

Maximizers, Satisficers and Programming Languages

Why Globalization Works

The book explains what the title promises. It’s a long read, because the author is very thorough and provides lots of supporting facts and figures.

Growing a Business

Good read on creating and growing a business, even if it’s a bit dated, and related to the individual in question and his experiences. Now, if only I had the business…

How to Bring a Product to Market for Less than $5000

Haven’t read it yet, but I have some ideas for products completely unrelated to high tech (it’s stuff from Italy, actually) that I think would do quite well in the US. Contact me if you’re interested…

The Design of Everyday Things

Haven’t got around to reading this one either (also, I have a backlog of The Economist to read here at home, which is usually time consuming). It comes high recommended though.

The Third Chimpanzee: The Evolution and Future of the Human Animal

I enjoyed Collapse as well as Guns, Germs and Steel by Jarod Diamond, and this one looks interesting too. In light of the aforementioned backlog, I left this one with my parents to read, and I’ll check it out later this fall.

Why Most Things Fail

Doesn’t seem to be rated very well on Amazon, but Ormerod’s thesis that economics-as-a-machine isn’t tenable is interesting, and I’m curious to see the details of that idea. Perhaps one of his earlier books would be good reading as well.

I’ll try and write up the books as I read them, if they prove worthwhile.

New laptop?

I’m looking forward to meeting people at OSCON tomorrow (Thursday) we decided to skip Wednesday, because we’re still a bit tired from the trip over, and… we’re on vacation.

One thing I’m considering while I’m in the states is getting a new laptop because 1) Oregon has no sales tax, and 2) I can get one with a US keyboard (I can’t stand Italian keyboards for programming).

The OS would be Ubuntu.

Any recommendations?

Oregon – OSCON

After more than three years away from home, we’re going on vacation to Oregon this summer. Luckily, that will coincide with OSCON in Portland, so hopefully it will be possible to meet some people there that I ordinarly wouldn’t get to see. Write me email if you’d like to get together for a beer or something! The rest of the time, we’ll be in Eugene, or travelling around the state.

.rhtml minor mode

[ Update – new version is here: https://journal.dedasys.com/articles/2008/09/25/rhtml-minor-mode-update ]

Emacs has been my favorite editor for a long time, due to its incredible flexibility to meet new challenges, and extreme programmability. Things like tramp are just too cool to do without.

In any case, I’ve been doing more Ruby on Rails lately, and as part of that, have run into a few irritations with existing emacs tools. For instance, editing .rhtml files is not quite as nice as it could be. One reason is that psgml-mode, which I use to edit HTML files wants to have access to the DTD declaration in use. Since Rails usually puts fragments in one directory (app/views/foobar/show.rhtml), and the “parent” template in another (app/views/layouts/foobar.rhtml), it means that the “child” template doesn’t have access to the DTD in use, and so autocompletion of tags is not as accurate as it should be. Luckily, psgml mode provides a way to tell it that the parent is elsewhere. Utilizing this, I wrote a bit of elisp that automatically goes looking for the parent .rhtml file when you load up a fragment. It’s just an initial cut, and could use some improvement, but it seems to work for me:

http://www.dedasys.com/freesoftware/files/rhtml-minor-mode.el

On the TODO list:

  • Actually examine the layout file, to look for the top level tag that contains @content_for_layout.

  • Make _partials.rhtml type files work, or at least ignore them. The problem being that it’s hard to find out what tag they are contained within.

Patches, comments and suggestions are welcome!