SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
2019
Badr Baddou - Loïc Knuchel
@GraalSeeker @loicknuchel
@GraalSeeker
@loicknuchel
The ugly truth
Hello !
Badr Baddou
Scala dev @ Zeenea
@GraalSeeker
Loïc Knuchel
Tech lead @ Zeenea
@loicknuchel
Scala
FP
DDD
Property based testing
Your next data catalog
#Data
#Documentation
#Glossary
#Lineage
#Gouvernance
@GraalSeeker
@loicknuchel
Common bad practices
● Do not use null and throw
● Avoid isEmpty / get
● Ban symbols in function names
● Pay attention of primitive types use
● Do not let library conventions leak in your code
● DRY overuse
● Beware of mixing paradigms
@GraalSeeker
@loicknuchel
Primitive
obsession
● Primitive types: Int, String, Boolean…
● They do not carry semantics
○ Int, String vs FileSize, Bandwidth, RelPath, Email…
● They are indistinguishable
○ String <=> String vs UserId <!> CommentId
● You don’t known if they were validated
○ String/String vs Email/CheckedEmail
● You have no helper methods
○ path.split(“/”).dropRight(1).mkString(“/”) vs path.getParent()
@GraalSeeker
@loicknuchel
Library-
splaining
Write a wrapper to protect from library conventions
● Anti corruption layer (DDD)
● Do types conversions
○ null <=> Option
○ throw <=> Try, Either
○ Java collections <=> Scala collections
○ primitive types <=> dedicated types => Type Safety o/
○ Any <=> ADT
● Paradigm shifts
○ mutable <=> immutable
○ currying
○ sync <=> async (dedicated thread pool)
@GraalSeeker
@loicknuchel
Mixing
paradigms class User() {
def updatedAt(): Option[Instant] =
null
def validEmail(): Try[String] =
throw new IllegalArgumentException("Email is invalid")
}
@GraalSeeker
@loicknuchel
DRY
overuse
case class User(id: Option[String],
name: String,
email: Option[String] = None,
friends: Seq[String] = Seq(),
admin: Boolean = false)
case class UserCreation(name: String,
email: String)
case class User(id: String,
name: String,
email: String)
case class UserFull(id: String,
name: String,
email: String,
friends: Seq[String],
admin: Boolean)
@GraalSeeker
@loicknuchel
Real code is
(often) a mess
● very long
● inconsitencies
● over generalization (DRY)
@GraalSeeker
@loicknuchel
Conciseness
over
readability
val tuple: (Int, Int) =
Map("id" -> ("badr", 13))
.flatMap(e => List(e._2))
.map(_._2 + 1)
./:((0, 0))((a, b) => (a._1 - 1, a._2 + b))
● Conciseness ≠ Clarity
● No semantics
Symbols
Tuple
Bad naming
@GraalSeeker
@loicknuchel
Solution
val tuple: (Int, Int) =
Map("id" -> ("badr", 13))
.flatMap(e => List(e._2))
.map(_._2 + 1)
./:((0, 0))((a, b) => (a._1 - 1, a._2 + b))
case class User(name: String, age: Int)
val tuple2: (Int, Int) =
Map("id" -> User("badr", 13))
.flatMap { case (_, value) => List(value) }
.map(user => user.age + 1)
.foldLeft((0, 0))((acc, e) => (acc._1 - 1, acc._2 + e))
“The most common things you want to do should be the most concise,
while the less common things should be more verbose”
Lihayo
No symbols
Use class
not tuples
Named pattern matching
Named value
@GraalSeeker
@loicknuchel
Powerful
Feature
misuse
final case class Arc(name: String)
def main() {
Arc("zzz").show()
}
case class RichArc(value: Arc) {
def show() = s"${value.name} is a rich Arc"
}
implicit def richArc(arc: Arc): RichArc = RichArc(arc)
// Problem conversion can apply when not needed
def createRichArc(): RichArc = {
// conversion not needed here
Arc("aaa")
}
@GraalSeeker
@loicknuchel
Solution
object Syntax {
implicit case class EnrichArc(value: Arc) extends AnyVal {
def show() = s"${value.name} is a rich Arc"
}
}
def main() {
import Syntax._
Arc("zzz").show()
}
@GraalSeeker
@loicknuchel
Apply
misuse
def main(args: Array[String]): Unit = {
val arc = Arc("id", "name")
}
// returns RichArc !!!
object Arc {
def apply(id: String, name: String): RichArc = {
val (in, out) = nodeRepo.getNodes(id).get // throws :(
RichArc(id, name, in, out)
}
}
case class Node(id: String, name: String)
case class Arc(id: String, name: String)
case class RichArc(id: String,
name: String,
in: Option[Node],
out: Option[Node])
@GraalSeeker
@loicknuchel
Solution object Arc {
def apply(id: String, name: String): RichArc = {
val (in, out) = nodeRepo.getNodes(id).get // throws :(
RichArc(id, name, in, out)
}
}
case class NodeRepo() {
def getNodes(id: String): Try[(Option[Node], Option[Node])] = ???
}
object RichArc {
def from(id: String, name: String): Try[RichArc] = {
nodeRepo.getNodes(id).map { case (in, out) =>
RichArc(id, name, in, out)
}
}
}
@GraalSeeker
@loicknuchel
hide and seek
implicits
object App {
def main(args: Array[String]): Unit = {
val p: PropertyValue = 1
val q: PropertyValue = true
val r: PropertyValue = "toto"
}
}
package object propertyHelpers {
implicit def build(v: Any): PropertyValue =
PropertyValue(v)
}
// there should be some implicits here
// but no import
// where to look???
“Package objects can contain arbitrary definitions.
For instance, they are frequently used to hold
package-wide implicit conversions.”
https://docs.scala-lang.org/tour/package-objects.html
@GraalSeeker
@loicknuchel
Define operator
val name: Prop[String] = Prop("name", StrWrap)
val score: Prop[Int] = Prop("score", IntWrap)
val props = Props(
name -> "Jean",
score -> 10)
@GraalSeeker
@loicknuchel
How it
works?
val name: Prop[String] = Prop("name", StrWrap)
val score: Prop[Int] = Prop("score", IntWrap)
val props = Props(
name -> "Jean",
score -> 10)
case class Props(in: Map[Prop.Name, Prop.Value])
object Props {
def apply(in: (Prop.Name, Prop.Value)*): Props =
new Props(in.toMap)
}
// look for implicits
case class Prop[A](name:Name, wrap:Wrap[A]) {
def ->(value: A): (Prop.Name, Prop.Value) =
(name, wrap.encode(value))
}
@GraalSeeker
@loicknuchel
Resources
● https://github.com/loicknuchel/scala-bad-practices
● http://bit.ly/scala-bad-practices
● https://github.com/zeenea/scala-best-practices

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharphmanjarawala
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevJavaDayUA
 
GDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván ZaeraGDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván ZaeraJc Miñarro
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-CollectionsMohammad Shaker
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript Dhananjay Kumar
 
Contracts in-clojure-pete
Contracts in-clojure-peteContracts in-clojure-pete
Contracts in-clojure-petejessitron
 
Humane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development roomHumane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development roomTudor Girba
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipsePeter Friese
 

Was ist angesagt? (20)

Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
GDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván ZaeraGDG Madrid - Dart Event - By Iván Zaera
GDG Madrid - Dart Event - By Iván Zaera
 
Green dao
Green daoGreen dao
Green dao
 
J query1
J query1J query1
J query1
 
J query
J queryJ query
J query
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
C# 7
C# 7C# 7
C# 7
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
 
Contracts in-clojure-pete
Contracts in-clojure-peteContracts in-clojure-pete
Contracts in-clojure-pete
 
Green dao
Green daoGreen dao
Green dao
 
PDBC
PDBCPDBC
PDBC
 
Humane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development roomHumane assessment: Taming the elephant from the development room
Humane assessment: Taming the elephant from the development room
 
OOP v3
OOP v3OOP v3
OOP v3
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Collection v3
Collection v3Collection v3
Collection v3
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 

Ähnlich wie Scala bad practices, scala.io 2019

Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
Learning groovy -EU workshop
Learning groovy  -EU workshopLearning groovy  -EU workshop
Learning groovy -EU workshopadam1davis
 
TC39: How we work, what we are working on, and how you can get involved (dotJ...
TC39: How we work, what we are working on, and how you can get involved (dotJ...TC39: How we work, what we are working on, and how you can get involved (dotJ...
TC39: How we work, what we are working on, and how you can get involved (dotJ...Igalia
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrongJulien Wetterwald
 
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015Andrea Zaza
 
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Codeweek 2015 - Reactive Web Applications with Scala and LIFT frameworkCodeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Codeweek 2015 - Reactive Web Applications with Scala and LIFT frameworkRiccardo Sirigu
 
Understanding Connected Data through Visualization
Understanding Connected Data through VisualizationUnderstanding Connected Data through Visualization
Understanding Connected Data through VisualizationSebastian Müller
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to sparkDuyhai Doan
 
When RegEx is not enough
When RegEx is not enoughWhen RegEx is not enough
When RegEx is not enoughNati Cohen
 
Sorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifySorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifyNeville Li
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with framelessMiguel Pérez Pasalodos
 
Inductive Triple Graphs: A purely functional approach to represent RDF
Inductive Triple Graphs: A purely functional approach to represent RDFInductive Triple Graphs: A purely functional approach to represent RDF
Inductive Triple Graphs: A purely functional approach to represent RDFJose Emilio Labra Gayo
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturialWayne Tsai
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...Fwdays
 

Ähnlich wie Scala bad practices, scala.io 2019 (20)

Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
Learning groovy -EU workshop
Learning groovy  -EU workshopLearning groovy  -EU workshop
Learning groovy -EU workshop
 
TC39: How we work, what we are working on, and how you can get involved (dotJ...
TC39: How we work, what we are working on, and how you can get involved (dotJ...TC39: How we work, what we are working on, and how you can get involved (dotJ...
TC39: How we work, what we are working on, and how you can get involved (dotJ...
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
 
Geo data analytics
Geo data analyticsGeo data analytics
Geo data analytics
 
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
 
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Codeweek 2015 - Reactive Web Applications with Scala and LIFT frameworkCodeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
 
COLLADA & WebGL
COLLADA & WebGLCOLLADA & WebGL
COLLADA & WebGL
 
Understanding Connected Data through Visualization
Understanding Connected Data through VisualizationUnderstanding Connected Data through Visualization
Understanding Connected Data through Visualization
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
 
Fancy talk
Fancy talkFancy talk
Fancy talk
 
When RegEx is not enough
When RegEx is not enoughWhen RegEx is not enough
When RegEx is not enough
 
Sorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifySorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at Spotify
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with frameless
 
Inductive Triple Graphs: A purely functional approach to represent RDF
Inductive Triple Graphs: A purely functional approach to represent RDFInductive Triple Graphs: A purely functional approach to represent RDF
Inductive Triple Graphs: A purely functional approach to represent RDF
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 

Mehr von Loïc Knuchel

Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...Loïc Knuchel
 
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Loïc Knuchel
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Loïc Knuchel
 
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016Loïc Knuchel
 
FP is coming... le 19/05/2016
FP is coming... le 19/05/2016FP is coming... le 19/05/2016
FP is coming... le 19/05/2016Loïc Knuchel
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptLoïc Knuchel
 
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015Loïc Knuchel
 
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015Loïc Knuchel
 
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015Loïc Knuchel
 
Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015Loïc Knuchel
 
Devoxx 2015, ionic chat
Devoxx 2015, ionic chatDevoxx 2015, ionic chat
Devoxx 2015, ionic chatLoïc Knuchel
 
Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015Loïc Knuchel
 
Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Loïc Knuchel
 
Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014Loïc Knuchel
 

Mehr von Loïc Knuchel (14)

Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
Mutation testing, enfin une bonne mesure de la qualité des tests ?, RivieraDe...
 
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
 
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
Ionic2, les développeurs web à l'assaut du mobile, BDX I/O le 21/10/2016
 
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
Ionic2 - the raise of web developer, Riviera DEV le 17/06/2016
 
FP is coming... le 19/05/2016
FP is coming... le 19/05/2016FP is coming... le 19/05/2016
FP is coming... le 19/05/2016
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
Ionic Framework, L'avenir du mobile sera hybride, bdx.io le 16-10-2015
 
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
Ionic, ce n'est pas que de l'UI, meetup PhoneGap le 25-05-2015
 
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
Le développement mobile hybride sort du bois, Ch'ti JUG le 15-04-2015
 
Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015Devoxx 2015, Atelier Ionic - 09/04/2015
Devoxx 2015, Atelier Ionic - 09/04/2015
 
Devoxx 2015, ionic chat
Devoxx 2015, ionic chatDevoxx 2015, ionic chat
Devoxx 2015, ionic chat
 
Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015Ionic HumanTalks - 11/03/2015
Ionic HumanTalks - 11/03/2015
 
Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015Ionic bbl le 19 février 2015
Ionic bbl le 19 février 2015
 
Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014Des maths et des recommandations - Devoxx 2014
Des maths et des recommandations - Devoxx 2014
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 

Kürzlich hochgeladen (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

Scala bad practices, scala.io 2019

  • 1. 2019 Badr Baddou - Loïc Knuchel @GraalSeeker @loicknuchel
  • 3. Hello ! Badr Baddou Scala dev @ Zeenea @GraalSeeker Loïc Knuchel Tech lead @ Zeenea @loicknuchel Scala FP DDD Property based testing
  • 4. Your next data catalog #Data #Documentation #Glossary #Lineage #Gouvernance
  • 5. @GraalSeeker @loicknuchel Common bad practices ● Do not use null and throw ● Avoid isEmpty / get ● Ban symbols in function names ● Pay attention of primitive types use ● Do not let library conventions leak in your code ● DRY overuse ● Beware of mixing paradigms
  • 6. @GraalSeeker @loicknuchel Primitive obsession ● Primitive types: Int, String, Boolean… ● They do not carry semantics ○ Int, String vs FileSize, Bandwidth, RelPath, Email… ● They are indistinguishable ○ String <=> String vs UserId <!> CommentId ● You don’t known if they were validated ○ String/String vs Email/CheckedEmail ● You have no helper methods ○ path.split(“/”).dropRight(1).mkString(“/”) vs path.getParent()
  • 7. @GraalSeeker @loicknuchel Library- splaining Write a wrapper to protect from library conventions ● Anti corruption layer (DDD) ● Do types conversions ○ null <=> Option ○ throw <=> Try, Either ○ Java collections <=> Scala collections ○ primitive types <=> dedicated types => Type Safety o/ ○ Any <=> ADT ● Paradigm shifts ○ mutable <=> immutable ○ currying ○ sync <=> async (dedicated thread pool)
  • 8. @GraalSeeker @loicknuchel Mixing paradigms class User() { def updatedAt(): Option[Instant] = null def validEmail(): Try[String] = throw new IllegalArgumentException("Email is invalid") }
  • 9. @GraalSeeker @loicknuchel DRY overuse case class User(id: Option[String], name: String, email: Option[String] = None, friends: Seq[String] = Seq(), admin: Boolean = false) case class UserCreation(name: String, email: String) case class User(id: String, name: String, email: String) case class UserFull(id: String, name: String, email: String, friends: Seq[String], admin: Boolean)
  • 10. @GraalSeeker @loicknuchel Real code is (often) a mess ● very long ● inconsitencies ● over generalization (DRY)
  • 11. @GraalSeeker @loicknuchel Conciseness over readability val tuple: (Int, Int) = Map("id" -> ("badr", 13)) .flatMap(e => List(e._2)) .map(_._2 + 1) ./:((0, 0))((a, b) => (a._1 - 1, a._2 + b)) ● Conciseness ≠ Clarity ● No semantics Symbols Tuple Bad naming
  • 12. @GraalSeeker @loicknuchel Solution val tuple: (Int, Int) = Map("id" -> ("badr", 13)) .flatMap(e => List(e._2)) .map(_._2 + 1) ./:((0, 0))((a, b) => (a._1 - 1, a._2 + b)) case class User(name: String, age: Int) val tuple2: (Int, Int) = Map("id" -> User("badr", 13)) .flatMap { case (_, value) => List(value) } .map(user => user.age + 1) .foldLeft((0, 0))((acc, e) => (acc._1 - 1, acc._2 + e)) “The most common things you want to do should be the most concise, while the less common things should be more verbose” Lihayo No symbols Use class not tuples Named pattern matching Named value
  • 13. @GraalSeeker @loicknuchel Powerful Feature misuse final case class Arc(name: String) def main() { Arc("zzz").show() } case class RichArc(value: Arc) { def show() = s"${value.name} is a rich Arc" } implicit def richArc(arc: Arc): RichArc = RichArc(arc) // Problem conversion can apply when not needed def createRichArc(): RichArc = { // conversion not needed here Arc("aaa") }
  • 14. @GraalSeeker @loicknuchel Solution object Syntax { implicit case class EnrichArc(value: Arc) extends AnyVal { def show() = s"${value.name} is a rich Arc" } } def main() { import Syntax._ Arc("zzz").show() }
  • 15. @GraalSeeker @loicknuchel Apply misuse def main(args: Array[String]): Unit = { val arc = Arc("id", "name") } // returns RichArc !!! object Arc { def apply(id: String, name: String): RichArc = { val (in, out) = nodeRepo.getNodes(id).get // throws :( RichArc(id, name, in, out) } } case class Node(id: String, name: String) case class Arc(id: String, name: String) case class RichArc(id: String, name: String, in: Option[Node], out: Option[Node])
  • 16. @GraalSeeker @loicknuchel Solution object Arc { def apply(id: String, name: String): RichArc = { val (in, out) = nodeRepo.getNodes(id).get // throws :( RichArc(id, name, in, out) } } case class NodeRepo() { def getNodes(id: String): Try[(Option[Node], Option[Node])] = ??? } object RichArc { def from(id: String, name: String): Try[RichArc] = { nodeRepo.getNodes(id).map { case (in, out) => RichArc(id, name, in, out) } } }
  • 17. @GraalSeeker @loicknuchel hide and seek implicits object App { def main(args: Array[String]): Unit = { val p: PropertyValue = 1 val q: PropertyValue = true val r: PropertyValue = "toto" } } package object propertyHelpers { implicit def build(v: Any): PropertyValue = PropertyValue(v) } // there should be some implicits here // but no import // where to look??? “Package objects can contain arbitrary definitions. For instance, they are frequently used to hold package-wide implicit conversions.” https://docs.scala-lang.org/tour/package-objects.html
  • 18. @GraalSeeker @loicknuchel Define operator val name: Prop[String] = Prop("name", StrWrap) val score: Prop[Int] = Prop("score", IntWrap) val props = Props( name -> "Jean", score -> 10)
  • 19. @GraalSeeker @loicknuchel How it works? val name: Prop[String] = Prop("name", StrWrap) val score: Prop[Int] = Prop("score", IntWrap) val props = Props( name -> "Jean", score -> 10) case class Props(in: Map[Prop.Name, Prop.Value]) object Props { def apply(in: (Prop.Name, Prop.Value)*): Props = new Props(in.toMap) } // look for implicits case class Prop[A](name:Name, wrap:Wrap[A]) { def ->(value: A): (Prop.Name, Prop.Value) = (name, wrap.encode(value)) }
  • 20.
  • 21.