REALbasic Computed Properties Debugging Gotcha

I’ve been doing a huge amount of work recently porting the C++ OOFILE report writer to REALbasic as a complete transliteration, having given up on the earlier report-writer I was writing from scratch.

I’m using REALbasic 2008r4.1 and finding it extremely flaky when debugging. I finally worked out the cause and it’s an interesting trap.

OOFILE was written about 15 – 10 years ago and makes use of lots of inline and non-virtual functions for high-performance in C++. Methods in REALbasic are, of course, all virtual but it also has Computed Properties which allow you to write code as getter and setter functions. These are non-virtual and therefore (presumably) much faster – an ideal and idiomatic match for the inline getters and setters used heavily in OOFILE.

However, there’s one very big gotcha – if you look at an object in the REALbasic debugger, all its getters on computed properties are executed.

Apart from the performance overhead of this, I had a number of state-dependent checks in my getter code which caused (homegrown) assertions to fire, whilst the poor debugger was trying to display values. In the original context, these were perfectly safe, in fact added safety by ensuring that complex object initialisation was completed before the object query methods were called.

// user enquiry ONLY expected to be called
// after finishConstruction
assert mKeepTogether <> keepTogetherT.eDefaultTogether
return (mKeepTogether = keepTogetherT.eKeepTogether)

Even worse was properties that do lazy initialisation so they only allocated the members they get when they are first called, which means they are trying to change other properties in the object at the time it is being shown in the debugger, eg:

if mPageFooters is nil then mPageFooters = new rbrwBandList
return mPageFooters

These obviously need rewriting and hopefully Real Software can be convinced to add a Don’t Compute Properties in Debugger option soon!

One thought on “REALbasic Computed Properties Debugging Gotcha

  1. There has been a good discussion on the mailing list and some feedback from Mars on the forum http://forums.realsoftware.com/viewtopic.php?f=1&t=24815 which has helped me come up with the real problem – the issue is a bug that Dan Stenning reported on 2008r3.1 where SHARED COMPUTED PROPERTIES cause the crash. I’m not 100% convinced that is the sole cause but have not been able to replicate the problem in a sample program. The sample DOES show shared computed properties crashing the debugger – http://www.aussiedesignedsoftware.com/files/TestComputedPropertiesCrashingDebugger.rbp.zip

Comments are closed.