What's happening here? And when?

A while ago, I posted to the Go users list about what seemed like a problem in how Go was choosing registers versus global variables. Roger’s answer was “go RTFM”, which was precisely the right thing to do. However, it took reading it twice (I’d read it before) and some hard pondering to connect what I was reading to what I was seeing. In order to save you, the reader, from the same experience, here’s a more detailed explanation of how “happens before” applies to programs where coroutines are writing to and reading from globals. Disclaimer: You really shouldn’t be doing this. In Go, you “share memory by communicating, not communicate by sharing memory”. Asking questions about “what happens when two coroutines write to a global?” means you are already thinking about communicating by sharing, and you are in for a world of hurt. But in this case, I was exploring the concurrency model in coroutines in the absence of calls into the runtime (i.e. cooperative or not?) and so I wanted to avoid channels. ...

November 1, 2010 · 5 min · jra

Go Fun - the cost of threads

Here’s a little program I wrote in Go. In it, I wanted to explore how it might work to create a giant “onion” of threads, passing messages in towards the center, where they would be reflected and sent back out. Why? Just for fun, to solidify my grasp on the syntax, to see what would happen. Here’s my program: package main import ( "fmt" "time" ) func make2() (chan int, chan int) { return make(chan int), make(chan int) } func makeAndEcho(ct int, in, out chan int) { var in2, out2 chan int; echo := func () { for !closed(in) { x := <-in out <- x } } pass := func () { for !closed(in) { select { case x := <-in: { in2 <- x } case x := <-out2: { out <- x } } } } if (ct == 0) { go echo() } else { in2, out2 = make2() makeAndEcho(ct-1, in2, out2) go pass() } } func try(depth, n int) { in, out := make2() makeAndEcho(depth, in, out) before := time.Nanoseconds() for i := 0; i < n; i++ { in <- 1 _ = <- out } close(in) after := time.Nanoseconds() transits := int64(n*depth*2) fmt.Printf( "%v round-trips, %v nsec/trip, %v nsec/transit for %v transits\n", n, (after-before)/int64(n), (after-before)/int64(transits), transits); } func main() { try(10, 10000) try(100, 10000) ch := make(chan int, 1) before := time.Nanoseconds() for i := 0; i < 200000; i++ { ch <- i _ = <- ch } after := time.Nanoseconds() fmt.Printf( "no threads: %v nsec/transit for %v transits\n", (after-before)/200000, 200000) } When you run it, you get this: ...

October 12, 2010 · 3 min · jra

The SQL backlash

I remember sitting in my databases class years ago and thinking, “This can’t possibly be the right way to store data.” It was a strange class, because it mixed theory and practice in a way that was anathema to the way I think. The theory part bored me to tears, and seemed ludicrously useless (first normal form? third normal form? who cares!). The practice part seemed ridiculously complicated and pointless. Why go to all that effort to write something down? Why not just write it? Yes, yes, I know, ACID and all that. I grudgingly learned it all, and I passed the class. But it never felt right to me. It felt like the students were putting on a performance to satisfy the teacher. It didn’t feel like Theory of Computing (i.e. Turing machines, regular expressions, the halting problem, etc), which just Felt Right. ...

July 3, 2009 · 2 min · jra

<nudge> <nudge>, <wink> <wink>

FOP can get confused and do stupid things. Giving it a nudge in the right direction fixes it. For example, when a table is going to fill the page right up from where it starts to the end of the region available for it, it does ok. But add a footnote onto that table, and the footnote ends up dangling at the top of the next page. I thought a bit about why this is happening, and I thought about what if you added a keep to the footnote, etc. What I ended up wanting to do is to nudge down something higher on the page so that it created a bit of whitespace in a place where the reader wouldn’t notice. That made the table not fit, which made the table break, which put the table footnote where I expected it to be, instead of hanging in space. ...

June 30, 2009 · 2 min · jra

Dealing with a clogged link

A friend asked me a question that reminded me of some great resources I want to mention here (in case I ever need to find them again…) They are: How to Accelerate Your Internet Wireless Networking in the Developing World Wireless U In my response to my friend, I also touched on something interesting I learned from Cricket, and from years as a consultant. Here’s the big lesson: Infrastructure projects don’t sell themselves. ...

June 30, 2009 · 3 min · jra

Disabling hyphenation in DocBook

When you are using the chain “DocBook -> FO -> PDF”, it is the FO processor that decides on the hyphenation of your words. This is because it knows the lengths of the lines it is making. In FOP, hyphenation can only be turned on and off at the level of <fo:blocks>. For some dumb reason, DocBook doesn’t have a way to turn off hyphenation in one region of the document. ...

June 24, 2009 · 1 min · jra

Printing a Blog

I got interested in applying my new XSLT wizardry to the task of printing an entire blog. Like making every post into a big PDF and sending it off to a print-on-demand service. Digital backups = bad. Paper backups = good. I thought it would be easy, just do “Wordpress export”, then write the XSLT to turn the export XML file into FO, and process into PDF. Well, it is easy, in principle. But in practice it’s not. ...

June 17, 2009 · 6 min · jra

Just Married

I’ve been away from the web for a while because I was in Olivone, Ticino, Switzerland getting married! Thanks to friends and family who came from so far away to witness such a special day. And thanks also to our wonderful vendors, who made the day go so well. If you are thinking of putting on a wedding in Blenio, give these guys a call: Restaurant/Hotel Arcobaleno Osteria Centrale Casa Lucomagno Pasticceria Bini for wedding cakes Viva gli sposi wedding photojournalism Giramondo Travel Agency for the wedding registry Sonpalaria, the heartbeat of the Ticinese dance floor! It feels different to be married. It seems like it shouldn’t… the house is the same, we still sleep on the same sides of the bed. But it’s different. Good. And safe. And happy. And… different. ...

June 14, 2009 · 1 min · jra

Apache FOP and document properties

I am a little bit obsessive about checking out the document properties in PDF files I read. I can’t explain why, but there you have it. I was sad when I noticed the PDF file being emitted by my XML has no document properties. So I figured, no problem, I can just go find the right FO tags, grep for them in the DocBook XSL and reverse engineer what stuff I need to put into my DocBook to get them set right. I figured it would be something obscure like, or something. In fact, DocBook already knows who the author is, in order to format the title page nicely, so no dice there. ...

May 24, 2009 · 2 min · jra

The <xen> of <xslt>

For a project I am doing right now, I descended into DocBook hell. Not completely unscathed, I made it through the learning curve (why don’t they call it what it is: The Unfathomable and Horrific Tunnel of Learning) and blinked slowly in the light of day. I realized DocBook is nice, but it’s not actually what I wanted. Doh. What I wanted was a structured way to represent my data, and I want two things to happen to it. Today, I want to publish my data with DocBook. Tomorrow I want someone to be able to suck the brains out of my DocBook document (leaving it to wander the earth as a zombie) and to put them into a wiki so that my project can become a community-maintained database, instead of being a single DocBook-formatted document that lives in my Subversion repository. ...

May 23, 2009 · 3 min · jra