In order for m0cxx0r to be useful for writing tests at Linden Lab, it needs to work on all of the platforms that we target with C++ applications, so today I tried building and running m0cxx0r on Windows.
Initially it looked good: m0cxx0r built in the default Visual Studio Debug configuration, but then crashed on construction of Mock objects due to accessing unitialised memory. This was relatively easy to fix, just requiring a call to memset to zero out the memory that would become the m0cxx0r::Mock object.
The next problem was harder to fix. One of the hacks at the core of m0cxx0r is pointing the mock object’s vptr at a donor vtable populated with methods that record calls to the methods. The problem is that the signatures of the original and replacement methods may not match, so multiple parameters may be passed to a method expecting a single parameter. This shouldn’t be a problem as long as the caller manages the stack unwinding: the caller just pushes parameters on to the stack which are ignored and then popped the back off again.
Although m0cxx0r just worked when compiled with GCC on darwin, the run time checks performed in Debug by Visual Studio caught the stack pointer mismatch and stopped execution. In Release the situation was even worse: the tests just crashed out without error. Luckily after some poking around I was able to turn of the stack pointer run time check in Debug and after some trial and error I found that disabling optimisations in the Release configuration with the default __cdecl calling convention allowed the tests to run without error in Release.
With these property changes made, m0cxx0r built and ran it’s tests fine in Visual Studio 2005 on Windows. Get the Visual Studio 2005 project and solution files along with the m0cxx0r code from Google Code.
A few weeks ago at JAOO I felt insanely jealous while watching Erik Doernenburg demo Mockito: I wanted dynamic mock objects in C++. It turns out that it’s really hard. However, after a few days hacking around I found that it’s not completely impossible. The results of my hacking are now available under a BSD license here. m0cxx0r lets you write tests like this in C++:
typedef m0cxx0r::Mock<ProductionClass> MockClass;
MockClass* mock = MockClass::create();
mock->expect("foo", &ProductionClass::foo);
mock->expect("bar", &ProductionClass::bar, 42);
mock->expect("baz", &ProductionClass::baz);
mock->foo();
mock->bar(3);
mock->verify();
MockClass::destroy(&mock);
Most importantly you don’t need to hand code a test double for ProductionClass: m0cxx0r generates it for you. The code needs lots of love: it’s all in a single file and the interface will need iterating a few times, but I think it’s a good start. Please download it, have a play and let me know what you come up with. I’ve only tested it on gcc version 4.0.1 on darwin, so I’d be interested to know if it works on other platforms as it uses some code layout assumptions that might not be portable. I’ll write some blog posts over the next few days that explain how it all works.
Was without a doubt the phrase I heard most often yesterday, especially if you include variants like “Not Like Second Life”, “A bit like Second Life” and “Unlike Second Life”. Whatever else it’s achieved, Second Life has definitely become the frame of reference for the small and somewhat myopic crowd that made up the delegates at the sparsely populated Virtual Worlds Conference in London yesterday.
Vastpark is not like Second Life because it works in a web browser. Everyone on the web integration panel seemed to agree that virtual worlds in a browser is the next step, so I was glad to be there to question the TechCrunch consensus. How does having a world in a browser help? What does back and forward mean to a virtual world? What does it mean for presence to have 10 tabs open looking in to different parts of the same virtual world? Why would you want your view further constained by extra web browser widgets? Isn’t 3D in the browser going to be a blood bath for the next few years? Aren’t you really just using the browser as a download path? I suggested that the final question was the real reason that developers are pushing virtual worlds on the web and that the integration that most people want is to be able to use existing web and 2D media while using virtual worlds and use web services as a universal data bus between virtual worlds and other web aware platforms.
MPEG-V is not like Second Life because it’s a standard defined by 35 companies which is much better than the emerging Linden led standard according to Dr. Yesha Sivan in what was the worst talk I’ve heard in a long time. Not only did he make the standardisation process sound like a 3 year political bun-fight by people who didn’t know much about virtual worlds and who might come up with a bad standard, he managed to spell MPEG and Google incorrectly, called Sun’s Darkstar, Blackstar and attributed a Ugotrade quote to Philip Rosedale amongst other clangers. He was roundly rebutted by a large part of the audience including Tara5 Oh who questioned the need for old fashioned standards processes in the web era. Thank goodness for rough consensus and running code.
Most of the virtual worlds talked about in the investment panel were not like Second Life, but were nearly all Club Penguin clones. This copy the big exit attitude was called out by one of the audience as it seemed to be at odds with a lot of the talk about wanting to back the first in a market, but at least one of the panel is still looking for a successful 18+ social world play. The panel ended with a show of hands from people wanting money and people wanting to invest, but the economic climate made the whole affair very muted with lots of the panelists saying that they are slowing down rates of investment as it’s difficult to get existing companies off their books.
As with Virtual Policy 08 and the Virtual Worlds Forum the most valuable parts of the conference were the spaces between sessions. I had another very worthwhile discussion with Adam Frisby of OpenSim about C# script compatibility between OpenSim and Second Life. The straw man design we talked about was to have an idiomatic .NET interface for event handling that can be used by C# scripts and adapted for LSL scripts and a set of static library methods for manipulating the world that would be used directly by LSL scripts and wrapped by user created libraries to provide an idiomatic object oriented interface. Adam was particularly interested in the idea of user created wrapper libraries as it would allow the creation of an OpenSim interface library that could be ported to Second Life and implemented in terms of the ll* static methods. OpenSim could then agree to support the common behaviour of this library in Second Life and OpenSim instead of having to support the gamut of ll* methods some of which don’t map well to OpenSim internals. As well as defining a common set of events and ll* static methods that are supported on both platforms there would need to be a way of extending the interface with new events and library methods. In addition Adam was interested in making the event propogation configurable so that a single script could respond to events on many objects in a scene. This would effectively add a script interest management layer to OpenSim’s scripting interface. Where platforms provide differing interfaces to scripts we would also need to decide how scripts query the available interfaces or how they behave when interfaces are not available.
Overall a worthwhile trip, but not because of the conference. This Friday I’ll be talking at the online head conference about conferencing in Second Life which has the advantage of requiring no travel making marginal conferences like the Virtual Worlds Conference less risky to attend while allowing all of the serendipitous networking opportunities that make real life conferences worthwhile.

Last week I was invited to talk at JAOO Denmark. Originally a Java conference, JAOO is now a very broad software development conference covering everything from agile to language design to distributed systems.
The stand out talk on the first day was Gregor Hohpe‘s Programming the Cloud which enumerated some of the problems with building distributed systems without call stacks, transactions, promises, certainty or ordering constraints and then outlined some approaches to overcome them including looking at real life situations which also have to deal with the lack of distributed transactions. For example at Starbucks your coffee is made concurrently with your payment being taken and then problems are fixed up afterwards if you can’t pay, they can’t make the coffee or they get the order wrong. The throughput gained from optimistic concurrency is greater than the loss of having to fix things up, even if it means that sometimes you end up giving away free coffee.
Unfortunately I missed Lars Bak’s V8 keynote on Tuesday, but was really impressed by Successfully Applying REST by Stefan Tilkov which enumerated REST patterns and anti-patterns shining some light on the subtleties of a technology which initially seems straight forward but turns out to have some pot holes for the unwary.
The highlights on Wednesday were seeing Guy Steele and Dick Gabriel give their 50-in-50 talk again (which is still not available on-line, but one of the highlights is here) and seeing the new WeDo lego robotics platform for kids which will be available next summer. The most relevant talk was Test Driven Development, Take 2 by Erik Doernenburg which got me thinking about how to do dynamic mock objects in C++. My talk on embedding Mono in Second Life went down well and elicited some good questions, although as a fringe topic it wasn’t heavily attended.
Other highlights included Erik Meijer’s keynote on fundamentalist functional programming, Bill Venners talk on Scala, hearing Patrick Linskey conclude that the way to make Java scale is to use Scala or Erlang, James Copland reinventing OO, playing guitar at the jam session and hearing Erik suggest to Lars that we compile LSL to CIL and run it on V8 modified to capture thread state while Erik was spilling half bottles of Champagne over people and Lars was swaying and stumbling around the room.