This post is really just here to have a bunch of syntax highlighting stuff in one place. IGNORE ME! (unless you just want to see some pretty colored code blocks, in which case read on).
JavaScript
function getRandomNumber() {
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
Scala
case class Person(name: String, age: Int)
def absoluteValue(n: Int): Int =
if (n < 0) -n else n
val hux = "hux"
def mux = "mux"
def qux: String = "qux"
type ξ[A] = (A, A)
trait Hist { lhs =>
def ⊕(rhs: Hist): Hist
}
def gsum[A: Ring](as: Seq[A]): A =
as.foldLeft(Ring[A].zero)(_ + _)
sealed trait Compass
case object North extends Compass
case object South extends Compass
case object East extends Compass
case object West extends Compass
trait Cake {
type T;
val things: Seq[T]
abstract class Spindler
def spindle(s: Spindler, ts: Seq[T], reversed: Boolean = false): Seq[T]
}
val colors = Map(
"red" -> 0xFF0000,
"turquoise" -> 0x00FFFF,
"black" -> 0x000000,
"orange" -> 0xFF8040,
"brown" -> 0x804000)
lazy val ns = for {
x <- 0 until 100
y <- 0 until 100
} yield (x + y) * 33.33
CoffeeScript
class Animal
### Intellegent design ###
getDNA: ->
print 'sequencing...'
while true
sleep 1
class Monkey extends Animal
speak: ->
print 'ah ah ah'
class Human extends Monkey
speak: ->
print ['yolo' unless i % 3] + ['swag' unless i % 5] or i for i in [1..100]
C
#include <stdio.h>
int main(void)
{
printf("Hello world\n");
return 0;
}
C++
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
C-sharp
class ExampleClass
{
static void Main()
{
System.Console.WriteLine("Hello, world!");
}
}
Erlang
io:format("~s~n", ["hello, world"])
Go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
ObjectiveC
#import <stdio.h>
int main(void)
{
printf("Hello, World!\n");
return 0;
}
PHP
<?php echo 'Hello, world'; ?>
Python
print("Hello World")
Ruby
puts "Hello world!"