مقدمة عن لغة سكالا

Post on 10-May-2015

4.320 views 7 download

Tags:

description

مقدمة عن لغة سكالا من المهندس احمد سليمان

Transcript of مقدمة عن لغة سكالا

Welcome to the Scalable Language

Ahmed SolimanFounder and Chairman

noZom NGO

Tuesday, May 24, 2011

@AhmedSoliman

AhmedSoliman.com

Asoliman@nozom.org

Tuesday, May 24, 2011

Martin OderskySwitzerland

Tuesday, May 24, 2011

@odersky

✦ 52 years old

✦ Pizza Programming language

✦ Generic Java

✦ Scala 2001

Tuesday, May 24, 2011

What is Scala?

Tuesday, May 24, 2011

What is Scala?

✦ Pronounced ‘skah-lak’

✦ Scalable Language

✦ Tastefully typed language

✦ Blend of object-oriented and functional programming

Tuesday, May 24, 2011

What is Scala?

✦ Uses the glorious JVM

✦ Can be used as scripting language

✦ Compiled!

✦ Everything is an expression!

Tuesday, May 24, 2011

Expression vs. Statement

Tuesday, May 24, 2011

Grows on you

✦ Looks like modern dynamically typed languages (Python, Ruby, etc.)

✦ Unlike Python, maps in scala is not a language syntax! {‘key’: ‘value’}

Tuesday, May 24, 2011

Growing new types

✦ BigInt looks like a built-in type, because you can use integer literals and operators such as (*, -, and +) with values of that type

Tuesday, May 24, 2011

What makes Scala scalable?

✦ Scala is object oriented in pure form!

✦ Every value is an object and every operation is a method call

✦ Scala is full-blown functional programming language

Tuesday, May 24, 2011

Functional?

✦ Lisp late 50s

✦ Scheme, SML, Erlang, Haskell, OCaml, and F#

✦ For long time, popular in academia, but not in industry

Tuesday, May 24, 2011

What’s functional?

✦ Functions return a value, given a set of parameters a function has one possible result.

Tuesday, May 24, 2011

Two Main Ideas: I

Functions are first-class citizens

Tuesday, May 24, 2011

Citizens?

✦ A function is a value of the same status as, say, an integer or a string.

✦ You can pass functions as arguments to other functions

✦ Return functions as a results from functions

✦ Store them in variables

Tuesday, May 24, 2011

Functions, citizens?

✦ You can define functions without giving them a name, sprinkling your code with function literals as easy as integer literals, like 25

✦ A good example is the pain in writing code for event handling in java

Tuesday, May 24, 2011

This is Java

Tuesday, May 24, 2011

Two Main Ideas: II

✦ Operations of a program should map input values to output values rather than change data in place

✦ Consider the difference between Strings in Java and Ruby!

✦ Immutable data structures are the cornerstone of functional programming

Tuesday, May 24, 2011

Referential Transparency

Tuesday, May 24, 2011

State is the evil!Pun intended

Tuesday, May 24, 2011

Multi-core problems✦ The future!

✦ Threading is damn hard to get right

✦ Memory overhead

✦ Dead locks?

✦ Shared state? Monitor? Mutex? Semaphore?

✦ Demand for highly concurrent application is increasing

Tuesday, May 24, 2011

Why Scala?

Tuesday, May 24, 2011

Why Scala?✦ The Java Virtual Machine

✦ Concise (programs are shorter)

Tuesday, May 24, 2011

Why Scala??✦ A rich static type system that gets out of your

way when you don’t need it, is awesome when you do. (Type Inference). Verifiable!

✦ Flexible syntax

✦ Immutable and mutable variables

Tuesday, May 24, 2011

Why Scala??

✦ Functional programming features: mapping, filtering, folding, currying, so much more.

✦ FAST! (most of the times as fast as Java)

✦ Can call any Java code

✦ Can be called by any Java code

Tuesday, May 24, 2011

Mapping

Tuesday, May 24, 2011

Reducing

21

Tuesday, May 24, 2011

Pattern Matching

Tuesday, May 24, 2011

Currying

Tuesday, May 24, 2011

Concurrency

✦ Actor model! (kinda like erlang)

✦ Threads

✦ Any other JVM concurrency framework (Netty, Apache Mina, etc.)

Tuesday, May 24, 2011

Concurrency :: Actor✦ Actor Mode: a different way to implement

concurrency

✦ Each object is an actor

✦ Each actor has a mailbox

✦ Actors (asynchronously) send messages and receive them in their mailbox

✦ No Shared State

✦ Why?

Tuesday, May 24, 2011

Actors :: Performance✦ Apache (C/Threads) vs. Yaws (Erlang/Actor)

Tuesday, May 24, 2011

Actors :: Simpler

✦ Code is design around single-threaded mind

✦ No Mutable State

✦ No (Dead) lock

Tuesday, May 24, 2011

Language Tour

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

What for?

Tuesday, May 24, 2011

✦ Scripting

✦ Concurrent Applications

✦ Web Development (Lift)

✦ Backend Components

Tuesday, May 24, 2011

Who uses Scala?

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Tuesday, May 24, 2011

Summary✦ Fast

✦ Reuses the Java Ecosystem

✦ Functional

✦ Expressive

✦ Statically typed

✦ Concurrent

✦ Has tons of features, complex? Worth it!

Tuesday, May 24, 2011

www.nozom.orgTuesday, May 24, 2011