twinsquared.ch

Example

Ruby

Ruby is a dynamic, reflective, general purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was initially developed and designed by Yukihiro "Matz" Matsumoto. It is based on Perl, Smalltalk, Eiffel, Ada, and Lisp.

# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end
 
  def salute
    puts "Hello #{@name}!"
  end
end
 
# Create a new object
g = Greeter.new("world")
 
# Output "Hello World!"
g.salute
 

Python

Python is a general-purpose high-level programming language. Its design philosophy emphasizes programmer productivity and code readability. Python's core syntax and semantics are minimalistic, while the standard library is large and comprehensive. Its use of whitespace as block delimiters is unusual among popular programming languages.

def some_function():
    try:
        # Division by zero raises an exception
        10 / 0
    except ZeroDivisionError:
        print "Oops, invalid."
    else:
        # Exception didn't occur, we're good.
        pass
    finally:
        # This is executed after the code block is run
        # and all exceptions have been handled, even
        # if a new exception is raised while handling.
        print "We're done with that."
 
>>> some_function()
Oops, invalid.
We're done with that.

Perl

In computer programming, Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall, a linguist working as a systems administrator for NASA, in 1987, as a general purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular among programmers. Larry Wall continues to oversee development of the core language, and its coming version, Perl 6.

$name = "joe";
$color = 'red';
 
$number1 = 42;
$number2 = '42';
 
# This evaluates to true
if ($number1 == $number2) { print "Numbers and strings of numbers are the same!"; }
 
$answer = "The answer is $number1"; # Variable interpolation: The answer is 42
$price = 'This device costs $42'; # No interpolation in single quotes
 
$album = "It's David Bowie's \"Heroes\""; # literal quotes inside a string;
$album = 'It\'s David Bowie\'s "Heroes"'; # same as above with single quotes;
$album = q(It's David Bowie's "Heroes"); # the quote-like operators q() and qq() allow
 # almost any delimiter instead of quotes, to
 # avoid excessive backslashing
 
$multilined_string =<<EOF;
This is my multilined string
note that I am terminating it with the "EOF" word.
EOF
 

Lua

In computing, Lua is a lightweight, reflective, imperative and functional programming language, designed as a scripting language with extensible semantics as a primary goal. The name means 'moon' in Portuguese. It is known for having a simple yet powerful C API.

function factorial(n)
  if n == 0 then
    return 1
  else
    return n * factorial(n - 1)
  end
end                                     
 
function factorial2(n)             -- Shorter equivalent of the above
  return n==0 and 1 or n*factorial2(n - 1)
end
 

C

In computing, C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system.

#include <stdio.h>
 
int main(void)
{
    printf("hello, world\n");
    return 0;
}
 

C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup in 1979 at Bell Labs as an enhancement to the C programming language and originally named "C with Classes". It was renamed to C++ in 1983.

#include <iostream>
#include <ostream>
 
int main() 
{
   std::cout << "Hello World!" << std::endl;
}