SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
Scala on Android
Android Development
●   Write lots of Java code
●   Write UI and other resources in XML
●   Generate Java code from resources
●   Compile Java code into “.class” files
●   Run proguard
●   Compile class files to Dalvik Executable (DEX)
●   Deploy on device
Dalvik VM
●   Does not support “.class” bytecode format
●   Can not use libraries which generate bytecode
●   Devices have limited CPU and Memory
●   Can not easily share libraries between
    applications
Eclipse
●   Has nice UI editors
●   IDE is a build tool
Alternative Languages for Android
Jython
●   Does not have enough community support
●   Slow
●   Dynamic
JRuby
●   Ruboto framework
●   Dynamic
●   Need to use java code generation
Clojure
●   Very cool :)
●   Very slow start-up time
●   Sometimes need to generate bytecode
PHP




Who cares?
Rhino
●   Nice language
●   Can run with optimization turned off
●   Completely interpreted
●   Dynamic
Groovy




 ???
Scala
●   Statically typed
●   Compiled to Java bytecode
●   Has access to all classes in Android
●   Fast
    ●   but sometimes slow :)
●   Has SBT
    ●   Android
    ●   Maven artifacts
How to build Scala apps for Android
●   ANT
●   Maven
●   SBT + Android Plugin
Little nice things about Scala
Type Inference
●   Improve readability
●   Reduce number of imports
●   Less typing
val stream = getAssets().open("areas.json")



        val stream: InputStream =
      getAssets().open("areas.json")
Import statement
import android.view.{
  Window, Menu, MenuItem, KeyEvent, View
}

import android.util.Log.{e => error}
Lazy vals
lazy val searchBox =
  findViewById(R.id.searchBox)
  .asInstanceOf[AutoCompleteTextView]
Mixin Inheritance
class MainActivity extends MapActivity
 with Logging
 with DatabaseHelpers
 with MapHelpers
Collections
●   Best collection library I ever used
    ●   Sorry google-collections...
●   Using arrays is easy
●   @specialized
Collection examples
val suggestions = areas map { _.name }
val index = areas.indexWhere(
  _.name == searchString
)

val index =
  areas.indexWhere(_.contains(coordinate))

pointList.minBy(_.lat)
First class functions
class AreaOverlay(
  areas: Array[Area],
  selectListener: Int => Unit
)

new AreaOverlay(
  areas, this.onAreaSelected
)
Convert listeners into functions
implicit def fn2ClickListener(
  f: View => Unit
): View.OnClickListener =
  new View.OnClickListener() {
     override def onClick(v: View) = f(view)
  }

exitButton.setOnClickListener(
 this.onExitClick
)
Files
●   Directory structure is not forced to mirror
    packages
●   Files can contain any amount of classes
Pattern matching
●   No NPEs when using Option[T]
●   Easy to work with data objects
Pattern matching
lastLocation match {
  case Some(c@Coordinate(lat, lon)) =>
    ...
  case None =>
    ...
}
Implicits
implicit def coordinate2geopoint(
  c: Coordinate
): GeoPoint = new GeoPoint(
  c.lat * 1.0e6 toInt, c.lon * 1.0e6 toInt
)
XML
for (s <- xml  "Document"  "Style")

placemarkElem  "Polygon" 
   "outerBoundaryIs"  "LinearRing" 
      "coordinates"
Bad stuff
●   Performance sensitive parts
    ●   Learn to use “javap”
    ●   Remove for-comprehensions and lambda functions
    ●   Do not use boxed types “by accident”
●   Tools
    ●   UI Editor
    ●   Debugger
    ●   Build time (dex'ing of scala library)
What I missed from Java
●   Google Guice
●   Maven
●   Good Eclipse integration
●   Feeling important...
Thank you!
Questions?

Mais conteúdo relacionado

Mais procurados

Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)Peter Arato
 
F# type providers
F# type providersF# type providers
F# type providersAntya Dev
 
Lightning talk: Kotlin
Lightning talk: KotlinLightning talk: Kotlin
Lightning talk: KotlinEvolve
 
Moving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xMoving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xSergey Rubanov
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Divedavanum
 
Why I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective CWhy I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective CSeniorDevOnly
 
Scala Code Analysis at Codacy
Scala Code Analysis at CodacyScala Code Analysis at Codacy
Scala Code Analysis at CodacyJohann Oikonomou
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scalaAlessandro Marrella
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?Alex Payne
 
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...Paris Open Source Summit
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features Florian Hopf
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with javaLiviu Tudor
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...DevClub_lv
 

Mais procurados (20)

Turbo charging v8 engine
Turbo charging v8 engineTurbo charging v8 engine
Turbo charging v8 engine
 
Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)Drupal and testing (2010 - 2011 / 2)
Drupal and testing (2010 - 2011 / 2)
 
C#
C#C#
C#
 
C#
C#C#
C#
 
C#
C#C#
C#
 
F# type providers
F# type providersF# type providers
F# type providers
 
Lightning talk: Kotlin
Lightning talk: KotlinLightning talk: Kotlin
Lightning talk: Kotlin
 
Moving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xMoving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201x
 
Oslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep DiveOslo.versioned objects - Deep Dive
Oslo.versioned objects - Deep Dive
 
Why I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective CWhy I don’t want to develop iOS apps in Objective C
Why I don’t want to develop iOS apps in Objective C
 
Realm database
Realm databaseRealm database
Realm database
 
Scala Code Analysis at Codacy
Scala Code Analysis at CodacyScala Code Analysis at Codacy
Scala Code Analysis at Codacy
 
Introduction to meta-programming in scala
Introduction to meta-programming in scalaIntroduction to meta-programming in scala
Introduction to meta-programming in scala
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
Metaprogramming with javascript
Metaprogramming with javascriptMetaprogramming with javascript
Metaprogramming with javascript
 
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...OWF12/PAUG Conf Days Dart   a new html5 technology, nicolas geoffray, softwar...
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features
 
React native
React nativeReact native
React native
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 

Semelhante a Scala on-android

Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioAhasan Habib
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming PatternsVasil Remeniuk
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Introducing Android Programming
Introducing Android ProgrammingIntroducing Android Programming
Introducing Android ProgrammingArif Huda
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015Jorg Janke
 
Google Dev Day2007
Google Dev Day2007Google Dev Day2007
Google Dev Day2007lucclaes
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
JVM languages "flame wars"
JVM languages "flame wars"JVM languages "flame wars"
JVM languages "flame wars"Gal Marder
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Kenneth Geisshirt
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeWaqqas Jabbar
 
React Native - performance optimization
React Native - performance optimizationReact Native - performance optimization
React Native - performance optimizationStas Doskalenko
 

Semelhante a Scala on-android (20)

Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Productivity Enhencement with Visual Studio
Productivity Enhencement with Visual StudioProductivity Enhencement with Visual Studio
Productivity Enhencement with Visual Studio
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
basic_java.ppt
basic_java.pptbasic_java.ppt
basic_java.ppt
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Introducing Android Programming
Introducing Android ProgrammingIntroducing Android Programming
Introducing Android Programming
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Google Dev Day2007
Google Dev Day2007Google Dev Day2007
Google Dev Day2007
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
JVM languages "flame wars"
JVM languages "flame wars"JVM languages "flame wars"
JVM languages "flame wars"
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
React Native - performance optimization
React Native - performance optimizationReact Native - performance optimization
React Native - performance optimization
 

Último

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Scala on-android

  • 2. Android Development ● Write lots of Java code ● Write UI and other resources in XML ● Generate Java code from resources ● Compile Java code into “.class” files ● Run proguard ● Compile class files to Dalvik Executable (DEX) ● Deploy on device
  • 3. Dalvik VM ● Does not support “.class” bytecode format ● Can not use libraries which generate bytecode ● Devices have limited CPU and Memory ● Can not easily share libraries between applications
  • 4. Eclipse ● Has nice UI editors ● IDE is a build tool
  • 6. Jython ● Does not have enough community support ● Slow ● Dynamic
  • 7. JRuby ● Ruboto framework ● Dynamic ● Need to use java code generation
  • 8. Clojure ● Very cool :) ● Very slow start-up time ● Sometimes need to generate bytecode
  • 10. Rhino ● Nice language ● Can run with optimization turned off ● Completely interpreted ● Dynamic
  • 12. Scala ● Statically typed ● Compiled to Java bytecode ● Has access to all classes in Android ● Fast ● but sometimes slow :) ● Has SBT ● Android ● Maven artifacts
  • 13. How to build Scala apps for Android ● ANT ● Maven ● SBT + Android Plugin
  • 14. Little nice things about Scala
  • 15. Type Inference ● Improve readability ● Reduce number of imports ● Less typing
  • 16. val stream = getAssets().open("areas.json") val stream: InputStream = getAssets().open("areas.json")
  • 17. Import statement import android.view.{ Window, Menu, MenuItem, KeyEvent, View } import android.util.Log.{e => error}
  • 18. Lazy vals lazy val searchBox = findViewById(R.id.searchBox) .asInstanceOf[AutoCompleteTextView]
  • 19. Mixin Inheritance class MainActivity extends MapActivity with Logging with DatabaseHelpers with MapHelpers
  • 20. Collections ● Best collection library I ever used ● Sorry google-collections... ● Using arrays is easy ● @specialized
  • 21. Collection examples val suggestions = areas map { _.name } val index = areas.indexWhere( _.name == searchString ) val index = areas.indexWhere(_.contains(coordinate)) pointList.minBy(_.lat)
  • 22. First class functions class AreaOverlay( areas: Array[Area], selectListener: Int => Unit ) new AreaOverlay( areas, this.onAreaSelected )
  • 23. Convert listeners into functions implicit def fn2ClickListener( f: View => Unit ): View.OnClickListener = new View.OnClickListener() { override def onClick(v: View) = f(view) } exitButton.setOnClickListener( this.onExitClick )
  • 24. Files ● Directory structure is not forced to mirror packages ● Files can contain any amount of classes
  • 25. Pattern matching ● No NPEs when using Option[T] ● Easy to work with data objects
  • 26. Pattern matching lastLocation match { case Some(c@Coordinate(lat, lon)) => ... case None => ... }
  • 27. Implicits implicit def coordinate2geopoint( c: Coordinate ): GeoPoint = new GeoPoint( c.lat * 1.0e6 toInt, c.lon * 1.0e6 toInt )
  • 28. XML for (s <- xml "Document" "Style") placemarkElem "Polygon" "outerBoundaryIs" "LinearRing" "coordinates"
  • 29. Bad stuff ● Performance sensitive parts ● Learn to use “javap” ● Remove for-comprehensions and lambda functions ● Do not use boxed types “by accident” ● Tools ● UI Editor ● Debugger ● Build time (dex'ing of scala library)
  • 30. What I missed from Java ● Google Guice ● Maven ● Good Eclipse integration ● Feeling important...