Coderpad logo color Features Pricing Login Register

Languages

CoderPad supports a wide variety of programming languages. Some of them have quirks and quite a few have supplementary libraries that you might want to use. Click on the language you're interested in, or scroll through the list!

C

Running GCC 5.4

The gcc compiler is invoked with the following args:

gcc -std=c14 -Wall -pthread -lm

Which stand for:

You should define an int main() entrypoint.

Clojure

Running Clojure 1.8

No extra information available. It probably just works!

CoffeeScript

Running CoffeeScript 1.10

CoffeeScript in CoderPad just runs on top of the JavaScript environment, the only difference being that we do not run CoffeeScript with the --harmony flag.

Information about the JS environment is reproduced below:

We provide a highly interactive REPL with allows access to your runtime variables. If there were no errors, you will have a REPL with access to all of the global variables and functions defined in your script.

We run NodeJS with the --harmony flag on, which gives you access to most of the features in the upcoming JavaScript ES6 spec. For a complete description of which ES6 features are available, check out the Node compatibility table. Your code is also run for you in strict mode by default, which will enable most ES6 features to work without configuration on your part.

We also have an array of interesting npm packages available for your use:

C++

Running GCC 5.4

Boost is provided, with most of its header-only libraries working straight out of the box. Of its statically compiled components, we link to DateTime, Regex, System, Thread, and Timer. If you need more than those, please let us know!

The gcc compiler is invoked with the following args:

g++ -Wall -std=c++14 -pthread \
-lboost_date_time -lboost_regex -lboost_system -lboost_thread -lboost_timer -lboost_filesystem

Which stand for:

You have access to the STL libraries as long as using namespace std; is present.

You should define an int main() entrypoint.

If you’d like to write some tests against your code, you can do so using the Catch C++ testing library. Catch is a single-header library and very easy to get started with. To use it on CoderPad, simply define a macro and include the header like so:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

unsigned int Factorial( unsigned int number ) {
    return number <= 1 ? number : Factorial(number-1)*number;
}

TEST_CASE( "Factorials are computed", "[factorial]" ) {
    REQUIRE( Factorial(1) == 1 );
    REQUIRE( Factorial(2) == 2 );
    REQUIRE( Factorial(3) == 6 );
    REQUIRE( Factorial(10) == 3628800 );
}

If you do so, you should not define your own main method. You can also read more about Catch’s macros for testing.

C#

Running Mono 4.6

Our C# environment runs on top of the venerable mono project’s implementation of the .NET runtime. Microsoft recently announced the eventual merging of the .NET core and Mono, so we’re in pretty good hands there.

You should define a static void Main on a class named Solution.

Your code is compiled and run with debug mode enabled.

Erlang

Running Erlang OTP 19.0

You should define the module as “solution” and define and export a method named “start” on it, like so:

-module(solution).
-export([start/0]).

start() ->
  io:format("Hello, World").

F#

Running Mono 4.6

Our F# environment runs on top of the venerable mono project’s implementation of the .NET runtime.

Your code is compiled and run with debug mode enabled.

Go

Running Go 1.7

You should declare a func main() in a package “main”, like so:

package main

import "fmt"

func main() {
  fmt.Println("Hello, world")
}

Haskell

Running GHC 8.0

Your code is run with runghc solution.hs. Your code runs in interpreted mode, so you don’t need a special entrypoint or anything.

The following packages are installed and their modules are available for importing:

bytestring, hashtables, parsec, split, text, unordered-containers, vector, and vector-algorithms

Java

Running HotSpot 1.8.0_91 (JDK 8)

You should define a public class named Solution with a public static void main. Your code is compiled with -Xlint (linting) and run with -ea (assertions enabled).

A few libraries are included for your convenience, and are available on the classpath with no additional work from you. Simply import and fire away:

JavaScript

Running NodeJS v6

We provide a highly interactive REPL with allows access to your runtime variables. If there were no errors, you will have a REPL with access to all of the global variables and functions defined in your script.

We run NodeJS with the --harmony flag on, which gives you access to most of the features in the upcoming JavaScript ES6 spec. For a complete description of which ES6 features are available, check out the Node compatibility table. Your code is also run for you in strict mode by default, which will enable most ES6 features to work without configuration on your part.

We also have an array of interesting npm packages available for your use:

Markdown

Running marked.js 0.3

No extra information available. It probably just works!

MySQL

Running MySQL Server 5.5

MySQL mode spins up a MySQL server with a default database with some sample data in it. The schema of the default database looks like:

employees                             projects
+---------------+---------+           +---------------+---------+
| id            | int     |<----+  +->| id            | int     |
| first_name    | varchar |     |  |  | title         | varchar |
| last_name     | varchar |     |  |  | start_date    | date    |
| salary        | int     |     |  |  | end_date      | date    |
| department_id | int     |--+  |  |  | budget        | int     |
+---------------+---------+  |  |  |  +---------------+---------+
                             |  |  |
departments                  |  |  |  employees_projects
+---------------+---------+  |  |  |  +---------------+---------+
| id            | int     |<-+  |  +--| project_id    | int     |
| name          | varchar |     +-----| employee_id   | int     |
+---------------+---------+           +---------------+---------+

The database is reset between every “Run”, so if you want to add custom data to the database, please write some INSERTs at the start of your pad. That way, that data will be inserted on every run.

Objective-C

Running Clang 3.6 with GNUstep and libobjc2

While we don’t run Objective-C on native OSX, we do run it in the latest clang with objc. This lets you include classes like NSString and so forth largely as you normally would.

Your code is compiled with

clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` \
  -fobjc-arc -fobjc-nonfragile-abi -lobjc -lgnustep-base

Which activates automatic reference counting and the nonfragile ABI.

You should define an int main() function.

Perl

Running Perl 5.18

No extra information available. It probably just works!

PHP

Running Zend PHP 7.0

You must wrap your code in <?php and ?> tags. Text outside of those tags will output to stdout without processing as PHP.

PHP’s mcrypt library is also installed.

Python

Running CPython 2.7

The Python environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses IPython to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for importing are:

Testing

We’ve got a few ways you can test your Python code in CoderPad:

  1. The excellent unittest library that ships with Python by default. Here’s a quick example:

    import unittest
    
    class TestStringMethods(unittest.TestCase):
        def test_upper(self):
            self.assertEqual('foo'.upper(), 'FOO')
    
        def test_isupper(self):
            self.assertTrue('FOO'.isupper())
            self.assertFalse('Foo'.isupper())
    
        def test_split(self):
            s = 'hello world'
            self.assertEqual(s.split(), ['hello', 'world'])
            # s.split should throw when the separator is not a string
            with self.assertRaises(TypeError):
                s.split(2)
    
    unittest.main(exit=False)
    
  2. The versatile pytest. The above snippet of code would look like the following when written for pytest:

    import pytest
    
    def test_upper():
        assert 'foo'.upper() == 'FOO'
    
    def test_isupper():
        assert 'FOO'.isupper()
        assert not 'Foo'.isupper()
    
    def test_split():
        s = 'hello world'
        assert s.split() == ['hello', 'world']
        # s.split should throw when the separator is not a string
        with pytest.raises(TypeError):
            s.split(2)
    
    pytest.main()
    
  3. mock is also available if you need to stub out some behavior. Here’s a quick usage example:

    from mock import Mock
    
    mock = Mock()
    mock.method(1, 2, 3)
    mock.method.assert_called_with('this should break')
    

    mock can of course be combined with unittest and pytest for even more fun.

Python 3

Running CPython 3.4

Python 3 in CoderPad is generally identical to the Python 2.x environment.

One small difference is that mock is available in Python 3 in the stdlib, as unittest.mock.

Information about the Python 2.x environment is reproduced below:

The Python environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses IPython to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for importing are:

Testing

We’ve got a few ways you can test your Python code in CoderPad:

  1. The excellent unittest library that ships with Python by default. Here’s a quick example:

    import unittest
    
    class TestStringMethods(unittest.TestCase):
        def test_upper(self):
            self.assertEqual('foo'.upper(), 'FOO')
    
        def test_isupper(self):
            self.assertTrue('FOO'.isupper())
            self.assertFalse('Foo'.isupper())
    
        def test_split(self):
            s = 'hello world'
            self.assertEqual(s.split(), ['hello', 'world'])
            # s.split should throw when the separator is not a string
            with self.assertRaises(TypeError):
                s.split(2)
    
    unittest.main(exit=False)
    
  2. The versatile pytest. The above snippet of code would look like the following when written for pytest:

    import pytest
    
    def test_upper():
        assert 'foo'.upper() == 'FOO'
    
    def test_isupper():
        assert 'FOO'.isupper()
        assert not 'Foo'.isupper()
    
    def test_split():
        s = 'hello world'
        assert s.split() == ['hello', 'world']
        # s.split should throw when the separator is not a string
        with pytest.raises(TypeError):
            s.split(2)
    
    pytest.main()
    
  3. mock is also available if you need to stub out some behavior. Here’s a quick usage example:

    from mock import Mock
    
    mock = Mock()
    mock.method(1, 2, 3)
    mock.method.assert_called_with('this should break')
    

    mock can of course be combined with unittest and pytest for even more fun.

R

Running R 3.2

Our R environment ships with the data.table, dplyr, forecast, plyr, reshape2, tidyr, xts, and zoo packages installed. No graphical output is provided at this time, but all your standard R computations should work normally.

Ruby

Running MRI 2.3

The Ruby environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses Pry to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for requireing are:

Rust

Running Rust 1.14

No extra information available. It probably just works!

Scala

Running Scala 2.11

You should define an object named Solution that extends App, like so:

object Solution extends App {
  for (i <- 0 until 5) println("Hello, world!")
}

Alternatively, you can forego using the App trait helper and define main yourself:

object Solution {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}

We include the Scala testing libraries ScalaCheck and ScalaTest for your convenience. Here’s a quick example of ussing ScalaTest driven by ScalaCheck generators:

import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FreeSpec, Matchers}

class Testable extends FreeSpec
    with Matchers
    with GeneratorDrivenPropertyChecks {

  def f (x: Int) = Math abs x

  "f (x) should be >= 0" in forAll (
    (x: Int) => f (x) should be >= 0
  )

  "f (x) should be >= 0 (sometimes!)" in forAll (
    (x: Int) => whenever (x != Int.MinValue) (f (x) should be >= 0)
  )
}

object Solution extends App {
  new Testable().execute
}

Additionally, these Java libraries are available. Simply import and fire away:

Swift

Running Swift 3

We’re using Apple’s recently open sourced Swift implementation, on a recent Linux snapshot.

Syntax highlighting might be a bit wonky, so please point out any issues via email! We also plan to add REPL support soon.

Visual Basic

Running Mono 4.6

Our Visual Basic environment runs on top of the venerable mono project’s implementation of the .NET runtime. However, the Mono project’s support for VB is currently a bit lacking. It currently supports something equivalent to about VB.NET 2.5, but hopefully will improve soon.

Your code is compiled and run with debug mode enabled.

Are there any libraries or settings I missed? Feel free to email me with suggestions!