Quartz Composer Javascript debugging

cybero's picture

I've been receiving a fair old number of requests for further information upon debugging Quartz Composer Javascript and shall be publishing my current state of understanding on this issue in greater depth upon my site.

Apart from the log() function, Quartz Composer JavaScript does not really have much else going for it code proofing wise apart form the obvious - code colouring when syntax is good, syntax error when bad, nil noodle outputs if code syntax is good but code content is amiss nonetheless.

If I can't get an output noodle then I know something is amiss with my coding in the JavaScript patch, that and code colouring tends to be the extent of my 'debugging' of Quartz Composer JavaScript, wherein JS is just that little bit different from the norm ref browser oriented JS.

As follows.

In brief :-

IE8, Mozilla [Venkmann or Firebug], Safari Web Inspector, Dashcode all provide debugging facilities for JavaScript but really only look for what syntax and semantics are supported within their particular JS version engine. Using them will greatly improve one's coding and help to build solid code cross platform and cross browser. They all universally micturate upon QC's chips even when set to their most forgiving, fudgy tolerant profiles.

So long as one remembers that what the debuggers effectively reinforce layout, syntax and semantics wise will, for the most part make very little difference to QC, within which JS that just won't even get off the tracks in most browsers will run AOK, then the reinforcement of good web JS coding habits might simply help to eventually sharpen one's use of QC's slightly variant JS.

Quartz Composer JavaScript really would benefit from a QC oriented JS debugger IMHO.

I may be wrong , but it seems to me that properly effective use of dtrace requires that one recompiles QC from source to include dstrace .js scripts , or Apple beefs up the debug facilities within the QC editor, or provides a set of appropriate QC focussed templates for Instruments / dtrace otherwise simply re-adjusting our prior JS knowledge to work, albeit sans as many semi colons, named functions, etc that other pedantic browser oriented JS debuggers correctly require is the best way to for now.

YMMV :-)

Any other options on this front, anyone know ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

toneburst's picture
Re: Quartz Composer Javascript debugging

I'd agree- QC would really benefit from more debugging options (breakpoints, for example, or even just a simple equivalent to ActionScript/Lingo's 'trace()' function).

Having said that, I'm not clear how this would fit in with Quartz Composer's whole per-frame-execution paradigm.

My feeling though, is that, while these tools would be useful, I'm probably becoming a better programmer for the hours of hair-tearing. At least, that's what I tell myself... ;)

a|x

cybero's picture
Re: Quartz Composer Javascript debugging

Quote:

My feeling though, is that, while these tools would be useful, I'm probably becoming a better programmer for the hours of hair-tearing. At least, that's what I tell myself... ;)

Quite agree toneburst, although the various requests for assistance that I've received, in this regard, have prompted me to look elsewhere.

I have previously made reference to the use of browser based debuggers, with the caveat that they are , surprise, surprise, browser and DOM oriented.

It seems to me that the QC JS model is likely to be a slightly simplified, possibly even bespoke simplified version of SquirrelFish, the JS engine for WebKit browsers. I think that I'll need to look at simplifying and recompiling that particular debugger, if possible.

Although I'll freely admit that this is not a top priority QC wise with me, it will be receiving regular attention from hereon in.

Will keep all posted. In the meantime, my QC JS site priority will be to place some good flesh on the bone examples up on that site. They might well help to put JS in QC more into context.

toneburst's picture
Re: Quartz Composer Javascript debugging

Quote:
It seems to me that the QC JS model is likely to be a slightly simplified, possibly even bespoke simplified version of SquirrelFish, the JS engine for WebKit browsers

That was the impression I got, too, from what cwright said the other day.

To be honest, I haven't really found anything major QCs JS implementation can't do. Apart from the obvious browser-specific DOM stuff, as you say, it seems to be able to do pretty-much all the standard JavaScript things.

Having said that, I did discover a possible bug when using object methods last week. It's not a killer though, just a bit inconvenient.

a|x

usefuldesign.au's picture
Re: Quartz Composer Javascript debugging

Quote:
Having said that, I did discover a possible bug when using object methods last week. It's not a killer though, just a bit inconvenient.

Could anybody post a reference for object methods applicable to QCStructures?

I was trying things like:

pointCount = 3DpointData.length

and getting nowhere, resorted to the structure count patch and inputted the result to JS patch (tragic workaround of the month!).

Also looking for a way to coerce a input-Structure (from node) to an Array type of object.

toneburst's picture
Re: Quartz Composer Javascript debugging

Quote:
Also looking for a way to coerce a input-Structure (from node) to an Array type of object

Dunno about the first question, but I've resorted to looping through the contents of an input __structure assigning each item to an array in the past. I'd also love to know if there's a better method. This isn't necessarily as horrendous as it could be. Lazy-evaluation should mean that it won't have to be done again until the input changes, provided you create the array outside the main program loop, so it's persistent.

This whole thing about JS standard arrays and objects on the one hand, and QC __structure datatypes on the other, is a bit confusing to me. They seem functionally interchangeable in some ways, but I don't know what's the most efficient way of using them.

a|x

cwright's picture
Re: Quartz Composer Javascript debugging

structure.length works -- you have to make sure the structure isn't null first though (it's always null the first time around)

For example:

var result = new Object();
function (__string stuff) main (__structure files)
{
   if(files)
      result.stuff = "length:" + files.length;
   return result;
}

will work just fine.

Regarding implementation: It uses WebKit's javascript engine. everything available in safari is available in QC (the big exception is that, as everyone says, the DOM stuff isn't configured, so you can't do document.write etc, because the document object doesn't exist -- this isn't a functionality thing, it's an environment thing).

cwright's picture
Re: Quartz Composer Javascript debugging

what's wrong with just using the structure /as/ an array?

var result = new Object();
function (__string stuff) main (__structure files)
{
   if(files)
      result.stuff = files[0].url;
   return result;
}

works just fine (directory scanner -> javascript -> imageWithString->sprite)

toneburst's picture
Re: Quartz Composer Javascript debugging

Ah, good point about __structure inputs being null on the testrun. I'd forgotten about that. I tend to stick everything in my JS inside

if(!_testMode)
{
   // code..
}

..which seems to do the trick. It's not strictly needed unless __structure inputs are being used though, I think.

You can also do initialization stuff on the pre-run, too

if(_testMode)
{
   // init code
} else {
   // rest of code
}

a|x

usefuldesign.au's picture
Re: Quartz Composer Javascript debugging

I always wondered why that if(!_testmode) was there for it your JS but was too afraid to ask. <joking> Thought it was to do with debug mode. Where did you learn that trick?

Null set must have been it. I'll go try. THX

toneburst's picture
Re: Quartz Composer Javascript debugging

usefuldesign.au wrote:
Where did you learn that trick?

Can't remember. Think it might be in the Apple documentation, in fact, though I think I first saw it used in anger (as it were), in some code Memo knocked together a while back.

a|x

usefuldesign.au's picture
Re: Quartz Composer Javascript debugging

Quote:
what's wrong with just using the structure /as/ an array?

Can array methods be applied to a structure (should just try it first I know but don't trust my error checking yet)?

ie

3DData.sort

n = 3DData.concat (newstuff)

etc

Guess there is no speed differences b/w the types inside JS patch as previous points by cwright on how structures/arrays are treated by QC suggests its expensive any old way.

usefuldesign.au's picture
Re: Quartz Composer Javascript debugging

Been using Safari 4 Public Beta (fast). Wondering whether to download 4 and found new debugging tools are listed and even an SQL Database interface. Cybero may have mentioned this under Safari Web Inspector but profiling looks interesting.

From apple.com:
JavaScript Debugger
The Scripts pane features the powerful JavaScript Debugger in Safari 4. To use it, choose the Scripts pane in the Web Inspector and click Enable Debugging. The debugger cycles through your page’s JavaScript, stopping when it encounters exceptions or erroneous syntax. The Scripts pane also lets you pause the JavaScript, set breakpoints, and evaluate local variables.

JavaScript Profiler
Optimize your JavaScript code using the state-of-the-art JavaScript Profiler in Safari 4. The Profiler lists the performance characteristics of each of your script’s functions, making it easy to pinpoint problem areas and drill down to the offending lines of code.

Databases
Safari is the only browser that includes tools for managing the offline databases that will be part of the next generation of websites. The Databases pane in Safari 4 allows you to view tables and databases and even execute SQL queries.

Resources
The Resources pane graphs the order and speed at which website components load over the network…

Could be worth the cost of a download...

toneburst's picture
Re: Quartz Composer Javascript debugging

That looks promising... Think I'll scrape by without it though.

a|x

cybero's picture
Re: Quartz Composer Javascript debugging

Safari's Inspector is truly brilliant for web designing and development.

However, any really helpful mileage is probably going to come by utilising a deliberately stripped down version of the SquirrelFish WebKit engine bespoked for QC syntax, or by revealing and incorporating the actual Core Class JS API QC uses.

Safari loves this kind of syntax

function calc_sales(units_a, units_b, units_c) {
   return units_a*79 + units_b * 129 + units_c * 699;
}

whilst QC abhors it - incorrect or missing main function :-)

QC loves

function (__number outputNumber) main (__number inputNumber[2])
{
   var result = new Object();
   result.outputNumber = inputNumber[0] + inputNumber[1];
   return result;
}

whilst Safari pours scorn; it's [almost] all a matter of syntax.

cwright's picture
Re: Quartz Composer Javascript debugging

The syntax is almost entirely identical, with the sole exception being the (__number outputNumber) block before the main function. That block's required so QC knows how many output ports to create, and what type to make them.

Otherwise, it's not "stripped down" any -- the Math object is full-featured, arrays and objects (and their associated functions) are present. the only "missing" piece is the "document" object, which wouldn't serve any purpose in QC.

What other differences are there?

usefuldesign.au's picture
Re: Quartz Composer Javascript debugging

For me, as someone just getting their coding brain back together after decades of neglect, access to variable states (properties) during a debug would definitely save bundles of time.

Often I'm finding the errors in my code are a variable misspelling or mis-substitution. The other major error is mishandling the object heirarchy when I want one structure inside or concat with another. Debug should help here too giving instant feed back of what values are being passed without haveing to create lots of outputs ie result.debug = tellMeSomething

Debuggers should be good for this even in a language that doesn't police declarations no?

If I like Safari debugging I'll try squirrel fish. Function headers can be easily modified back to QC syntax on completion of code.

usefuldesign.au's picture
Re: Quartz Composer Javascript debugging

I was pointed out to me at some point by bbinkovitz (I think) that not using the test method of

if (!_testMode)
{
   …
}

results in a null value error on structure functioins involving input nodes because on the first run through of the code (pre-parsing?) the input values are not assigned to the variables. This is probably why I was getting that error, I still make this error occasionally.