This will be a talk about a few past projects which, at least at first glance, might not seem like the best fit for Scala. A combination of language features and libraries enabled rapid development on each of these projects, while keeping the rate of bugs (relatively) low, and performance (relatively) high.
DevoxxFR 2024 Reproducible Builds with Apache Maven
Scala can do this, too
1. Scala can do this, too
Matic Potocnik @ Scala Slovenia, 08.09.2016
2. Overview of Projects
Projects we’ll look at today
• IRC Bot
• OCR Optimization
• Digital Art Installation
• Color Correction
1
3. IRC Bot - Overview
The usual bot features
• Greeting new users
• Passing messages to offline users
• Wordplay and telling jokes
• Posting to social media
• ...
2
5. IRC Bot - Scala
• Regex + Pattern matching
val cmd = "@([a-z]+) (.*)".r
input match {
case cmd("msg", message) =>
/*handle message*/
case cmd("retweet", url)
if (url.matches(Regexes.URL)) =>
/*handle url*/
/*more cases*/
}
4
6. OCR Optimizer - Context
Scanning books and documents
OCR is hard in general... but easier for e.g. a single scan job
Preprocessing
Thresholding, removing stains, rotating, ...
⇒
5
8. OCR Optimizer - Scala
• Futures
The next talk will tell you more...
I mostly used them to spawn processes,
and misused Await for process timeout
• Process
As easy as: s"tesseract-ocr $image".!!
Also supports pipes, redirects, &&, ||, ...
Better libraries such as lihaoyi/Ammonite exist
• rockymadden/stringmetric
String and phonetic similarity metrics
7
9. Digital Art Installation - Overview
Liminoid
by Sasa Spacal & Matic Potocnik
produced by: LJUDMILA
8
10. Digital Art Installation - Context
Software development in art
Frameworks and libraries exist for lots of stacks
I opted for Scala and LWJGL (plain OpenGL library)
Worked better than past projects (C++, VVVV, Python)
Art in software development
Very different process than developing software by spec,
not much attachment to already written code or style,
playing with code is important for project progress
9
11. Digital Art Installation - Animation
Animation player
A moving particle mandala proved too hard for video codecs,
and the player was rigid and hard to integrate with OpenGL,
so we wrote a player, which handled sequences of PNG files
10
12. Digital Art Installation - Performance
Performance Optimization
Hard to avoid noticeable pauses in VR
-XX:MaxGCPauseMillis to get frequent short GC pauses
Tried to keep variable scope and allocations to a minimum
Precomputing some things and reusing them
Future
Looking forward to improvements in 2.12 and Scala Native
11
13. Color Correction - Context
Color in the context of geology
Cheaply simplify and improve accuracy
0
5
10
15
Brez korekcije Premik Uteženo povpre je
Linearna kombinacija Linearna kombinacija II
12
14. Color Correction - Computer Vision
JavaCV
ASIFT algorithm to detect the color chart
13
15. Color Correction - GUI
Scala Swing
It’s nicer than Java Swing, if that counts
Terse nested syntax, some reactive features
Moved out of stdlib and deprecated now ⇒ ScalaFX exists
14
16. Color Correction - Conclusion
Why else Scala?
Color library easier to write with expressive type system
Making code parallel and fast is simple (tnx scala-blitz)
All Java libraries still available (Jrawio, JavaCV, ...)
Numeric math is easier to get right (tnx Breeze, tnx Linter ;))
15