SlideShare a Scribd company logo
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

PDF
ADG Poznań - Kotlin for Android developers
PDF
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
PDF
Javantura v2 - Making Java web-apps Groovy - Franjo Žilić
PPTX
PPTX
Dart, unicorns and rainbows
PDF
The Kotlin Programming Language, Svetlana Isakova
PDF
Introduction to kotlin
PDF
Google Dart
ADG Poznań - Kotlin for Android developers
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - Making Java web-apps Groovy - Franjo Žilić
Dart, unicorns and rainbows
The Kotlin Programming Language, Svetlana Isakova
Introduction to kotlin
Google Dart

What's hot (19)

PDF
(How) can we benefit from adopting scala?
PDF
C# Starter L02-Classes and Objects
PDF
Kotlin Developer Starter in Android projects
PDF
Kotlin in action
PDF
Coding Ajax
ODP
AST Transformations at JFokus
PDF
Kotlin advanced - language reference for android developers
PPTX
Dart structured web apps
PDF
Functional Principles for OO Developers
PPTX
Javascript Basics
PDF
scala.reflect, Eugene Burmako
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
PPTX
Java script
PDF
Why Java Sucks and C# Rocks (Final)
PDF
TWINS: OOP and FP - Warburton
ODP
Ast transformations
PPT
Svcc Groovy Testing
ODP
AST Transformations
(How) can we benefit from adopting scala?
C# Starter L02-Classes and Objects
Kotlin Developer Starter in Android projects
Kotlin in action
Coding Ajax
AST Transformations at JFokus
Kotlin advanced - language reference for android developers
Dart structured web apps
Functional Principles for OO Developers
Javascript Basics
scala.reflect, Eugene Burmako
Develop your next app with kotlin @ AndroidMakersFr 2017
Svcc Building Rich Applications with Groovy's SwingBuilder
Java script
Why Java Sucks and C# Rocks (Final)
TWINS: OOP and FP - Warburton
Ast transformations
Svcc Groovy Testing
AST Transformations
Ad

Similar to 6 Programming Languages under investigation (20)

KEY
1 the language essentials
PDF
Java Full Throttle
PPT
Core_java_ppt.ppt
PPTX
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
PDF
Scala - from "Hello, World" to "Heroku Scale"
PPTX
Learn Java in 2 days
PDF
robert-kovacsics-part-ii-dissertation
PDF
Javaprecisely
PPT
java tutorial for beginners learning.ppt
PDF
Core Java Volume I Fundamentals 12th Horstmann Cay
PDF
(Ebook) The Rust Programming Language, Second Edition by Steve Klabnik, Carol...
PPT
core java
PPT
PPT
PPT
JAVA ppt tutorial basics to learn java programming
PPTX
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
PPT
Introduction to Java(basic understanding).ppt
PPTX
ppt_on_java.pptx
PDF
Basic Java Programming
PPTX
Java programmingjsjdjdjdjdjdjdjdjdiidiei
1 the language essentials
Java Full Throttle
Core_java_ppt.ppt
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Scala - from "Hello, World" to "Heroku Scale"
Learn Java in 2 days
robert-kovacsics-part-ii-dissertation
Javaprecisely
java tutorial for beginners learning.ppt
Core Java Volume I Fundamentals 12th Horstmann Cay
(Ebook) The Rust Programming Language, Second Edition by Steve Klabnik, Carol...
core java
JAVA ppt tutorial basics to learn java programming
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
Introduction to Java(basic understanding).ppt
ppt_on_java.pptx
Basic Java Programming
Java programmingjsjdjdjdjdjdjdjdjdiidiei
Ad

More from Hosam Aly (6)

PPTX
Running a simple Scala app in AWS Lambda (demo)
PDF
القيادة: فن ومهارة (Leadership: an art and a skill)
PPTX
Hard questions
PDF
Dev Team Process
PDF
Quick dive into Ruby on Rails
PPTX
Mercurial DVCS
Running a simple Scala app in AWS Lambda (demo)
القيادة: فن ومهارة (Leadership: an art and a skill)
Hard questions
Dev Team Process
Quick dive into Ruby on Rails
Mercurial DVCS

Recently uploaded (20)

PDF
Digital Strategies for Manufacturing Companies
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administraation Chapter 3
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Strategies for Manufacturing Companies
Reimagine Home Health with the Power of Agentic AI​
VVF-Customer-Presentation2025-Ver1.9.pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Odoo Companies in India – Driving Business Transformation.pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
top salesforce developer skills in 2025.pdf
System and Network Administraation Chapter 3
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
wealthsignaloriginal-com-DS-text-... (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Odoo POS Development Services by CandidRoot Solutions
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Adobe Illustrator 28.6 Crack My Vision of Vector Design

6 Programming Languages under investigation

  • 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

  • #4: 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.
  • #7: 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).
  • #13: 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.
  • #14: 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.
  • #16: 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
  • #23: C# Anonymous Functions: http://msdn.microsoft.com/en-us/library/bb882516.aspx
  • #28: Scala Anonymous Functions: http://www.scala-lang.org/node/133
  • #31: Scala Anonymous Functions: http://www.scala-lang.org/node/133
  • #33: 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/
  • #37: 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
  • #42: 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.
  • #43: C# accepts weak typing through the `dynamic` keyword Scala allows semi-weak typing via implicit conversions
  • #44: Scala Value Classes is a new feature in Scala 2.10: http://docs.scala-lang.org/overviews/core/value-classes.html
  • #45: 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.
  • #46: 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
  • #47: 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
  • #49: 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.
  • #52: Introduction to Object-Oriented JavaScript: https://developer.mozilla.org/en-US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript
  • #56: 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.