SlideShare a Scribd company logo
1 of 67
Download to read offline
SCALA
Scalable language
About.me/byF
About.me/byF



Basic → Pascal → JavaScript → C/C++ → PHP → Java → Scala
Scala je nechvalně proslulá jako složitý
                 jazyk.
"Útes šílenství"
Scala jednoduše řeší složité problémy!
"If I were to pick a language to use today
other than Java, it would be Scala."
                               James Gosling
Scala a Java




téměř 100% kompatibilní

   JVM ekosystém
Kdo používá Scalu?
Kdo používá Scalu?




            @byFcz
Velmi, velmi základní syntaxe




  val msg = "ScalaFTW!"
Scala má pokročilou type inference!
Velmi, velmi základní syntaxe




val msg: String = "ScalaFTW!"
Scala má semi-colon inference!
Velmi, velmi základní syntaxe




     def msg = "ScalaFTW!"
Velmi, velmi základní syntaxe




def msg(): String = { return "ScalaFTW!"}
Scala má úspornou, flexibilní syntaxi!
Scala je čistě objektový jazyk




           1+2
Scala je čistě objektový jazyk




         (1).+(2)
Definice třídy v Javě
class Person {
   private String name;

    public Person(String name) {
         this.setName(name);
    }

    public void getName() {
         return this.name;
    }

    public String setName(String name) {
         this.name = name;
    }
}
Definice třídy ve Scale



class Person(var name: String)
Singleton v Javě
public class Singleton {

    private static final Singleton instance = new Singleton();


    private Singleton() { }

    public static Singleton getInstance() {
        return instance;
    }
}
Singleton ve Scale



 object Singleton
Scala je funkcionální jazyk
Kolekce funkcionálně

int[] x = {1,2,3,4,5,6}
ArrayList res = new ArrayList();
for (int v : x) {
  if (v % 2 == 1)
     res.add(new Integer(v));
}
Kolekce funkcionálně



val x = Array(1,2,3,4,5,6)
val res = x filter ( _ % 2 == 1 )
Kolekce funkcionálně




val (odds,evens) = x partition(_% 2 == 1)
Kolekce funkcionálně




val str = x mkString
Kolekce funkcionálně




val str = x mkString("Start: ",",","!")
Scala je HYBRID!
Case classes



case class Person(name: String,surname: String)
Pattern matching


selektor match {
  vzor => výraz(y)
  jinyVzor => výraz(y)
}
Switch v Javě


public boolean doSwitch(int n) {
  switch(n) {
     case 1: return true;
     default: return false;
}
}
Alternativa switche ve Scale


def doSwitch(n:Integer) = n match {
  case 1 => true
  case _ => false
}
Case classes



case class Person(name: String,surname: String)
Pattern matching v akci
val audience = List[Person](...)

         /* To jste VY! */

val enthusiasts = audience filter {
  case _ => false
}
Pattern matching v akci
val enthusiasts = audience filter {
  case Person("Karel","Smutný") => true
  case _ => false
}
Pattern matching v akci
val enthusiasts = audience filter {
  case Person("Karel","Smutný") => true
  case Person("Jan",_) => true
  case _ => false
}
Pattern matching v akci
val enthusiasts = audience filter {
  case Person("Karel","Smutný") => true
  case Person("Jan",_) => true
  case Person("Tomas",sur) =>
     println(sur)
     true
  case _ => false
}
Pattern matching v akci
val enthusiasts = audience filter {
  case Person("Karel","Smutný") => true
  case Person("Jan",_) => true
  case Person("Tomas",sur) =>
     println(sur)
     true
  case Person(name,sur) => true
  case _ => false
}
Podpora XML



val elem = <xml></xml>
Podpora XML



val elem = <xml>{foo}</xml>
Podpora XML



<xml>scala</xml>.text
Podpora XML



<a><b>hello</b></a>  "b"
Více jader, ...
... 80 jader!
Kolekce paralelně


val kolekce = for {
  s <- surnames //mujan
  n <- names    //jan
  if s endsWith n
} yield n + " " + s
Kolekce paralelně


val kolekce = for {
  s <- surnames.par
  n <- names.par
  if s endsWith n
} yield n + " " + s
Paralelní programování „klasicky“




        Sdílení dat & zámky
Paralelní programování „klasicky“




     Deadlocks & race conditions
Actor model




„Make send, not share.“
Actor model


class Announcer extends Actor {
  def receive = {
     case s: String => println(s)
     case _ => println("Ignored!")
  }
}
Actor model


val zf = Actor.actorOf[Announcer].start()
zf ! "Super" //Actor vypíše Super
zf ! 5 //Actor ignoruje zprávu
val a = Actor.actorOf[Announcer].start()
val b = Actor.actorOf[Announcer].start()
val c = Actor.actorOf[Announcer].start()
Actor model




Fault tolerance → Self-Healing
Teď trochu distribuovaně…




RMI, Corba, EJB, SOAP, XML-RPC, Thrift
Teď trochu distribuovaně…



„It‘s time for RPC to retire!“
                            Steve Vinoski
Akka 2.0




Úplně všichni aktoři jsou distribuovaní!
Akka 2.0




Naprogramovali jste actor-based
          aplikaci.
Akka 2.0




Přidáte další stroj a zapnete v
      konfiguraci cluster.
Scala je elegantní jazyk se stručnou
syntaxí, který umožňuje jednoduše
       řešit složité problémy.
Literatura



• Programming in Scala, Second Edition
     http://www.artima.com/shop/programming_in_scala_2ed

• Dokumentace na webu Scaly
     http://www.scala-lang.org/node/197
Czech Scala Enthusiasts
http://www.meetup.com/czech-scala-enthusiasts/

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Scala - jazyk budoucnosti