SlideShare a Scribd company logo
1 of 24
Download to read offline
Scala.js & friends
SCALA
ALL THE
THINGS
Chris Birchall
Content API team
Nightwatch
Nightwatch: a perfectly good app
● Node.js + Server Sent Events
● Concise, well written JavaScript
● Reliable
● Only one problem…
IT’S NOT
WRITTEN IN
SCALA
Scala.js to the rescue
● Compile Scala code to JS
○ Implemented as a compiler plugin
● Supports almost any Scala code
● Interop with 3rd-party JS libs
○ (with a bit of boilerplate)
● Generated JS size is not outrageous
○ Hello world is about 100k
Credit: scala-js.org
Hello world in 2 slides
Hello world in 2 slides
3rd-party JS interop
● Use js.Dynamic
○ i.e. throw type safety out of the window
○ Quick to write, feels like writing normal JS
● Write a Scala facade for your JS lib
○ Typesafe, assuming the facade matches the JS
js.Dynamic
Scala facade
Dependency management
● Facades can be published and shared
● Also support for WebJars
● The sbt plugin can write all deps to a single
.js file, à la browserify
libraryDependencies +=
"be.doeraene" %%% "scalajs-jquery" % "0.8.0"
TRIPLE SQUIGGLE!
<script src=”my-scalajs-app-jsdeps.js”></script>
<script src=”my-scalajs-app.js”></script>
Scala.js-ifying Nightwatch
● Untyped hashes → case classes
● Scala facades for moment.js, Rickshaw
● JS if/else chains → Scala pattern matching
● uPickle for JSON deserialization
Scala.js-ifying Nightwatch
Before 106 lines of JS After 216 lines of Scala
Facades
Case classes
Chained if/else -> pattern match
Before After
Problems along the way
● Obscure Scala.js bugs
○ e.g. .className doesn’t work sometimes
● Unexpected uPickle behaviour
● Trial and error getting facades to work
○ Gave up and settled on facade + Dynamic hybrid
● Brainmelt from Scala/JS context switching
○ e.g. trying to write Scala strings with single quotes
(All in all, > 5 hours to port 100 lines of code)
Credit: The Atlantic
Result: Kinda sorta typesafe JavaScript!
Hang on a sec
What’s this?
CSS?
But...
IT’S NOT
WRITTEN IN
SCALA
ScalaCSS to the rescue?
Erm, no.
DSL is virtually undocumented
Gave up after a bit of fruitless
trial and error.
Not quite ready for primetime.
On to the next victim
IT’S NOT
WRITTEN IN
SCALA
There, that’s better
http://lihaoyi.github.io/scalatags/
Conclusions
Should I use Scala to replace my ...
JavaScript Probably not.
Boilerplate and bugs outweigh type
safety benefits.
CSS Nope.
Just use Sass like everyone else.
HTML Maybe.
Scalatags could be useful as a
templating lang, to replace e.g. Scalate

More Related Content

What's hot

What's hot (20)

Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
 
The Modern Java Web Developer Bootcamp - Devoxx 2013
The Modern Java Web Developer Bootcamp - Devoxx 2013The Modern Java Web Developer Bootcamp - Devoxx 2013
The Modern Java Web Developer Bootcamp - Devoxx 2013
 
Scala for C# Developers
Scala for C# DevelopersScala for C# Developers
Scala for C# Developers
 
Scala,a practicle approach
Scala,a practicle approachScala,a practicle approach
Scala,a practicle approach
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Introduction to Knockout Js
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout Js
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
The evolution of Angular 2 @ AngularJS Munich Meetup #5
The evolution of Angular 2 @ AngularJS Munich Meetup #5The evolution of Angular 2 @ AngularJS Munich Meetup #5
The evolution of Angular 2 @ AngularJS Munich Meetup #5
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
JScala. Write your JavaScript in Scala
JScala. Write your JavaScript in ScalaJScala. Write your JavaScript in Scala
JScala. Write your JavaScript in Scala
 
xlab #7 - ReactJS & NodeJS
xlab #7 - ReactJS & NodeJSxlab #7 - ReactJS & NodeJS
xlab #7 - ReactJS & NodeJS
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Future
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
Javascript 01 (js)
Javascript 01 (js)Javascript 01 (js)
Javascript 01 (js)
 

Viewers also liked

AU2012_AB2006_presentation
AU2012_AB2006_presentationAU2012_AB2006_presentation
AU2012_AB2006_presentation
pchan925
 
Safety Supervisor & Advisor Cv.... (1)
Safety Supervisor &  Advisor Cv.... (1)Safety Supervisor &  Advisor Cv.... (1)
Safety Supervisor & Advisor Cv.... (1)
mohammad arman
 
Presentation_FINAL
Presentation_FINALPresentation_FINAL
Presentation_FINAL
Jessy Schott
 
Appendix A8_Excerpts from Project Delivery Strategy -Tower
Appendix A8_Excerpts from Project Delivery Strategy -TowerAppendix A8_Excerpts from Project Delivery Strategy -Tower
Appendix A8_Excerpts from Project Delivery Strategy -Tower
Richard D. Ochotorena
 
A Self-Assembling Curtain Wall System
A Self-Assembling Curtain Wall SystemA Self-Assembling Curtain Wall System
A Self-Assembling Curtain Wall System
elliando dias
 
Supervisor Safety Training 1
Supervisor Safety Training 1Supervisor Safety Training 1
Supervisor Safety Training 1
David Knight
 
industrialised building systems_achah
industrialised building systems_achahindustrialised building systems_achah
industrialised building systems_achah
Aisyah Asyikin
 

Viewers also liked (19)

Introduction to Quill
Introduction to QuillIntroduction to Quill
Introduction to Quill
 
Guess the Country - Playing with Twitter Streaming API
Guess the Country - Playing with Twitter Streaming APIGuess the Country - Playing with Twitter Streaming API
Guess the Country - Playing with Twitter Streaming API
 
AU2012_AB2006_presentation
AU2012_AB2006_presentationAU2012_AB2006_presentation
AU2012_AB2006_presentation
 
Safety Supervisor & Advisor Cv.... (1)
Safety Supervisor &  Advisor Cv.... (1)Safety Supervisor &  Advisor Cv.... (1)
Safety Supervisor & Advisor Cv.... (1)
 
Presentation_FINAL
Presentation_FINALPresentation_FINAL
Presentation_FINAL
 
Green Building Index & Universal Design
Green Building Index & Universal DesignGreen Building Index & Universal Design
Green Building Index & Universal Design
 
Fall Protection Guide
Fall Protection GuideFall Protection Guide
Fall Protection Guide
 
Appendix A8_Excerpts from Project Delivery Strategy -Tower
Appendix A8_Excerpts from Project Delivery Strategy -TowerAppendix A8_Excerpts from Project Delivery Strategy -Tower
Appendix A8_Excerpts from Project Delivery Strategy -Tower
 
Facility Fall Protection: Roof and Facade Maintenance
Facility Fall Protection: Roof and Facade MaintenanceFacility Fall Protection: Roof and Facade Maintenance
Facility Fall Protection: Roof and Facade Maintenance
 
Shanghai tower facade_design_process_11_10_2011
Shanghai tower facade_design_process_11_10_2011Shanghai tower facade_design_process_11_10_2011
Shanghai tower facade_design_process_11_10_2011
 
Installation techniques 07
Installation techniques 07Installation techniques 07
Installation techniques 07
 
Façades English Presentation
Façades English PresentationFaçades English Presentation
Façades English Presentation
 
A Self-Assembling Curtain Wall System
A Self-Assembling Curtain Wall SystemA Self-Assembling Curtain Wall System
A Self-Assembling Curtain Wall System
 
Supervisor Safety Training 1
Supervisor Safety Training 1Supervisor Safety Training 1
Supervisor Safety Training 1
 
Industrialised Building System report,
Industrialised Building System report, Industrialised Building System report,
Industrialised Building System report,
 
XSPlatforms - Facade Access Equipment
XSPlatforms - Facade Access EquipmentXSPlatforms - Facade Access Equipment
XSPlatforms - Facade Access Equipment
 
Designing and optimising a glass curtain wall facade
Designing and optimising a glass curtain wall facadeDesigning and optimising a glass curtain wall facade
Designing and optimising a glass curtain wall facade
 
Cleaning standard-operating-procedures
Cleaning standard-operating-proceduresCleaning standard-operating-procedures
Cleaning standard-operating-procedures
 
industrialised building systems_achah
industrialised building systems_achahindustrialised building systems_achah
industrialised building systems_achah
 

Similar to Scala.js & friends: SCALA ALL THE THINGS

Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
e-Legion
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
ssusercd195b
 

Similar to Scala.js & friends: SCALA ALL THE THINGS (20)

How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadius
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
Seastar / ScyllaDB, or how we implemented a 10-times faster Cassandra
Seastar / ScyllaDB,  or how we implemented a 10-times faster CassandraSeastar / ScyllaDB,  or how we implemented a 10-times faster Cassandra
Seastar / ScyllaDB, or how we implemented a 10-times faster Cassandra
 
Scala in a wild enterprise
Scala in a wild enterpriseScala in a wild enterprise
Scala in a wild enterprise
 
Scala.js
Scala.js Scala.js
Scala.js
 
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
 
2009 Eclipse Con
2009 Eclipse Con2009 Eclipse Con
2009 Eclipse Con
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
aws lambda & api gateway
aws lambda & api gatewayaws lambda & api gateway
aws lambda & api gateway
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
scala
scalascala
scala
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Clojure Lightning Talk
Clojure Lightning TalkClojure Lightning Talk
Clojure Lightning Talk
 
Lambda SnapStart - wellington meetup Apr-2024.pptx
Lambda SnapStart - wellington meetup Apr-2024.pptxLambda SnapStart - wellington meetup Apr-2024.pptx
Lambda SnapStart - wellington meetup Apr-2024.pptx
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software Systems
 
C* Summit 2013: Cassandra at Instagram by Rick Branson
C* Summit 2013: Cassandra at Instagram by Rick BransonC* Summit 2013: Cassandra at Instagram by Rick Branson
C* Summit 2013: Cassandra at Instagram by Rick Branson
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to Galera
 
Scala & Spark(1.6) in Performance Aspect for Scala Taiwan
Scala & Spark(1.6) in Performance Aspect for Scala TaiwanScala & Spark(1.6) in Performance Aspect for Scala Taiwan
Scala & Spark(1.6) in Performance Aspect for Scala Taiwan
 

More from Chris Birchall (10)

Rust 超入門
Rust 超入門Rust 超入門
Rust 超入門
 
Tour of Distributed Systems 3 - Apache Kafka
Tour of Distributed Systems 3 - Apache KafkaTour of Distributed Systems 3 - Apache Kafka
Tour of Distributed Systems 3 - Apache Kafka
 
Tour of distributed systems 2 - Cassandra
Tour of distributed systems 2 - CassandraTour of distributed systems 2 - Cassandra
Tour of distributed systems 2 - Cassandra
 
Tour of distributed systems 1 - ZooKeeper
Tour of distributed systems 1 - ZooKeeperTour of distributed systems 1 - ZooKeeper
Tour of distributed systems 1 - ZooKeeper
 
ScalaCache: simple caching in Scala
ScalaCache: simple caching in ScalaScalaCache: simple caching in Scala
ScalaCache: simple caching in Scala
 
Hydra
HydraHydra
Hydra
 
Load testing with gatling
Load testing with gatlingLoad testing with gatling
Load testing with gatling
 
Debugging and Testing ES Systems
Debugging and Testing ES SystemsDebugging and Testing ES Systems
Debugging and Testing ES Systems
 
Phone Home: A client-side error collection system
Phone Home: A client-side error collection systemPhone Home: A client-side error collection system
Phone Home: A client-side error collection system
 
Branching Strategies: Feature Branches vs Branch by Abstraction
Branching Strategies: Feature Branches vs Branch by AbstractionBranching Strategies: Feature Branches vs Branch by Abstraction
Branching Strategies: Feature Branches vs Branch by Abstraction
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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 future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Scala.js & friends: SCALA ALL THE THINGS