SlideShare a Scribd company logo
WHY SCALA IS NOT MY IDEAL LANGUAGE
Ruslan Shevchenko
https://github.com/rssh
@rssh1
AND WHAT I CAN DO WITH THIS
ANY SUFFICIENTLY ADVANCED DEVELOPMENT CONSIDERED HARMFUL
OVERVIEW
WHY SCALA IS NOT MY IDEAL LANGUAGE AND WHAT I CAN DO WITH THIS
• Implicit mismatch.
• inexistent ‘ideal’ solution
• ‘Cooperative’ solutions
• (ways to tell something to users of you code)
• Asynchronous programming
• Errors handling
• Async - the ideal way in ideal world and workarounds in real ;)
• Actors / Transputers
• Compiler
• Effects
• Extensibility
IMPLICIT MISMATCH
• Configuring runtime behaviour via implicit.
• Wildly used anti-pattern
• Mongo reactive-db driver
• Scala standard library.
MONGO SALACT CONTEXT
CONFIGURE RUNTIME BEHAVIOUR VIA IMPLICIT-S
import com.mongodb.casbah.Imports._
import com.novus.salat._
// import our context
import com.mycompany.salatcontext._
……
import com.mongodb.casbah.Imports._
import com.novus.salat._
// import standard context
import com.novus.salat.global._
……
File A:
File B:
SCALA STANDARD LIBRARY
CONFIGURE RUNTIME BEHAVIOUR VIA IMPLICIT-S
val zf = for( x <- XService.retrieve();
y <- YService.retrieve(x)
) yield
combine(x, y)
val z = Await(zf, 1 minute)
Q: Where it’s block ?
//note: slide changed, version shown during first presentation was without last line. [sorry].
and reference to full example.
//full example: http://bit.ly/1oPF5zM
WHAT TO DO ?
CONFIGURING RUNTIME BEHAVIOUR
• Do not use such libraries/frameworks (?)
• Block of imports as entity which possible to compose.
• require language changes
• motivation for @annotated imports pre-sip (2012)
• http://bit.ly/1NfVIej (proposal itself)
• patch against scalac & scaladoc 2.10
WHAT TO DO ?
CONFIGURING RUNTIME BEHAVIOUR
• Do not use such libraries/frameworks (?)
• Block of imports as entity which possible to compose.
• require language changes
• motivation for @annotated imports pre-sip (2012)
• http://bit.ly/1NfVIej (proposal itself)
• patch against scalac & scaladoc 2.10
EXAMPLE OF USAGE
ANNOTATED IMPORTS
object ConfiguredSalat {
@exported import com.mongodb.casbah.Imports._
@exported import com.novus.salat._
// our context
@exported import com.mycompany.salatcontext._
}
e ConfiguredSalat.scala
File A:
import com.mycompany.ConfiguredSalat._
……
File B:
import com.mycompany.ConfiguredSalat._
……
WHAT TO DO ?
CONFIGURING RUNTIME BEHAVIOUR
• Do not use such libraries/frameworks (?)
• Patch compiler.
// submitted pre-SIP was closed
as ‘too big change, maybe later’
WHAT TO DO ?
CONFIGURING RUNTIME BEHAVIOUR
• Do not use such libraries/frameworks (?)
• Patch compiler.
• Try not to write big programs.
• Provide wrapper which will force developers to read
docs ;))))
• FORCE USERS OF YOU WRAPPER TO UNDERSTAND PROBLEM
• ALLOW TO DO EVERYTHING
COOPERATIVE FIX
object ThinkAboutFuture {
implicit val `[implicit execution context is disabled]`:
ExecutionContext = ???
implicit val `(implicit execution context is disbled)`:
ExecutionContext = ???
implicit object knowledge
}
Config:
Service:
class MyCoreContext {
def baseService()
(implicit ThinkAboutFuture.knowledge.type):
Future[MyService] =
………
}
• FORCE USERS OF YOU WRAPPER TO UNDERSTAND PROBLEM
• ALLOW TO DO EVERYTHING
COOPERATIVE FIX
import ThinkAboutFuture._
object ReenableGlobalContext {
implicit def ec = ExecutionContext.Implicits.global._
………
}
not
• MORE ABOUT FUTURE
ASYNC PROGRAMMING
Future{
throw new RuntimeException(“Be-Be-Be!!!”)
}
- community accepted way to spawn task without return.
object FuturePlus {
def apply[T](body: =>T): Future[T] =
Future(body)(myEc)
def exec[T](body: =>T): Unit =
FuturePlus(body).onFailure{
case ex => handleException(_)
}(myEc)
}
// write own spawn methods
// use some lint tools, like wartremover
• MORE ABOUT FUTURE
ASYNC PROGRAMMING
Future{
throw new RuntimeException(“Be-Be-Be!!!”)
}
java.lang.RuntimeException: Be-Be-Be !!!
at x.Test$$anonfun$main$2.apply(X.scala:49)
at x.Test$$anonfun$main$2.apply(X.scala:47)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scal
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl
$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107
• MORE ABOUT FUTURE
ASYNC PROGRAMMING
- From where it was spawn ?
java.lang.RuntimeException: Be-Be-Be !!!
at x.Test$$anonfun$main$2.apply(X.scala:49)
at x.Test$$anonfun$main$2.apply(X.scala:47)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl
$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
- Can I see full stack-trace ?
// problem - that getting stack trace is expensive
TRACK FUTURE APPLY
• Let’s patch byte-code.
InvokeVirtual s/c/Future$ apply
(Ls/Function0;Ls/c/ExecutionContext;)Ls/c/Future
InvokeStatic t/TrackedFuture rapply
(Ls/c/Future;Ls/Function0;Ls/c/ExecutionContext;)Ls/c/Future
TRACK FUTURE APPLY
libraryDependencies += "com.github.rssh" %% "trackedfuture" % "0.1"
fork := true
javaOptions += s"""-javaagent:${System.getProperty("user.home")}/.ivy2/local/
com.github.rssh/trackedfuture_2.11/0.1/jars/trackedfuture_2.11.jar"""
small agent: https://github.com/rssh/trackedfuture
[error] java.lang.RuntimeException: Be-Be-Be !!!
[error] at x.Test$$anonfun$main$2.apply(X.scala:49)
[error] at x.Test$$anonfun$main$2.apply(X.scala:47)
[error] at trackedfuture.runtime.TrackedFuture$$anon$1.run(TrackedFuture.scala:21)
[error] at scala.concurrent.impl.ExecutionContextImpl
$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
[error] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
[error] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
[error] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
[error] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:
107)
[error] at java.lang.Thread.getStackTrace(Thread.java:1552)
[error] at trackedfuture.runtime.TrackedFuture$.apply(TrackedFuture.scala:13)
TRACK FUTURE APPLY
[error] java.lang.RuntimeException: Be-Be-Be !!!
[error] at x.Test$$anonfun$main$2.apply(X.scala:49)
[error] at x.Test$$anonfun$main$2.apply(X.scala:47)
[error] at trackedfuture.runtime.TrackedFuture$$anon$1.run(TrackedFuture.scala:2
[error] at scala.concurrent.impl.ExecutionContextImpl
$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
[error] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
[error] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool
[error] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:19
[error] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThre
107)
[error] at java.lang.Thread.getStackTrace(Thread.java:1552)
[error] at trackedfuture.runtime.TrackedFuture$.apply(TrackedFuture.scala:13)
[error] at trackedfuture.runtime.TrackedFuture$.rapply(TrackedFuture.scala:39)
[error] at trackedfuture.runtime.TrackedFuture.rapply(TrackedFuture.scala)
[error] at x.InDBFuture$.apply(X.scala:26)
[error] at x.InDBFuture$.exec(X.scala:29)
[error] at x.Test$.main(X.scala:47)
[error] at x.Test.main(X.scala)
[success] Total time: 1 s, completed Apr 9, 2016 2
ASYNC PROGRAMMING
Future is low-level interface,
like manual memory management in C
— configure execution context for db connections [1]
— spawn from Actor future with this db context [2]
— actually run query and retrieve the data [3]
— send retrieved data to place, where it can be used
(in map or to the same mailbox) [4]
How to retrieve data few times via SQL Query in Actor ?
4 steps, why not 1 ?
ASYNC PROGRAMMING
Future is low-level interface,
like manual memory management in C
Management execution flow: Async
• SIP-22
• transform code with async to state machine
val respFut = async {
val dayOfYear = await(futureDOY).body
val daysLeft = await(futureDaysLeft).body
Ok(s"$dayOfYear: $daysLeft days left!")
}
ASYNC
In ideal world, we should forget about Future and
use Async in business logic.
Async is a second-size citizen in scala.
• Luck of exception support // no technical reason for this.
• Luck of hight-level functions support
• still SIP, no 1.0 version
• expose set of macro/compiler bugs.
ASYNC => GO
ASYNC PROGRAMMING
def copy(inf: File, outf: File): Long =
goScope {
val in = new FileInputStream(inf)
defer{ in.close() }
val out = new FileOutputStream(outf);
defer{ out.close() }
out.getChannel() transferFrom(in.getChannel(), 0, Long.MaxV
}
• Part of scala-gopher:
• https://github.com/rssh/scala-gopher
• wrapper around async:
• defer instead try/catch/finally
• Hight-level function support
NOT IMPLEMENTED IDEAS ABOUT HIGHT-LEVEL FUNCTION
SUPPORT
ASYNC PROGRAMMING
async{
val l = for(i <- 1 to N) yield {
await(retrieve something i)
}
} IMPOSSIBLE
async{
var l = IndexedSeq[X]()
var i = 0
while(i < N) {
l += await(retrieve something i)
}
}
• Hight-level function support
• before generation of async, wrap type classes for well-
known hight-order functions:
• map( A (with awaits) ) => mapAsync(Future[A])
• allows to write own type classes
• when TASTY will be available: try to generate async
variants in simple cases.
NOT IMPLEMENTED IDEAS ABOUT HIGHT-LEVEL FUNCTION
SUPPORT
ASYNC PROGRAMMING
ASYNC
COMPILER SUPPORT
• can async be better integrated with compiler ?
• async is very low-level interface,
• like automatic memory management in C++
• Hight level way:
• Effects in type system.
• (X@Ex; Y@Ey) => Y @ (Ex+Ey) [in ideal world]
• (X; Y) => Y [ now ]
• ability to specialise execution context by effects.
// SCALA [Q PART]
• lim <?>
Hight-level DSL
Specialised DSL (Q, SQL)
Scala
Java/NPJava
C
ASM
// SCALA [Q PART]
• lim <?>
Hight-level DSL
Q
Scala
Java/NPJava
C
ASM
code <=> run time complexity
possible to track behaviour
looking at code
code =/= run time complexity
syntax sugar, implicits, std
// SCALA [Q PART]
• lim <?>
Hight-level DSL
Q
Scala
Java/NPJava
C
ASM
verbose API,
verbose imports
leaked low-level issues
Hight-level fluent API;
carefully optimised;
controlled low-level platform
// SCALA [Q PART]
• lim <?>
Hight-level DSL
Q
Scala
Java/NPJava
C
ASM
s.split(‘|’).toSeq flatMap (_.split(‘=‘)).
… verify that it-s int
…
(!/) “I=|”0:fix
// SCALA [Q PART]
• DSL construction: boilerplate factory
- Internal
- own set of types and globals;
- — no way to set precedence
- — manual construction
- — import needed postfix,
- macroses (limited).
- — awkward reflection API
- — traversing instead construction.
- — run after typing phase.
// SCALA [Q PART]
• Scala is one of my favourite languages.
• It can be sufficiently better.
• Maybe[support for compiler plugins]
• Any[sufficiently advanced development]
considered harmful
• Questions [?]; Ideas[?] ; — call me

More Related Content

What's hot (20)

PDF
[COSCUP 2020] How to use llvm frontend library-libtooling
Douglas Chen
 
PDF
JRuby 9000 - Optimizing Above the JVM
Charles Nutter
 
PPTX
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
ngotogenome
 
PPTX
Dive into ROP - a quick introduction to Return Oriented Programming
Saumil Shah
 
PDF
Return-Oriented Programming: Exploits Without Code Injection
guest9f4856
 
PPTX
Triton and Symbolic execution on GDB@DEF CON China
Wei-Bo Chen
 
PDF
Klee and angr
Wei-Bo Chen
 
PDF
java8-patterns
Justin Lin
 
PDF
The Parenscript Common Lisp to JavaScript compiler
Vladimir Sedach
 
PDF
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 
PPTX
From Ruby to Scala
tod esking
 
PDF
effective_r27
Hiroshi Ono
 
PDF
Taking Kotlin to production, Seriously
Haim Yadid
 
PDF
Building microservices with Kotlin
Haim Yadid
 
PDF
Introduction to Khronos SYCL
Min-Yih Hsu
 
PDF
Code lifecycle in the jvm - TopConf Linz
Ivan Krylov
 
PDF
What to expect from Java 9
Ivan Krylov
 
PPTX
Iron Languages - NYC CodeCamp 2/19/2011
Jimmy Schementi
 
PDF
parenscript-tutorial
tutorialsruby
 
PDF
TypeProf for IDE: Enrich Development Experience without Annotations
mametter
 
[COSCUP 2020] How to use llvm frontend library-libtooling
Douglas Chen
 
JRuby 9000 - Optimizing Above the JVM
Charles Nutter
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
ngotogenome
 
Dive into ROP - a quick introduction to Return Oriented Programming
Saumil Shah
 
Return-Oriented Programming: Exploits Without Code Injection
guest9f4856
 
Triton and Symbolic execution on GDB@DEF CON China
Wei-Bo Chen
 
Klee and angr
Wei-Bo Chen
 
java8-patterns
Justin Lin
 
The Parenscript Common Lisp to JavaScript compiler
Vladimir Sedach
 
Ruby Performance - The Last Mile - RubyConf India 2016
Charles Nutter
 
From Ruby to Scala
tod esking
 
effective_r27
Hiroshi Ono
 
Taking Kotlin to production, Seriously
Haim Yadid
 
Building microservices with Kotlin
Haim Yadid
 
Introduction to Khronos SYCL
Min-Yih Hsu
 
Code lifecycle in the jvm - TopConf Linz
Ivan Krylov
 
What to expect from Java 9
Ivan Krylov
 
Iron Languages - NYC CodeCamp 2/19/2011
Jimmy Schementi
 
parenscript-tutorial
tutorialsruby
 
TypeProf for IDE: Enrich Development Experience without Annotations
mametter
 

Similar to Why scala is not my ideal language and what I can do with this (20)

PPTX
Async fun
💡 Tomasz Kogut
 
PDF
Making our Future better
legendofklang
 
PDF
The Future starts with a Promise
Alexandru Nedelcu
 
PDF
Scala(e) to the large. Concurrent programming in Scala and relevant Frameworks
Gianluca Aguzzi
 
PDF
Pure Future
Wiem Zine Elabidine
 
PDF
Codemotion akka voló sobre el nido del future
Javier Santos Paniego
 
PDF
Codemotion 2015 - Akka voló sobre el nido del future
scalerablog
 
PDF
Monix : A Birds’ eye view
Knoldus Inc.
 
PDF
Back to the futures, actors and pipes: using Akka for large-scale data migration
Manuel Bernhardt
 
ODP
Scala Future & Promises
Knoldus Inc.
 
PDF
Introduction to Asynchronous scala
Stratio
 
PDF
Learning Concurrent Programming in Scala Second Edition Aleksandar Prokopec
trtekatsuro
 
PPT
Devoxx
Martin Odersky
 
PDF
Learning Concurrent Programming in Scala Second Edition Aleksandar Prokopec
imtiajvakto83
 
PDF
Scala.io
Steve Gury
 
PDF
Completable future
Srinivasan Raghvan
 
PDF
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan Shevchenko
 
PDF
Learning Concurrent Programming In Scala Second Edition 2nd Edition Aleksanda...
evilioverali
 
PDF
Learning Concurrent Programming in Scala Second Edition Aleksandar Prokopec
fryerlidoro
 
PDF
Principles of the Play framework
Bernhard Huemer
 
Making our Future better
legendofklang
 
The Future starts with a Promise
Alexandru Nedelcu
 
Scala(e) to the large. Concurrent programming in Scala and relevant Frameworks
Gianluca Aguzzi
 
Pure Future
Wiem Zine Elabidine
 
Codemotion akka voló sobre el nido del future
Javier Santos Paniego
 
Codemotion 2015 - Akka voló sobre el nido del future
scalerablog
 
Monix : A Birds’ eye view
Knoldus Inc.
 
Back to the futures, actors and pipes: using Akka for large-scale data migration
Manuel Bernhardt
 
Scala Future & Promises
Knoldus Inc.
 
Introduction to Asynchronous scala
Stratio
 
Learning Concurrent Programming in Scala Second Edition Aleksandar Prokopec
trtekatsuro
 
Learning Concurrent Programming in Scala Second Edition Aleksandar Prokopec
imtiajvakto83
 
Scala.io
Steve Gury
 
Completable future
Srinivasan Raghvan
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan Shevchenko
 
Learning Concurrent Programming In Scala Second Edition 2nd Edition Aleksanda...
evilioverali
 
Learning Concurrent Programming in Scala Second Edition Aleksandar Prokopec
fryerlidoro
 
Principles of the Play framework
Bernhard Huemer
 
Ad

More from Ruslan Shevchenko (20)

PDF
Embedding Generic Monadic Transformer into Scala. [Tfp2022]
Ruslan Shevchenko
 
PDF
Svitla talks 2021_03_25
Ruslan Shevchenko
 
PDF
Akka / Lts behavior
Ruslan Shevchenko
 
PDF
Papers We Love / Kyiv : PAXOS (and little about other consensuses )
Ruslan Shevchenko
 
PDF
Scala / Technology evolution
Ruslan Shevchenko
 
PDF
{co/contr} variance from LSP
Ruslan Shevchenko
 
PDF
N flavors of streaming
Ruslan Shevchenko
 
PDF
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Ruslan Shevchenko
 
PDF
Few simple-type-tricks in scala
Ruslan Shevchenko
 
PDF
Scala jargon cheatsheet
Ruslan Shevchenko
 
PDF
Java & low latency applications
Ruslan Shevchenko
 
PDF
Jslab rssh: JS as language platform
Ruslan Shevchenko
 
PDF
Behind OOD: domain modelling in post-OO world.
Ruslan Shevchenko
 
PDF
scala-gopher: async implementation of CSP for scala
Ruslan Shevchenko
 
PDF
Programming Languages: some news for the last N years
Ruslan Shevchenko
 
PDF
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
PDF
Web architecture - overview of techniques.
Ruslan Shevchenko
 
PDF
R scala 17_05_2014
Ruslan Shevchenko
 
ODP
Javascript in modern scala backend. [russian]
Ruslan Shevchenko
 
Embedding Generic Monadic Transformer into Scala. [Tfp2022]
Ruslan Shevchenko
 
Svitla talks 2021_03_25
Ruslan Shevchenko
 
Akka / Lts behavior
Ruslan Shevchenko
 
Papers We Love / Kyiv : PAXOS (and little about other consensuses )
Ruslan Shevchenko
 
Scala / Technology evolution
Ruslan Shevchenko
 
{co/contr} variance from LSP
Ruslan Shevchenko
 
N flavors of streaming
Ruslan Shevchenko
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Ruslan Shevchenko
 
Few simple-type-tricks in scala
Ruslan Shevchenko
 
Scala jargon cheatsheet
Ruslan Shevchenko
 
Java & low latency applications
Ruslan Shevchenko
 
Jslab rssh: JS as language platform
Ruslan Shevchenko
 
Behind OOD: domain modelling in post-OO world.
Ruslan Shevchenko
 
scala-gopher: async implementation of CSP for scala
Ruslan Shevchenko
 
Programming Languages: some news for the last N years
Ruslan Shevchenko
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
Web architecture - overview of techniques.
Ruslan Shevchenko
 
R scala 17_05_2014
Ruslan Shevchenko
 
Javascript in modern scala backend. [russian]
Ruslan Shevchenko
 
Ad

Recently uploaded (20)

PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 

Why scala is not my ideal language and what I can do with this

  • 1. WHY SCALA IS NOT MY IDEAL LANGUAGE Ruslan Shevchenko https://github.com/rssh @rssh1 AND WHAT I CAN DO WITH THIS
  • 2. ANY SUFFICIENTLY ADVANCED DEVELOPMENT CONSIDERED HARMFUL
  • 3. OVERVIEW WHY SCALA IS NOT MY IDEAL LANGUAGE AND WHAT I CAN DO WITH THIS • Implicit mismatch. • inexistent ‘ideal’ solution • ‘Cooperative’ solutions • (ways to tell something to users of you code) • Asynchronous programming • Errors handling • Async - the ideal way in ideal world and workarounds in real ;) • Actors / Transputers • Compiler • Effects • Extensibility
  • 4. IMPLICIT MISMATCH • Configuring runtime behaviour via implicit. • Wildly used anti-pattern • Mongo reactive-db driver • Scala standard library.
  • 5. MONGO SALACT CONTEXT CONFIGURE RUNTIME BEHAVIOUR VIA IMPLICIT-S import com.mongodb.casbah.Imports._ import com.novus.salat._ // import our context import com.mycompany.salatcontext._ …… import com.mongodb.casbah.Imports._ import com.novus.salat._ // import standard context import com.novus.salat.global._ …… File A: File B:
  • 6. SCALA STANDARD LIBRARY CONFIGURE RUNTIME BEHAVIOUR VIA IMPLICIT-S val zf = for( x <- XService.retrieve(); y <- YService.retrieve(x) ) yield combine(x, y) val z = Await(zf, 1 minute) Q: Where it’s block ? //note: slide changed, version shown during first presentation was without last line. [sorry]. and reference to full example. //full example: http://bit.ly/1oPF5zM
  • 7. WHAT TO DO ? CONFIGURING RUNTIME BEHAVIOUR • Do not use such libraries/frameworks (?) • Block of imports as entity which possible to compose. • require language changes • motivation for @annotated imports pre-sip (2012) • http://bit.ly/1NfVIej (proposal itself) • patch against scalac & scaladoc 2.10
  • 8. WHAT TO DO ? CONFIGURING RUNTIME BEHAVIOUR • Do not use such libraries/frameworks (?) • Block of imports as entity which possible to compose. • require language changes • motivation for @annotated imports pre-sip (2012) • http://bit.ly/1NfVIej (proposal itself) • patch against scalac & scaladoc 2.10
  • 9. EXAMPLE OF USAGE ANNOTATED IMPORTS object ConfiguredSalat { @exported import com.mongodb.casbah.Imports._ @exported import com.novus.salat._ // our context @exported import com.mycompany.salatcontext._ } e ConfiguredSalat.scala File A: import com.mycompany.ConfiguredSalat._ …… File B: import com.mycompany.ConfiguredSalat._ ……
  • 10. WHAT TO DO ? CONFIGURING RUNTIME BEHAVIOUR • Do not use such libraries/frameworks (?) • Patch compiler. // submitted pre-SIP was closed as ‘too big change, maybe later’
  • 11. WHAT TO DO ? CONFIGURING RUNTIME BEHAVIOUR • Do not use such libraries/frameworks (?) • Patch compiler. • Try not to write big programs. • Provide wrapper which will force developers to read docs ;))))
  • 12. • FORCE USERS OF YOU WRAPPER TO UNDERSTAND PROBLEM • ALLOW TO DO EVERYTHING COOPERATIVE FIX object ThinkAboutFuture { implicit val `[implicit execution context is disabled]`: ExecutionContext = ??? implicit val `(implicit execution context is disbled)`: ExecutionContext = ??? implicit object knowledge } Config: Service: class MyCoreContext { def baseService() (implicit ThinkAboutFuture.knowledge.type): Future[MyService] = ……… }
  • 13. • FORCE USERS OF YOU WRAPPER TO UNDERSTAND PROBLEM • ALLOW TO DO EVERYTHING COOPERATIVE FIX import ThinkAboutFuture._ object ReenableGlobalContext { implicit def ec = ExecutionContext.Implicits.global._ ……… } not
  • 14. • MORE ABOUT FUTURE ASYNC PROGRAMMING Future{ throw new RuntimeException(“Be-Be-Be!!!”) } - community accepted way to spawn task without return. object FuturePlus { def apply[T](body: =>T): Future[T] = Future(body)(myEc) def exec[T](body: =>T): Unit = FuturePlus(body).onFailure{ case ex => handleException(_) }(myEc) } // write own spawn methods // use some lint tools, like wartremover
  • 15. • MORE ABOUT FUTURE ASYNC PROGRAMMING Future{ throw new RuntimeException(“Be-Be-Be!!!”) } java.lang.RuntimeException: Be-Be-Be !!! at x.Test$$anonfun$main$2.apply(X.scala:49) at x.Test$$anonfun$main$2.apply(X.scala:47) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scal at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at scala.concurrent.impl.ExecutionContextImpl $AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107
  • 16. • MORE ABOUT FUTURE ASYNC PROGRAMMING - From where it was spawn ? java.lang.RuntimeException: Be-Be-Be !!! at x.Test$$anonfun$main$2.apply(X.scala:49) at x.Test$$anonfun$main$2.apply(X.scala:47) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24 at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at scala.concurrent.impl.ExecutionContextImpl $AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) - Can I see full stack-trace ? // problem - that getting stack trace is expensive
  • 17. TRACK FUTURE APPLY • Let’s patch byte-code. InvokeVirtual s/c/Future$ apply (Ls/Function0;Ls/c/ExecutionContext;)Ls/c/Future InvokeStatic t/TrackedFuture rapply (Ls/c/Future;Ls/Function0;Ls/c/ExecutionContext;)Ls/c/Future
  • 18. TRACK FUTURE APPLY libraryDependencies += "com.github.rssh" %% "trackedfuture" % "0.1" fork := true javaOptions += s"""-javaagent:${System.getProperty("user.home")}/.ivy2/local/ com.github.rssh/trackedfuture_2.11/0.1/jars/trackedfuture_2.11.jar""" small agent: https://github.com/rssh/trackedfuture [error] java.lang.RuntimeException: Be-Be-Be !!! [error] at x.Test$$anonfun$main$2.apply(X.scala:49) [error] at x.Test$$anonfun$main$2.apply(X.scala:47) [error] at trackedfuture.runtime.TrackedFuture$$anon$1.run(TrackedFuture.scala:21) [error] at scala.concurrent.impl.ExecutionContextImpl $AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) [error] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [error] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [error] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [error] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java: 107) [error] at java.lang.Thread.getStackTrace(Thread.java:1552) [error] at trackedfuture.runtime.TrackedFuture$.apply(TrackedFuture.scala:13)
  • 19. TRACK FUTURE APPLY [error] java.lang.RuntimeException: Be-Be-Be !!! [error] at x.Test$$anonfun$main$2.apply(X.scala:49) [error] at x.Test$$anonfun$main$2.apply(X.scala:47) [error] at trackedfuture.runtime.TrackedFuture$$anon$1.run(TrackedFuture.scala:2 [error] at scala.concurrent.impl.ExecutionContextImpl $AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) [error] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [error] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool [error] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:19 [error] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThre 107) [error] at java.lang.Thread.getStackTrace(Thread.java:1552) [error] at trackedfuture.runtime.TrackedFuture$.apply(TrackedFuture.scala:13) [error] at trackedfuture.runtime.TrackedFuture$.rapply(TrackedFuture.scala:39) [error] at trackedfuture.runtime.TrackedFuture.rapply(TrackedFuture.scala) [error] at x.InDBFuture$.apply(X.scala:26) [error] at x.InDBFuture$.exec(X.scala:29) [error] at x.Test$.main(X.scala:47) [error] at x.Test.main(X.scala) [success] Total time: 1 s, completed Apr 9, 2016 2
  • 20. ASYNC PROGRAMMING Future is low-level interface, like manual memory management in C — configure execution context for db connections [1] — spawn from Actor future with this db context [2] — actually run query and retrieve the data [3] — send retrieved data to place, where it can be used (in map or to the same mailbox) [4] How to retrieve data few times via SQL Query in Actor ? 4 steps, why not 1 ?
  • 21. ASYNC PROGRAMMING Future is low-level interface, like manual memory management in C Management execution flow: Async • SIP-22 • transform code with async to state machine val respFut = async { val dayOfYear = await(futureDOY).body val daysLeft = await(futureDaysLeft).body Ok(s"$dayOfYear: $daysLeft days left!") }
  • 22. ASYNC In ideal world, we should forget about Future and use Async in business logic. Async is a second-size citizen in scala. • Luck of exception support // no technical reason for this. • Luck of hight-level functions support • still SIP, no 1.0 version • expose set of macro/compiler bugs.
  • 23. ASYNC => GO ASYNC PROGRAMMING def copy(inf: File, outf: File): Long = goScope { val in = new FileInputStream(inf) defer{ in.close() } val out = new FileOutputStream(outf); defer{ out.close() } out.getChannel() transferFrom(in.getChannel(), 0, Long.MaxV } • Part of scala-gopher: • https://github.com/rssh/scala-gopher • wrapper around async: • defer instead try/catch/finally
  • 24. • Hight-level function support NOT IMPLEMENTED IDEAS ABOUT HIGHT-LEVEL FUNCTION SUPPORT ASYNC PROGRAMMING async{ val l = for(i <- 1 to N) yield { await(retrieve something i) } } IMPOSSIBLE async{ var l = IndexedSeq[X]() var i = 0 while(i < N) { l += await(retrieve something i) } }
  • 25. • Hight-level function support • before generation of async, wrap type classes for well- known hight-order functions: • map( A (with awaits) ) => mapAsync(Future[A]) • allows to write own type classes • when TASTY will be available: try to generate async variants in simple cases. NOT IMPLEMENTED IDEAS ABOUT HIGHT-LEVEL FUNCTION SUPPORT ASYNC PROGRAMMING
  • 26. ASYNC COMPILER SUPPORT • can async be better integrated with compiler ? • async is very low-level interface, • like automatic memory management in C++ • Hight level way: • Effects in type system. • (X@Ex; Y@Ey) => Y @ (Ex+Ey) [in ideal world] • (X; Y) => Y [ now ] • ability to specialise execution context by effects.
  • 27. // SCALA [Q PART] • lim <?> Hight-level DSL Specialised DSL (Q, SQL) Scala Java/NPJava C ASM
  • 28. // SCALA [Q PART] • lim <?> Hight-level DSL Q Scala Java/NPJava C ASM code <=> run time complexity possible to track behaviour looking at code code =/= run time complexity syntax sugar, implicits, std
  • 29. // SCALA [Q PART] • lim <?> Hight-level DSL Q Scala Java/NPJava C ASM verbose API, verbose imports leaked low-level issues Hight-level fluent API; carefully optimised; controlled low-level platform
  • 30. // SCALA [Q PART] • lim <?> Hight-level DSL Q Scala Java/NPJava C ASM s.split(‘|’).toSeq flatMap (_.split(‘=‘)). … verify that it-s int … (!/) “I=|”0:fix
  • 31. // SCALA [Q PART] • DSL construction: boilerplate factory - Internal - own set of types and globals; - — no way to set precedence - — manual construction - — import needed postfix, - macroses (limited). - — awkward reflection API - — traversing instead construction. - — run after typing phase.
  • 32. // SCALA [Q PART] • Scala is one of my favourite languages. • It can be sufficiently better. • Maybe[support for compiler plugins] • Any[sufficiently advanced development] considered harmful • Questions [?]; Ideas[?] ; — call me