Thanks for your comments everyone. I'll stick with return.
On 13/04/12 22:12, Petr Bena wrote:
I have no knowledge of Lua, but I don't see what is problem with print here, the function print is supposed to print output to output device in most of programming languages, just as in this case, so I don't understand why we should want to use return [...]
Platonides' response hints at the answer:
On 14/04/12 02:31, Platonides wrote:
I'd also prefer return values. Fits better with wikitext in general.
Most programming environments allow progressive output. You can call print, do some processing for a few seconds, ask for some user input on stdin, then do another print. When we embed a script in wikitext, its output is required to be fully buffered. So the advantages of allowing print are substantially less.
There are disadvantages: it is more difficult to identify the data flow when you use print(), as several people have said.
MediaWiki has $wgOut->addHTML() which is kind of like print(), despite being in a fully buffered environment, but its effect is consistent. By contrast, the output from a parser function can be modified by other parser functions and templates.
On 13/04/12 22:33, Happy Melon wrote:
Having a print() function would be very useful for debugging; you could turn 'debug mode' on on sandbox pages with an input arg (I assume #invoke and friends can take arguments?) and something like {{#invoke:MyModule|MyFunction|debug={{#ifeq:{{SUBPAGENAME}}|Sandbox|true|false}}}}, and output debugging data with more flexibility if you had a second channel for printing.
I think it's probably best if we have separate support for debug messages -- something that can be used without changing the output. Maybe an mw.log() function like we have in JavaScript.
-- Tim Starling