Friday, 7 May 2010

Online compiler/interpreter/IDE


I had been using www.codepad.org whenever I wanted to run a piece of code and didn't have the required compiler/interpreter in the system I was using. But the main disadvantage with this was that you cannot read input from the user while using this site - scanf(), cin, <STDIN>, etc. (in C, C++, Perl respectively) are promptly ignored. This was often an irritation since I'd have to modify my program to not take an input before testing there, which might not be an easy process (especially given complex data structures).

Today, I came across http://ideone.com, which is very similar to the above, except that it allows providing input to the program! Yay! You type (or paste) the program in a text area as in codepad, choose your language from the list, and then click on "click here to paste input (stdin) or additional note". Whatever you type here becomes the input to your program. That's a neat solution to the problem of providing input to remotely-evaluated programs.
And it supports "more than 40 languages", including Assembler, Common Lisp, and even Whitespace (of course the boring old C, C++, Java, Perl, Python, etc. are there too). It has other goodies like syntax highlighting for all these languages, 'private' pasting for times when you don't want others to see the code, etc. The site is quite very well done.

While we're in the topic, let me also add two more online code evaluation tools (compilers/interpreters):

* Lord of the REPLs: This is a Read-Eval-Print-Loop from Google, where each line you enter is evaluated immediately. Despite the fancy "Lord" name and the Google brand, I haven't found this very useful mainly because: it doesn't preserve function definitions or variables' values after you evaluate them, unlike other REPLs. This makes it hard to run anything more than trivial "hello world" programs. Also, I found it quite buggy at times.

* "Compile & Execute": This is somewhat similar to ideone, allowing you to enter your own input and having a choice of a similar number of languages. However, it doesn't have a 'private' pasting option, and has syntax highlighting for only a few languages. This leads to weird highlighting at times: if you choose to paste Perl code, the Highlight choice remains in cpp (which is the default), so your Perl code gets highlighted as C++ code! Sloppy design like this makes me think this site might not be very well designed.

These two are the only generic code evaluation tools I could find. If you find that none of these do it for you, try googling for something specific to your language. For example, for Python, searching for 'python online (IDE OR compiler OR interpreter)' gives a lot of good results.

If you know some other online code evaluation tool, or have experience with any of the above, do share it in the comments. Thanks!