The document discusses the syntactical features of 6 programming languages: C++, C#, Java, Scala, Ruby, and JavaScript. It covers topics like identifiers, literals, classes, templates, functions, imports, variables, parameters, and embedded syntax features like LINQ and XML. The presentation aims to provide an overview of the syntactical elements of each language for comparative purposes.
2. Agenda
A flower from every garden
A taste of worldwide fruits
Start your engines!
The genius inside each of us
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 2
4. Atasteofworldwidefruits
#include <iostream>
#include <string>
using namespace std;
int main(/* int argc, char* argv[] */)
{
string name;
cout << "Enter your name, please: ";
cin >> name;
cout << "Hello " + name + "n";
// or
cout << "Hello " << name << endl;
return 0;
}
C++
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 4
5. Atasteofworldwidefruits
using System;
namespace JDC2013
{
class Program {
static void Main(/* string[] args */) {
Console.Write("Enter your name, please: ");
string name = Console.ReadLine();
Console.WriteLine("Hello " + name);
// or
Console.WriteLine("Hello {0}", name);
}
}
}
C#
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 5
6. Atasteofworldwidefruits
package org.egjug.jdc2013;
// import java.lang.*;
public class Program {
public static void main(String[] args) {
System.out.print("Enter your name, please: ");
String name = System.console().readLine();
System.out.println("Hello, " + name);
// or
System.out.printf("Hello, %s", name);
}
}
Java
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 6
7. Atasteofworldwidefruits
package org.egjug.jdc2013
// import scala._
object Program extends App {
print("Enter your name, please: ")
val name = readLine
println("Hello " + name)
// or
printf("Hello %s", name)
}
Scala
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 7
8. Atasteofworldwidefruits
# require 'a_library'
puts 'Enter your name, please: '
name = STDIN.gets
puts 'Hello ' + name
# or
puts "Hello #{name}"
Ruby
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 8
9. Atasteofworldwidefruits var name = prompt("Enter your name, please:");
alert("Hello " + name);JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 9
12. Start your
Engines!
• JavaScript
• Ruby
Interpreter
• C#
• Java
• Scala
Virtual
Machine
• C++
Binary
Executable
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 12
13. There is a
Genius inside
Each ofUs
Personal Impressions
Ruby
JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 13
14. Agenda
Syntactical Overview
Identifiers, Literals, Symbols and Annotations
Classes, Templates, Functions and Code Blocks
Imports,Variables and Parameter Passing
Embedded Syntax (e.g. LINQ, XML)
Programming Paradigms
Procedural, Functional and Object-Oriented
Meta-programming
Type Systems
Static, Dynamic, Strong and Weak
ValueTypes, Reference Types and Higher Order Types
Annotations and Generics
Inheritance Models
Single and Multiple
Polymorphism and Prototyping
Mix-ins: Interfaces, Extensions, Traits and Modules
Memory Management
Manual, Automatic and Garbage Collected
Constructors, Destructors, Initializers and Finalizers
Dependency System
JARs, DLLs, Gems and Static Libraries
The real one!
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 14
15. SyntacticalOverview
Identifiers
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 15
Letters Numerals Operators Operator Examples
C++ Unicode? After first letter Predefined set void operator++()
C# Unicode After first letter Predefined set void operator--()
Java Unicode After first letter None
Scala Unicode After first letter All val + = 1
Ruby Unicode? Anywhere? Most def ಠ_ಠ(x, y)
JavaScript Unicode After first letter None
16. SyntacticalOverview
Literals
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 16
Numeric Objects Functions
C++ 123456, 07, 0xFF int x[] = {0}
C# 123456, 07, 0xFF
new { Name = "Ali" }
new Dict<int, int> {
{1,2}, {3,4} }
x => y, () => {}
Java
123_456, 0b101,
123456, 07, 0xFF
int x[] = {0}
Scala 123456, 07, 0xFF
(1, 2)
{ 'age' -> 24 }
x => y, () => {}
Ruby
123_456
123456, 07, 0xFF
[1], {b:2}, 0..5
JavaScript 123456, 07, 0xFF [1], {b:2}
17. SyntacticalOverview
Symbols &Annotations
Java @Deprecated
class Address {
}
[Obsolete]
class Program
{
}
C#
Scala @cloneable
class Address {
val db_column =
'address_line_1
}
person = {
name: 'Ahmad',
age: 26
}
Ruby
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 17
18. SyntacticalOverview
class MyFirstClass {
public:
// pure virtual function makes a class abstract
virtual void firstMethod() = 0;
};
class MySecondClass {
public:
int secondMethod() { return 7; }
};
class MyParentClass : MyFirstClass {
public:
/* override */
void firstMethod() { }
};
C++ Classes
&Templates
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 18
19. SyntacticalOverview
template<typename T>
class MyClass : MyParentClass, MySecondClass {
T value;
public:
MyClass(T value) { setValue(value); }
T getValue() { return value; }
void setValue(T value) { this->value = value; }
};
// example usage
MyClass<string> obj("");
obj.setValue("Hi");
cout << obj.getValue();
C++ Classes
&Templates
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 19
20. SyntacticalOverview
public interface MyFirstInterface
{
void firstMethod();
}
interface MySecondInterface
{
int secondMethod();
}
abstract class MyParentClass
{
public void firstMethod() { }
public sealed override string ToString()
{
return base.ToString();
}
}
C# Classes,
Interfaces &
Generics
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 20
21. SyntacticalOverview
sealed class MyClass<T> :
MyParentClass, MyFirstInterface, MySecondInterface
{
public MyClass(T value) { Value = value; }
public T Value { get; set; }
public int secondMethod() { return 7; }
}
// example usage
var obj = new MyClass<string>("");
obj.Value = null;
Console.WriteLine(obj.Value);
C# Classes,
Interfaces &
Generics
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 21
22. SyntacticalOverview
Func<int, int, int> f =
(int x, int y) => x * 2;
Action<int> a =
x => { Console.WriteLine(x); };
var v = new { Name = "Mohammad", Age = 24 };
C#
Anonymous
Types and
Functions
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 22
23. SyntacticalOverview
interface MyFirstInterface {
void firstMethod();
}
interface MySecondInterface {
int secondMethod();
}
abstract class MyParentClass
implements MyFirstInterface {
@Override public void firstMethod() {}
@Override public final String toString() {
return super.toString();
}
}
Java Classes,
Interfaces &
Generics
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 23
24. SyntacticalOverview
public final class MyClass<T>
extends MyParentClass implements MySecondInterface {
private T value;
public MyClass(T value) { setValue(value); }
public T getValue() { return value; }
public void setValue(T value) {
this.value = value;
}
@Override public int secondMethod() { return 7; }
}
// example usage
MyClass<String> obj = new MyClass<>("");
obj.setValue(null);
System.out.println(obj.getValue());
Java Classes,
Interfaces &
Generics
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 24
25. SyntacticalOverview Runnable r = new Runnable() {
public void run() { }
};Java
Anonymous
Classes
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 25
26. SyntacticalOverview
trait MyFirstTrait {
def firstMethod()
}
trait MySecondTrait {
def secondMethod = 7
}
abstract class MyParentClass extends MyFirstTrait {
override def firstMethod() {}
final override def toString = super.toString
}
final class MyClass[T](var value: T)
extends MyParentClass with MySecondTrait
object MyClass {
// companion object
def test() {
val obj = new MyClass("")
obj.value = null
println(obj.value)
}
}
Scala Classes,
Traits and
Generics
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 26
27. SyntacticalOverview
val f = (x: Int, y: Int) => x+y
val list = List(-1, 2, 3.0, 5, 7.12)
list.filter(_ < 5)
list.filter(signum(_) != 0)
abstract class Printer {
def print // abstract
}
val p = new Printer {
def print { println("Hi") }
}
Scala
Anonymous
Classes and
Functions
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 27
29. SyntacticalOverview
class MyClass < MyParentClass
include MySecondModule
def initialize(value)
@value = value
end
def value
@value
end
def value= value
@value = value
end
end
# example usage
obj = MyClass.new('')
obj.value = nil
puts obj.value
puts obj.to_s
Ruby Classes
and Modules
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 29
30. SyntacticalOverview
[1, 2, 3].each { |x| puts x }
[1, 2, 3].each do |x|
puts x
end
c = Class.new
c.send :include, MyFirstModule
obj = c.new
Ruby
Anonymous
Classes and
Functions
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 30
31. SyntacticalOverview
No Classes
The following code tries to emulate it
Warning: the following code is unreliable
JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 31
32. SyntacticalOverview
function MyFirstClass() {
this.firstMethod = function () { }
}
function MySecondClass() {
this.secondMethod = function () { return 7; }
}
function MyParentClass() {
// Call the parent constructor
MyFirstClass.call(this);
this.toString = function () {
// take care, this is not exactly super!
return this.prototype.toString();
}
}
MyParentClass.prototype = new MyFirstClass();
MyParentClass.prototype.constructor = MyParentClass;
JavaScript
Function
Prototypes
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 32
33. SyntacticalOverview
function MyClass(value) {
MyParentClass.call(this);
MySecondClass.call(this);
this.value = value;
this.getValue = function () { return this.value; }
this.setValue = function (value) {
this.value = value;
}
}
MyClass.prototype = new MyParentClass();
MyClass.prototype.constructor = MyClass;
// example usage
var obj = new MyClass("");
obj.setValue(null); // or obj.value = null;
alert(obj.getValue()); // or alert(obj.value);
JavaScript
Function
Prototypes
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 33
34. SyntacticalOverview
Imports
C++
• #include <iostream>
C#
• using System.Collections;
• using Con = System.Console;
Java
• import java.util.*;
• import static java.lang.Math.*;
Scala
• import scala.io._
• import java.lang.Math.{IEEEremainder => rem, _}
Ruby
• require 'date/format'
• load 'date/format.rb'
N/AJavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 34
35. SyntacticalOverview
Variables
C++
• int x; auto y = 0; const int &z = x; char *p;
• vector<int> x; const vector<int> x;
C#
• int x; const int x; readonly int x; var x = 0;
• List<int> x; readonly List<int> x;
Java
• int x; final int x;
• List<Integer> x; final List<Integer> x;
Scala
• var x: Int; val x: Int;
• var x: List[Int]; val x: List[Int];
Ruby
• x = 0; @x = 1; @@x = 2
• Constant = 0; CONSTANT = 0
var x;JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 35
36. SyntacticalOverview
Parameters andArguments
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 36
All
Languages
except JavaScript
Default
Arguments
(except Java)
Variable
Arguments
Named
Arguments
(except C++)
37. SyntacticalOverview
Parameters andArguments
void f(int x, const char *p = "abc", ...)C++
• Positional arguments only, with constant default arguments and
un-typed varargs
void f(int x, string s = "ab", params int[] y)C#
• f(1, s: "def"); f(0, null, 1, 2, 3)
• Named, constant default and typed variable arguments supported
void f(int x, String... args)Java
• Positional arguments only, with typed variable arguments
def f(x: Int, y: Int = 0, z: =>Long, s: Int*)Scala
• f(1, z = System.nanoTime())
• Named & expr. default arguments, typed varargs, and call-by-name
def f(x, y = 0, z = @a, tags: [], *names)Ruby
• Named, expression default and variable arguments
function f(x)JavaScript
• Nothing special; variable arguments supported artificially
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 37
38. SyntacticalOverview
EmbeddedSyntax
C# LINQ
var query =
from c in categories
join p in products
on c equals p.Category
into ps
from p in ps.DefaultIfEmpty()
select new {
Category = c,
ProductName = p.ProductName
};
Scala XML
val html =
<html>
<body>
<h1>Hello Scala!</h1>
</body>
</html>
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 38
39. Agenda
Syntactical Overview
Identifiers, Literals, Symbols and Annotations
Classes, Templates, Functions and Code Blocks
Imports,Variables and Parameter Passing
Embedded Syntax (e.g. LINQ, XML)
Programming Paradigms
Procedural, Functional and Object-Oriented
Meta-programming
Type Systems
Static, Dynamic, Strong and Weak
ValueTypes, Reference Types and Higher Order Types
Annotations and Generics
Inheritance Models
Single and Multiple
Polymorphism and Prototyping
Mix-ins: Interfaces, Extensions, Traits and Modules
Memory Management
Manual, Automatic and Garbage Collected
Constructors, Destructors, Initializers and Finalizers
Dependency System
JARs, DLLs, Gems and Static Libraries
The real one!
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 39
46. Memory
Management
All languages support constructors.
Dynamic languages (i.e. Ruby and JavaScript)
provide only one constructor, and rely on the
dynamic nature of their parameters.
Only C++ has deterministic destructors.
C#, Java, Scala and Ruby support finalizers, but
they are not guaranteed tor run.
JavaScript has no finalizers, because all memory is
GC’d.
The .NET framework provides a
CriticalFinalizerObject parent class,
supporting semi-guaranteed finalization.
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 46
47. MemoryManagement
Class Initializers
C++
class MyClass { static int x; };
MyClass::x = 0;
C#
static class MyClass {
static int x;
static MyClass() { x = 10; } }
Java
class MyClass {
static int x;
static { x = 10; } }
Scala
object MyClass {
var x: Int;
x = 10 }
Ruby
class MyClass
@@x = 10
end
JS
function MyClass() {}
MyClass.x = 10;
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 47
48. Polymorphism
and
Prototyping
Only statically compiled languages have
polymorphism
Dynamic languages don’t need polymorphism.
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 48
49. Polymorphism
C++
class C1 {
public:
void nonVirtualM() {}
virtual void virtualM() {}
};
class C2 : C1 {
public:
void nonVirtualM() {}
virtual void virtualM() {}
};
C#
class C1
{
public void nonVirtual() {}
public virtual void @virtual() {}
}
class C2 : C1
{
public new void nonVirtual() { }
public override void @virtual() {}
}
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 49
50. Polymorphism
Java
class C1 {
public void virtual() {}
}
class C2 extends C1 {
@Override
public void virtual() {}
}
Scala
class C1 {
def virtual {}
}
class C2 extends C1 {
override def virtual {}
}
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 50
51. JavaScript
Prototyping
// define the Person Class
function Person() { }
Person.prototype.walk = function() { alert('Walk'); };
Person.prototype.hello = function() { alert('Hi'); };
function Student() { // define the Student class
Person.call(this); // Call the parent constructor
}
// inherit Person
Student.prototype = new Person();
// correct the constructor pointer
// because it points to Person
Student.prototype.constructor = Student;
// replace the hello method
Student.prototype.hello = function() { alert('hey'); }
// add bye method
Student.prototype.bye = function () { alert('Bye'); }
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 51
53. Mix-ins
Interfaces
Abstract function declarations only
No data, no implementation
Can be emulated
In C++: with pure virtual functions
In Scala: with traits
interface MyInterface
{
void MyMethod();
}
C#
interface MyInterface {
void myMethod();
}
Java
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 53
54. Mix-ins
Extensions
The ability to “attach” new methods
to existing classes or objects
Emulated in Scala using implicit
conversions
static class Extensions {
public static void
Print(this string s) {}
}
// to call it:
"abc".Print();
C#
class String
def print
end
end
# to call it:
'abc'.print
Ruby
String.prototype.print =
function() {};
// to call it:
'abc'.print();
JS
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 54
55. Mix-ins
Traits and Modules
Evolution of interfaces: allowing
implementations
Almost like classes, except that they
cannot be instantiated
Traits cannot have instance
variables, while modules can.
trait T1 {
def print {}
}
class C1
// to use it:
val p = new C1 with T1
p.print
Scala
module Named
def name
@name ||= nil; end
def name=(name)
@name = name; end
end
# to use it:
class Person; include Named;
end
Ruby
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 55
56. DependencySystem
C++
Static Libraries and
Dynamically Loaded Libraries (DLLs) or SOs
C#
Dynamically Loaded Libraries (DLLs)
NuGet
Java
JavaArchives (JARs)
Maven or Ivy
Scala
JavaArchives (JARs)
Simple BuildTool (SBT)
Ruby
Gems
Bundler
JS Node Package Manager (NPM)
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 56
57. Agenda
Syntactical Overview
Identifiers, Literals, Symbols and Annotations
Classes, Templates, Functions and Code Blocks
Imports,Variables and Parameter Passing
Embedded Syntax (e.g. LINQ, XML)
Programming Paradigms
Procedural, Functional and Object-Oriented
Meta-programming
Type Systems
Static, Dynamic, Strong and Weak
ValueTypes, Reference Types and Higher Order Types
Annotations and Generics
Inheritance Models
Single and Multiple
Polymorphism and Prototyping
Mix-ins: Interfaces, Extensions, Traits and Modules
Memory Management
Manual, Automatic and Garbage Collected
Constructors, Destructors, Initializers and Finalizers
Dependency System
JARs, DLLs, Gems and Static Libraries
The real one!
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 57
C++ was invented in the 1980s, as an object-oriented addition to C. Similar background of weak processors and small memory.
Java and JavaScript appeared almost at the same time, in the mid-1990s. JavaScript was considered a lightweight scripting language with emphasis on familiarity to Java programmers. Java was the first thoroughly documented, VM-sandboxed programming language.
At the other end of the world, Ruby was invented in the middle 1990s, in the far distant east in Japan. It’s a scripting language that learned a lot from other languages throughout time. It wasn’t known to the rest of the world until the late 1990s.
C# followed at the beginning of the millennium, along with .NET, as an effort from Microsoft to regain grounds. C# evolution was much quicker than Java in the 10 years that followed.
Scala was a research effort from Switzerland with the goal of creating a “better Java”, that would be compatible with existing Java libraries, but provide a more modern programming language. It became public in the middle 2000s.
Note that the call to System.console() will return null if the application is being run inside an IDE or if it doesn’t have a console (e.g. Web Start or Swing).
C++ applications are normally compiled and linked into binary code.
C# applications are compiled into an executable, but it requires the .NET framework to be installed.
Java applications can be distributed in various ways, e.g. Executable JARs, Applets, and Web Start.
Scala applications are in essence Java applications, so most Java distribution channels apply to Scala.
JavaScript and Ruby need an interpreter.
JavaScript is easiest. Very simple syntax & very few constructs
Java is easy to learn.
C++ is somewhat harder.
C# has both Java and C++ features, so it’s harder to grasp all of it.
Ruby is intermediate. Quite some features, but not too many. The problem is with aging names.
Scala is probably harder than all of them, because it has features from both OOP and Functional worlds, and sometimes looks like scripting! But it’s probably the most advanced too.
C# Overloadable Operators: http://msdn.microsoft.com/en-us/library/8edha89s.aspx
Java Language Specification: http://docs.oracle.com/javase/specs/
Scala Language Specification: http://www.scala-lang.org/docu/files/ScalaReference.pdf
Valid JavaScript variable names: http://mathiasbynens.be/notes/javascript-identifiers
Introduction to Object-Oriented JavaScript: https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript
JavaScript Ninja Slides: http://ejohn.org/apps/learn/
C#: http://msdn.microsoft.com/en-us/library/dd264739.aspx
Scala: http://www.scala-lang.org/node/2075
Named Arguments are new in Ruby 2.0
C++, Ruby and JavaScript can have functions defined anywhere. Scala can have functions defined directly in a package.
Scala supports almost all functional programming constructs, and even has special syntax to aid in functional programming. Ruby, C# and JavaScript all treat functions as first-class objects. C++ has function pointers, but no anonymous functions.
All the languages presented here claim to be object-oriented, but they vary in the level to which they mandate (or encourage) following OOP principles.
Ruby supports Meta-programming at all levels. Suffice it to say that one can “open” a class and add or override methods dynamically. The same can even be done to objects. JavaScript follows closely, although it provides no special syntax for that, but its very dynamic nature allows methods to be added and replaced with extreme ease. Scala supports implicit methods and implicit conversions, and C# supports extension methods, both of which can simulate this behavior.
C# accepts weak typing through the `dynamic` keyword
Scala allows semi-weak typing via implicit conversions
Scala Value Classes is a new feature in Scala 2.10: http://docs.scala-lang.org/overviews/core/value-classes.html
Only the C++ compiler generates multiple versions of the class for each template parameter value. It also supports template customization, which (as far as I know) is not supported by the other compilers.
Example of manual memory management in C++:
string *s = new string; delete s;
int[] a = new int[1000]; delete[] a;
Examples of automatic memory management in C++:
auto_ptr<string> str(new string);
class DynamicArray {
int *array;
public:
DynamicArray(int size) {
array = new int[size];
}
~DynamicArray() {
delete[] array;
}
}
Beware of cyclic dependencies in Garbage Collection
Constructors:
C++: class MyClass { MyClass(int x) {} }
C#: class MyClass { MyClass(int x) {} }
Java: class MyClass { MyClass(int x) {} }
Scala: class MyClass(x: Int)
Ruby: class MyClass; def initialize(x); end; end
JavaScript: function MyClass(x) {}
Destructors:
C++: class MyClass { ~MyClass() {} }
Finalizers:
C#: class MyClass { ~MyClass() {} } | CriticalFinalizerObject
Java: class MyClass { protected void finalize() {} }
Scala: class MyClass { override def finalize() {} }
Ruby: class MyClass
ObjectSpace.define_finalizer(self, proc { })
end
There is no polymorphism in dynamic languages (i.e. Ruby and JS), as there is no compiler and no virtual function table. Every object somehow has a set of pointers to its methods.
Introduction to Object-Oriented JavaScript: https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript
Tutorial about Scala Traits: http://joelabrahamsson.com/learning-scala-part-seven-traits/
Ruby modules are almost classes, except they cannot be instantiated. Any instance methods are only accessible if the module is included in a class.