SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
SCALA :GOOD/BAD PARTS
Xuefeng.Wu
2014.01.07
PROGRAMMING
GOOD PARTS
bad parts?
PROGRAMMING
PARADIGM
A programming paradigm is a fundamental style of computer
programming, a way of building the structure and elements of
computer programs.
!

There are five main paradigms: imperative, functional, objectoriented, logic and symbolic programming.
PROGRAMMING
PARADIGMS
Turing Machine: Imperative Programming
Turing Machine: Object-oriented Programming
λ-calculus: Functional Programming
First-order logic: Logic Programming
PROGRAMMING
PARADIGMS
!

Turing Machine: Object-oriented Programming
λ-calculus: Functional Programming
OBJECT-ORIENTED
PROGRAMMING
An object has state (data) and behaviour (code).
is an approach to designing modular reusable software systems.
Increased understanding
Ease of maintenance
encapsulation and information hiding
Ease of evolution
inheritance and polymorphism
INCREASED
UNDERSTANDING
Less Code

write less code

Less Logic
Less new things
no surprise

solve problem
EASE OF EVOLUTION
change self and not affect others

be careful of dependence
be careful of status
change object: data and behaviour
always together?
FUNCTIONAL
PROGRAMMING
computation as the evaluation of mathematical functions
and avoids state and mutable data.
emphasises functions that produce results that
depend only on inputs and not on the program state

Increased understanding
Ease of maintenance
Ease of evolution
Effective ?

FP / OO
FP

immutable

OO

encapsulation
WHAT IS SCALA
Scala (/ˈskɑːlə/ skah-lə) is an object-functional
programming and scripting language for general software
applications, statically typed
designed to concisely express solutions in an elegant,
type-safe and lightweight (low ceremonial) manner.
Scala has full support for functional programming
(including currying, pattern matching, algebraic data
types, lazy evaluation, tail recursion, immutability, etc.).
SHOW ME YOUR CODE
Java

Scala

public class Point {




private int x;

private int y;




public Point(int x, int y) {

this.x = x;

this.y = y;

}







public
public
public
public
}

int getX() {return x;}

int getY() {return y;}

void setX(int x) {this.x = x;}

void setY(int y) {this.y = y;}


case class Point(x: Int, y: Int)

Java
List filtered = new ArrayList<Point>();

for(Point p:points){

if(p.y > 0) {

filtered.add(p);

}

}







Collections.sort(points, new
Comparator<Point>() {

public int compare(Point p0, Point p1)
{

return p1.getX() - p0.getX();

}

});

return points;

Scala

points.filter(_.y > 0).sortBy(_.x)
public boolean checkPrime(int number) {

// checks if a number between 1 and 10 is prime

switch (number) {

case 1: return true;

case 2: return true;

case 3: return true;

case 5: return true;

case 7: return true;


Java




default: return false;

}

}

businessResult match {

case OKResult(createdAccount: CreatedAccount) => Created
case FailedResult(emailAlreadyExists) => Conflict
…

case FailedResult(_) => BadRequest


Scala
}
AN INTERN
Worker: salary

Student: courses

Employee: company

Intern

trait
trait
trait
trait
class

Person

Employee extends Person

Student extends Person

Worker extends Person

Intern extends Person with Employee with Student with Worker

* Scala’s Stackable Trait Pattern
Java
public class Quicksort {

private int[] numbers;

private int number;




public void sort(int[] values) {

if (values ==null || values.length==0){

return;

}

this.numbers = values;

number = values.length;

quicksort(0, number - 1);

}




}

private void quickSort(int low, int high) {

int i = low, j = high;

int pivot = numbers[low + (high-low)/2];

while (i <= j) {

while (numbers[i] < pivot) {

i++;

}

while (numbers[j] > pivot) {

j--;

}

if (i <= j) {

exchange(i, j);

i++;

j--;

}

}

// Recursion

if (low < j)

quicksort(low, j);

if (i < high)

quicksort(i, high);

}

private void exchange(int i, int j) {

int temp = numbers[i];

numbers[i] = numbers[j];

numbers[j] = temp;

}


Scala

def quickSort[T <: Ordered[T]](list: List[T]):
List[T] = {

list match {

case Nil => Nil

case x::xs =>

val (before, after) = xs partition (_ < x)

quickSort(before) ++ (x :: quickSort(after))

}

}
ENDLESS
scalaz

Haskell

sealed trait KiloGram
def KiloGram[A](a: A): A @@ KiloGram = Tag[A, KiloGram](a)
val mass = KiloGram(20.0)
2 * mass
res: Double = 40.0

case class KiloGram(value: Double)
val mass = KiloGram(20.0)
2 * mass.value
A NUMBER OF
COMPLAINTS
Compile Times - TDD
Libraries and the Community invocation syntax & terrible
documentation
Magic Syntax - ∼, — !!
Everything is a Type - HTTP
request/response cycle.
‘Local’ Type Inference - Scala can’t
perform full type inference across
your program
LEARN CURL

MOOC :Functional Programming Principles in Scala
INCOMPATIBLE
orm

PK

Storm

lime
KILLER
Scala the good and bad parts
Scala the good and bad parts

Weitere ähnliche Inhalte

Was ist angesagt?

Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesPéter Verhás
 
Learn To Code: Diving deep into java
Learn To Code: Diving deep into javaLearn To Code: Diving deep into java
Learn To Code: Diving deep into javaSadhanaParameswaran
 
Learn To Code: Introduction to c
Learn To Code: Introduction to cLearn To Code: Introduction to c
Learn To Code: Introduction to cSadhanaParameswaran
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to javaSadhanaParameswaran
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8Introduction to functional programming with java 8
Introduction to functional programming with java 8JavaBrahman
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Madhavan Malolan
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh Kumar
 
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNightHyderabad
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabsbrainsmartlabsedu
 
C++ to java
C++ to javaC++ to java
C++ to javaAjmal Ak
 
P 3 object_oriented_programming
P 3 object_oriented_programmingP 3 object_oriented_programming
P 3 object_oriented_programmingIrfan Wahyudin
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaSujit Majety
 
Javascript for Intermediates
Javascript for IntermediatesJavascript for Intermediates
Javascript for IntermediatesAnkit Agrawal
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersHuffPost Code
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingRyan Riley
 

Was ist angesagt? (20)

Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
 
Learn To Code: Diving deep into java
Learn To Code: Diving deep into javaLearn To Code: Diving deep into java
Learn To Code: Diving deep into java
 
Final keyword
Final keywordFinal keyword
Final keyword
 
Learn To Code: Introduction to c
Learn To Code: Introduction to cLearn To Code: Introduction to c
Learn To Code: Introduction to c
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Lambdas
LambdasLambdas
Lambdas
 
java token
java tokenjava token
java token
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8Introduction to functional programming with java 8
Introduction to functional programming with java 8
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
 
Java principles
Java principlesJava principles
Java principles
 
C++ to java
C++ to javaC++ to java
C++ to java
 
P 3 object_oriented_programming
P 3 object_oriented_programmingP 3 object_oriented_programming
P 3 object_oriented_programming
 
Java tokens
Java tokensJava tokens
Java tokens
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Javascript for Intermediates
Javascript for IntermediatesJavascript for Intermediates
Javascript for Intermediates
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP Developers
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 

Andere mochten auch

Why Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldDean Wampler
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in ScalaPatrick Nicolas
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 

Andere mochten auch (7)

Why Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data World
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Intro to Apache Spark
Intro to Apache SparkIntro to Apache Spark
Intro to Apache Spark
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
Why Scala?
Why Scala?Why Scala?
Why Scala?
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 

Ähnlich wie Scala the good and bad parts

Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Simplifying Software Correctness
Simplifying Software CorrectnessSimplifying Software Correctness
Simplifying Software CorrectnessCaleb Callaway
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Courseparveen837153
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional ProgrammingAapo Kyrölä
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionKent Huang
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...Make Mannan
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8 Bansilal Haudakari
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingYuan Wang
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureJayaram Sankaranarayanan
 
java sql hibernate and springsDAKSHAYINI 3BR19EE026.pptx
java sql hibernate and springsDAKSHAYINI 3BR19EE026.pptxjava sql hibernate and springsDAKSHAYINI 3BR19EE026.pptx
java sql hibernate and springsDAKSHAYINI 3BR19EE026.pptxZakiyaSultana7
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987乐群 陈
 
Vendredi Tech_ la programmation fonctionnelle.pptx
Vendredi Tech_ la programmation fonctionnelle.pptxVendredi Tech_ la programmation fonctionnelle.pptx
Vendredi Tech_ la programmation fonctionnelle.pptxGuillaume Saint Etienne
 
Write codeforhumans
Write codeforhumansWrite codeforhumans
Write codeforhumansNarendran R
 

Ähnlich wie Scala the good and bad parts (20)

Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Simplifying Software Correctness
Simplifying Software CorrectnessSimplifying Software Correctness
Simplifying Software Correctness
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Minds-on DDD
Minds-on DDDMinds-on DDD
Minds-on DDD
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org)  (usef...
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
java sql hibernate and springsDAKSHAYINI 3BR19EE026.pptx
java sql hibernate and springsDAKSHAYINI 3BR19EE026.pptxjava sql hibernate and springsDAKSHAYINI 3BR19EE026.pptx
java sql hibernate and springsDAKSHAYINI 3BR19EE026.pptx
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987
 
L04 Software Design Examples
L04 Software Design ExamplesL04 Software Design Examples
L04 Software Design Examples
 
Vendredi Tech_ la programmation fonctionnelle.pptx
Vendredi Tech_ la programmation fonctionnelle.pptxVendredi Tech_ la programmation fonctionnelle.pptx
Vendredi Tech_ la programmation fonctionnelle.pptx
 
Write codeforhumans
Write codeforhumansWrite codeforhumans
Write codeforhumans
 

Kürzlich hochgeladen

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Scala the good and bad parts

  • 3. PROGRAMMING PARADIGM A programming paradigm is a fundamental style of computer programming, a way of building the structure and elements of computer programs. ! There are five main paradigms: imperative, functional, objectoriented, logic and symbolic programming.
  • 4. PROGRAMMING PARADIGMS Turing Machine: Imperative Programming Turing Machine: Object-oriented Programming λ-calculus: Functional Programming First-order logic: Logic Programming
  • 5. PROGRAMMING PARADIGMS ! Turing Machine: Object-oriented Programming λ-calculus: Functional Programming
  • 6. OBJECT-ORIENTED PROGRAMMING An object has state (data) and behaviour (code). is an approach to designing modular reusable software systems. Increased understanding Ease of maintenance encapsulation and information hiding Ease of evolution inheritance and polymorphism
  • 7. INCREASED UNDERSTANDING Less Code write less code Less Logic Less new things no surprise solve problem
  • 8. EASE OF EVOLUTION change self and not affect others be careful of dependence be careful of status change object: data and behaviour always together?
  • 9. FUNCTIONAL PROGRAMMING computation as the evaluation of mathematical functions and avoids state and mutable data. emphasises functions that produce results that depend only on inputs and not on the program state Increased understanding Ease of maintenance Ease of evolution Effective ? FP / OO
  • 11. WHAT IS SCALA Scala (/ˈskɑːlə/ skah-lə) is an object-functional programming and scripting language for general software applications, statically typed designed to concisely express solutions in an elegant, type-safe and lightweight (low ceremonial) manner. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.).
  • 12. SHOW ME YOUR CODE
  • 13. Java Scala public class Point {
 
 private int x;
 private int y;
 
 public Point(int x, int y) {
 this.x = x;
 this.y = y;
 }
 
 
 public public public public } int getX() {return x;}
 int getY() {return y;}
 void setX(int x) {this.x = x;}
 void setY(int y) {this.y = y;}
 case class Point(x: Int, y: Int)

  • 14. Java List filtered = new ArrayList<Point>();
 for(Point p:points){
 if(p.y > 0) {
 filtered.add(p);
 }
 }
 
 
 Collections.sort(points, new Comparator<Point>() {
 public int compare(Point p0, Point p1) {
 return p1.getX() - p0.getX();
 }
 });
 return points; Scala points.filter(_.y > 0).sortBy(_.x)
  • 15. public boolean checkPrime(int number) {
 // checks if a number between 1 and 10 is prime
 switch (number) {
 case 1: return true;
 case 2: return true;
 case 3: return true;
 case 5: return true;
 case 7: return true;
 Java 
 default: return false;
 }
 } businessResult match {
 case OKResult(createdAccount: CreatedAccount) => Created case FailedResult(emailAlreadyExists) => Conflict …
 case FailedResult(_) => BadRequest
 Scala }
  • 16. AN INTERN Worker: salary Student: courses Employee: company Intern trait trait trait trait class Person
 Employee extends Person
 Student extends Person
 Worker extends Person
 Intern extends Person with Employee with Student with Worker * Scala’s Stackable Trait Pattern
  • 17. Java public class Quicksort {
 private int[] numbers;
 private int number;
 
 public void sort(int[] values) {
 if (values ==null || values.length==0){
 return;
 }
 this.numbers = values;
 number = values.length;
 quicksort(0, number - 1);
 }
 
 } private void quickSort(int low, int high) {
 int i = low, j = high;
 int pivot = numbers[low + (high-low)/2];
 while (i <= j) {
 while (numbers[i] < pivot) {
 i++;
 }
 while (numbers[j] > pivot) {
 j--;
 }
 if (i <= j) {
 exchange(i, j);
 i++;
 j--;
 }
 }
 // Recursion
 if (low < j)
 quicksort(low, j);
 if (i < high)
 quicksort(i, high);
 }
 private void exchange(int i, int j) {
 int temp = numbers[i];
 numbers[i] = numbers[j];
 numbers[j] = temp;
 }
 Scala def quickSort[T <: Ordered[T]](list: List[T]): List[T] = {
 list match {
 case Nil => Nil
 case x::xs =>
 val (before, after) = xs partition (_ < x)
 quickSort(before) ++ (x :: quickSort(after))
 }
 }
  • 18. ENDLESS scalaz Haskell sealed trait KiloGram def KiloGram[A](a: A): A @@ KiloGram = Tag[A, KiloGram](a) val mass = KiloGram(20.0) 2 * mass res: Double = 40.0 case class KiloGram(value: Double) val mass = KiloGram(20.0) 2 * mass.value
  • 19. A NUMBER OF COMPLAINTS Compile Times - TDD Libraries and the Community invocation syntax & terrible documentation Magic Syntax - ∼, — !! Everything is a Type - HTTP request/response cycle. ‘Local’ Type Inference - Scala can’t perform full type inference across your program
  • 20. LEARN CURL MOOC :Functional Programming Principles in Scala
  • 22.
  • 23.