Tools for code snippet execution
Asked Answered
H

6

11

By "code snippet execution", I mean the ability to write a few lines of code, run and test it without having to fire up an IDE and create a dummy project.

It's incredibly useful for helping people with a small code sample without creating a project, compiling everything cleanly, sending them the code snippet and deleting the project.

I'm not asking about the best code snippets or a snippet editor or where to store snippets!

For C#, I use Snippet Compiler.

For Java, I use Eclipse Scrapbook.

For LINQ, I use LINQPad.

Any suggestions for other (better?) tools? e.g. is there one for Java that doesn't involve firing up Eclipse?

What about C?

Higbee answered 5/11, 2008 at 0:32 Comment(1)
related: Are there any good online IDEs?Citified
S
3

For C, the in-browser http://codepad.org/ is truly excellent. Executes code and everything.

Sileas answered 5/11, 2008 at 1:35 Comment(0)
A
4

Try ideone. It is able to run your code on server side in more than 40 programming languages including C and Java (it is free for individual usage).

Andromeda answered 28/12, 2010 at 13:49 Comment(0)
S
3

For C, the in-browser http://codepad.org/ is truly excellent. Executes code and everything.

Sileas answered 5/11, 2008 at 1:35 Comment(0)
E
1

For executing JavaScript snippets I use most Firebug and Google Chrome JavaScript console.

For F# I use the Interactive Console.

Ezzell answered 5/11, 2008 at 1:1 Comment(0)
T
1

I sometimes want to try something very short just to confirm semantics. Since creating a temporary file and putting in the boilerplate takes more than 30 seconds, I have this script:

#!/bin/sh

body="$1"
out=$(mktemp /tmp/ccrun-XXXXXX)
src=${out}.c
cat > ${src} <<EOF
#include <limits.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define UNUSED __attribute__((unused))

int main(int UNUSED argc,char UNUSED *argv[])
{
EOF
echo "$body" >> ${src}
echo -e "return 0;\n}" >> ${src}
cc -std=c99 -Wall -Wextra ${CCRUN_FLAGS} -o ${out} ${src} -lm
shift
echo ${out} "$@"
${out} "$@"
#rm ${out} ${src}

A sample invocation (this code statically initializes an array of function pointers) looks like:

$ ccrun 'int f(int a){return a+1;} int g(int a){return a+2;} int (*farr[2])(int) = {f,g}; for (int i=0; i<2; i++) printf("%d %d\n",i,farr[i](i));'
/tmp/ccrun-6nT4Wo
0 1
1 3

If I want to make little changes, I just edit the command line. If it becomes unwieldy on the command line, I'll edit the temporary file, in this case /tmp/ccrun-6nT4Wo.c. Command line arguments to the executable can be given after the program (first argument). The executable is left in place so it can be run without recompiling. You can do something similar for any language.

Traitorous answered 9/11, 2008 at 20:24 Comment(0)
G
0

In Ruby you can use the Interactive Ruby Shell.

It also looks like the guru's at the mono project have gone and made a C# interactive. YAY

Gawen answered 5/11, 2008 at 9:16 Comment(0)
S
0

For Python and Sage, try out http://live.codenode.org. It is also an open source project, licensed under the BSD, so it can be downloaded and ran from your own computer, more info is here: http://codenode.org

Season answered 12/10, 2009 at 4:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.