Using JAVA and Javascript in MAX - what is the benefit?
Lately I have been exploring the area of using Javascript and Java within MAX and I personally think it is a great combination to use MAX objects combined with program logic written in e.g javascript.
(I also use Ableton Live and really like the fact that the Live API is available in Javascript).
However today I was confronted with the question: "Why do you need to use javascript and java in MAX MSP?" My response was then that javascript and Java makes it easier to implement complex logic in that I can use datatypes and arrays etc. However thinking about it I know Java and Javascript from the past and I am then wondering if it is only my lack of indepth MAX knowledge that make me prefer using java/javascript?? Could I implement most of the logic I need using pure MAX?
If you have any suggestions on pros/cons using java/js-script code in MAX MSP please let me know so that I can provide a better and unbiased response to the person who asked me the question.
Max is a graphical programming language, java/javascript is a text programming language. Both have their strengths. There are things that you can implement in Max that are easier than javascript and vice versa.
But I would say that in general, augmenting Max patching with java script saves you a lot of time. There are certain things that are hands down easier in javascript, regardless of how well you know Max.
Why not have the best of both worlds.
I would say the real debate would be, should one be satisfied with javascript or is there a real justification for the added complexity of the java route?
"logic" is probably something which can be done in max just fine.
but when it comes to working with long lists, with databases, or with things like file in / out there are probably nicer solutions with java.
i have no clue about java so i am better at finding arguments against the use of java inside max. one of them is that java often needs more CPU. the jsui examples showx that very well, tons of processing power wasted for effects, which are almost of no use, and which almost could have be coded for [lcd] as well.
another issue is that the more 3rd party extras you use with max, the more difficult it gets to upgrade, downgrade, crossgrade your applications to make them work with any max/msp runtime, on all platforms.
so dont be afraid that the fact you know java better than max would not let you see the pros and cons. it is for sure a reasonable argument why and when to use java in max!
-110
like many things, it's a question of balance.
writing complex logic in js/Java is more natural for me (being a programmer) so I tend to drop into those when needed, though at the moment the stuff I'm working on is majority js as it's quite a large system that is more of a low-level control system rather than a highly interactive gui system.
js and Java will both do number crunching faster than MAX (java faster than js), but MAX has some really powerful stuff built in which shouldn't be overlooked, so a hybrid is often the best case.
the downsides to JS are that it runs in the low priority thread and can be interrupted by gui updates (as well as anything else running in the env) and is not suitable if you need accurate timing 100% of the time. java doesn't have this limitation so is more suitable for time critical stuff.
both of these incur a small cost from crossing the boundary from MAX into js/java and back again, and although this is negligable (again cost of going into js is more than java), both are suited more to doing larger amounts of work for fewer calls rather than lots of calls for a smaller amount of work (just to reiterate here though, you're only going to start noticing this realistically if you are doing 10s of thousands of calls per second)
one other consideration is that both js/java rely on a garbage collection system that can kick in unpredictably at any time - probably not even a real consideration on setups these days where people have 8G of memory, but will be more noticeable on lower spec systems with 2G.
so, as with most things, there's always a trade off.... right tool for the right job...
Well, both JavaScript and Java were originally attempts to avoid the complexity of compiling in C when performance was not an issue, and interpretive or virtual machine overhead was acceptable. Over time, they've both got pretty much as complicated.
Thanks for the input on this thread. I believe the replies were very helpful and in line with my understanding of pros/cons - thanks!