# For Code Golf, how do you deal with languages without a traditional print/echo statements? [duplicate]

JavaScript comes to mind as a language without a traditional outputting mechanism.

In this instance, document.write() is suggested, but its specific to the browser, not to the JavaScript/ECMAScript language (in addition to being verbose).

Obviously, this matters, since with CodeGolf, every character 'counts'.

So, how can these instances be handled fairly?

• Related question: meta.codegolf.stackexchange.com/questions/13/… – Nakilon Jan 28 '11 at 1:56
• Use alert for output and prompt for input ? – HoLyVieR Jan 28 '11 at 17:29
• @HoLyVieR Clever idea, though those are also browser specific functions, and not native to the language. – Yahel Jan 28 '11 at 18:36
• On spidermonkey (JS), I think there's print and readline. – Nabb Feb 3 '11 at 2:43
• Well, Burlesque does not have a print statement. It has no access to any I/O (except stdin already lies on the stack). For golfing it is assumed, that the stack is printed to stdout at program termination. (That is, a Burlesque program CAN'T produce any output until it terminates.) – mroman Sep 7 '13 at 11:22

I think you should treat a challenge almost the same as a task or project your boss wants you to work on.

If the language you want to use to solve this task isn't appropriate, I suppose you won't ask your boss to adjust the project, to fit to your preferred programming language.
Instead, you'll choose an appropriate language, to solve the problem fast and elegant.

The other possibility, much easier on Codegolf.SE than explaining to your boss, would be to accept the challenge, deal with the pitfalls of your preferred language, and perhaps come up with a solution you never thougt about before, just to compensate some weird input/output mechanisms.

So, as long as the problem doesn't specify the language it wants to be solved in, it's your choice.

• Indeed yes. In the 8086 emulator I switched back and forth between terminal output and graphical output. Not a golf per se, but I tried to be terse. If you can access a bitmapped alphabet with a short url, you cat blit letters to an image and show that (makes it sound easy hoping no one asks any questions :) – luser droog Jan 29 '13 at 9:11

Some CodeGolf questions are about completing a full program - usually with specified input and output formatting. For such challenges, I'd say that JavaScript, or, say, SQL, would be inappropriate langauges.

On the other hand, some CodeGolf questions are about creating a function that performs the operation, and the input and output are left to be what ever is "natural" in the given language. For these, JavaScript will be fine.

Now - If someone defined a CodeGolf that was to create an HTML document... I suppose creating via the DOM would be just peachy!

• T-SQL has PRINT, at least ;-) – Joey Jan 28 '11 at 8:11