SlideShare a Scribd company logo
1 of 58
6 Programming
Languages
under investigation
C++, C#, Java, Scala, Ruby and JavaScript
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
A flower
from every
garden
Ruby
JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 3
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
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
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
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
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
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
Start your
Engines! Compilation
Intermediate
LanguageC#
Java
Scala
Machine Code
C++
Interpreted
JavaScript
Ruby
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 10
Start your
Engines! Linkage
Dynamic
• C++
• C#
• Java
• Scala
• Ruby
Static
• C++
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 11
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
There is a
Genius inside
Each ofUs
Personal Impressions
Ruby
JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 13
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
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
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}
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
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
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
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
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
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
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
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
SyntacticalOverview Runnable r = new Runnable() {
public void run() { }
};Java
Anonymous
Classes
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 25
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
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
SyntacticalOverview
module MyFirstModule
def first_method
end
end
module MySecondModule
def second_method
7
end
end
class MyParentClass
include MyFirstModule
# override
def to_s
super
end
end
Ruby Classes
and Modules
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 28
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
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
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
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
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
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
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
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++)
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
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
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
Break!
Ruby
JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 40
Programming Paradigms
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 41
TypeSystems
Static
• C++
• C#
• Java
• Scala
Dynamic
• Ruby
• JavaScript
Strong
• C#
• Scala
Weak
• Ruby
• JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 42
C#
Scala
TypeSystems
ValueTypes
ReferenceTypes
HigherOrderTypes
C#
Scala
Ruby
JS?
C++?
C++
C#
Java
Scala
Ruby
JS
C++
C#
Scala
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 43
TypeSystems
Annotations
• C#
• Java
• Scala
Generics
• C#
• Java
• Scala
Templates
• C++
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 44
Memory Management
Manual
C++
Pointers
Automatic
C++
auto_ptr Destructors
Garbage
Collected
C#,
Java,
Scala,
Ruby & JS
Unreliable
Finalizers
(C#: CFO)
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 45
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
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
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
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
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
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
InheritanceCardinality
Single
C#
Java
JavaScript
Mix-in
Scala
Ruby
Multiple
C++
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 52
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
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
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
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
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
That’s it.
Thank you!
Ruby
JavaScript
March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 58

More Related Content

What's hot

(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in actionCiro Rizzo
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web appschrisbuckett
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developersjessitron
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene BurmakoVasil Remeniuk
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Arnaud Giuliani
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonCodemotion
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 

What's hot (20)

Google Dart
Google DartGoogle Dart
Google Dart
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web apps
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene Burmako
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
Java script
Java scriptJava script
Java script
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Svcc Groovy Testing
Svcc Groovy TestingSvcc Groovy Testing
Svcc Groovy Testing
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 

Similar to 6 Programming Languages Syntactical Overview

Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005Tugdual Grall
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Jonathan Felch
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Java Intro
Java IntroJava Intro
Java Introbackdoor
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesRay Toal
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
java object oriented presentation
java object oriented presentationjava object oriented presentation
java object oriented presentationAli Ahsan Mujahid
 

Similar to 6 Programming Languages Syntactical Overview (20)

Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Prototype Js
Prototype JsPrototype Js
Prototype Js
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Jet presentation
Jet presentationJet presentation
Jet presentation
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Java Intro
Java IntroJava Intro
Java Intro
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
 
Modern frontend in react.js
Modern frontend in react.jsModern frontend in react.js
Modern frontend in react.js
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
java object oriented presentation
java object oriented presentationjava object oriented presentation
java object oriented presentation
 

Recently uploaded

Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 

Recently uploaded (20)

Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 

6 Programming Languages Syntactical Overview

  • 1. 6 Programming Languages under investigation C++, C#, Java, Scala, Ruby and JavaScript
  • 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
  • 3. A flower from every garden Ruby JavaScript March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 3
  • 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
  • 10. Start your Engines! Compilation Intermediate LanguageC# Java Scala Machine Code C++ Interpreted JavaScript Ruby March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 10
  • 11. Start your Engines! Linkage Dynamic • C++ • C# • Java • Scala • Ruby Static • C++ March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 11
  • 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
  • 28. SyntacticalOverview module MyFirstModule def first_method end end module MySecondModule def second_method 7 end end class MyParentClass include MyFirstModule # override def to_s super end end Ruby Classes and Modules March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 28
  • 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
  • 40. Break! Ruby JavaScript March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 40
  • 41. Programming Paradigms March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 41
  • 42. TypeSystems Static • C++ • C# • Java • Scala Dynamic • Ruby • JavaScript Strong • C# • Scala Weak • Ruby • JavaScript March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 42 C# Scala
  • 44. TypeSystems Annotations • C# • Java • Scala Generics • C# • Java • Scala Templates • C++ March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 44
  • 45. Memory Management Manual C++ Pointers Automatic C++ auto_ptr Destructors Garbage Collected C#, Java, Scala, Ruby & JS Unreliable Finalizers (C#: CFO) March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 45
  • 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
  • 58. That’s it. Thank you! Ruby JavaScript March 8, 2013 Presented by Hosam Aly at Egypt's JDC 2013 58

Editor's Notes

  1. 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.
  2. 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).
  3. 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.
  4. 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.
  5. 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
  6. C# Anonymous Functions: http://msdn.microsoft.com/en-us/library/bb882516.aspx
  7. Scala Anonymous Functions: http://www.scala-lang.org/node/133
  8. Scala Anonymous Functions: http://www.scala-lang.org/node/133
  9. 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/
  10. 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
  11. 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.
  12. C# accepts weak typing through the `dynamic` keyword Scala allows semi-weak typing via implicit conversions
  13. Scala Value Classes is a new feature in Scala 2.10: http://docs.scala-lang.org/overviews/core/value-classes.html
  14. 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.
  15. 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
  16. 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
  17. 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.
  18. Introduction to Object-Oriented JavaScript: https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript
  19. 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.