SlideShare a Scribd company logo
1 of 22
Download to read offline
The Scalactic Way
ScalaDays 2015, San Francisco
BillVenners
Artima, Inc.
Escalate Software
Use types to achieve quality.
The Scalactic Way
Three prongs of the quality pitchfork
ScalaTest - quality through tests
Scalactic - quality through types
SuperSafe - quality through static analysis
Scalactic Anyvals
// n > 0
PosInt
PosLong
PosFloat
PosDouble
// n >= 0
PosZInt
PosZLong
PosZFloat
PosZDouble
Demo!
case class PropertyCheckConfig(
  minSuccessful: Int = 100,
  maxDiscarded: Int = 500,
  minSize: Int = 0,
  maxSize: Int = 100,
  workers: Int = 1
) {
  require(minSuccessful > 0, "minSuccessful had value " +
minSuccessful + ", but must be greater than zero")
  require(maxDiscarded >= 0, "maxDiscarded had value " +
maxDiscarded + ", but must be greater than or equal to zero")
  require(minSize >= 0, "minSize had value " + minSize +
", but must be greater than or equal to zero")
  require(maxSize >= 0, "maxSize had value " + maxSize +
", but must be greater than or equal to zero")
  require(minSize <= maxSize, "minSize had value " + minSize +
", which must be less than or equal to maxSize, which had value " + maxSize)
  require(workers > 0, "workers had value " + workers +
", but must be greater than zero")
}
PropertyCheckConfig
case class PropertyCheckConfiguration(
  minSuccessful: PosInt = 100,
  maxDiscardedFactor: PosZDouble = 5.0, // This changed in ScalaCheck
  minSize: PosZInt = 0,
  maxSize: PosZInt = 100,
  workers: PosInt = 1
) {
  require(minSize <= maxSize, "minSize had value " + minSize +
", which must be less than or equal to maxSize, which had value " + maxSize)
}
PropertyCheckConfiguration
case class PropertyCheckConfiguration(
  minSuccessful: PosInt = 100,
  maxDiscardedFactor: PosZDouble = 5,
  minSize: PosZInt = 0,
  sizeRange: PosZInt = 101,
  workers: PosInt = 1
)
PropertyCheckConfiguration
intercept[IllegalArgumentException] {
PropertyCheckConfiguration(
  minSuccessful = 0
)
}
intercept[IllegalArgumentException] {
PropertyCheckConfiguration(
  minSuccessful = -1
)
}
Don’t need these tests
final class EvenInt private (val value: Int) extends AnyVal {
override def toString: String = s"EvenInt($value)"
}
object EvenInt {
def from(value: Int): Option[EvenInt] =
if (value % 2 == 1) Some(new EvenInt(value)) else None
def apply(value: Int): EvenInt = macro EvenIntMacro.apply
}
Roll your own
with
compile-time
assertions
final class EvenInt private (val value: Int) extends AnyVal {
override def toString: String = s"EvenInt($value)"
}
object EvenInt {
def from(value: Int): Option[EvenInt] =
if (value % 2 == 0) Some(new EvenInt(value)) else None
def apply(value: Int): EvenInt = macro EvenIntMacro.apply
}
object EvenIntMacro extends CompileTimeAssertions {
def apply(c: Context)(value: c.Expr[Int]): c.Expr[EvenInt] = {
val notValidMsg = "EvenInt.apply can only be invoked on even Int literals, like EvenInt(3)."
val notLiteralMsg = "EveInt.apply can only be invoked on Int literals, like " +
"EvenInt(3). Please use EvenInt.from instead."
ensureValidIntLiteral(c)(value, notValidMsg, notLiteralMsg) { i => i % 2 == 1 }
c.universe.reify { EvenInt.from(value.splice).get }
}
}
Roll your own
with
compile-time
assertions
def half(even: Int): Int = {
require(even % 2 == 0, s"$even was not even")
even / 2
}
def half(even: EvenInt): Int = {
// Why no require here?
even / 2
}
Use types where practical to focus
and reduce the need for tests
(both assert and require).
The Scalactic Way
Stories!
Safety, but complexity// ScalaTest 2.0
scala> equal("one")
res0: MatcherFactory1[Any,Equality] = equal ("one")
// ScalaTest 3.0
scala> equal("one")
res0: MatcherFactory1[Any,EvidenceThat[String]#CanEqual] = equal ("one")
Safety, but complexity// ScalaTest 2.0
scala> equal ("one")
res0: MatcherFactory1[Any,Equality] = equal ("one")
// ScalaTest 3.0
scala> equal("one")
res0: MatcherFactory1[Any,EvidenceThat[String]#CanEqual] = equal ("one")
// ScalaTest 2.0
scala> Some("one") should (be (defined) and not equal "one")
// ScalaTest 3.0
scala> Some("one") should (be (defined) and not equal "one")
<console>:20: error: could not find implicit value for parameter typeClass2:
org.scalactic.enablers.EvidenceThat[String]#CanEqual[Some[String]]
Some("one") should not equal "one"
^
Let’s graph something!
The Scalactic Way
The type system does not offer the
best solution to every problem.
The SuperSafe Way
- Can run all the time
- Doesn’t hurt compile time
- No warnings, only errors
- Not a linter; a “Scala subset policy enforcer”
artima.com/flyer
SuperSafe, Escalate Stairway to Scala training


50% discount
at Artima booth
Q => A

More Related Content

What's hot

JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineRaimonds Simanovskis
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Roy Yu
 
Mirage For Beginners
Mirage For BeginnersMirage For Beginners
Mirage For BeginnersWilson Su
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyIgor Napierala
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with JasmineTim Tyrrell
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingLars Thorup
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mochaRevath S Kumar
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncArtur Szott
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewAngular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewThirumal Sakthivel
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaChristopher Bartling
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsMihail Gaberov
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategiesnjpst8
 
MeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentMeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentArtur Szott
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Morris Singer
 
Practical JavaScript Promises
Practical JavaScript PromisesPractical JavaScript Promises
Practical JavaScript PromisesAsa Kusuma
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observablesStefan Charsley
 

What's hot (20)

JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Mirage For Beginners
Mirage For BeginnersMirage For Beginners
Mirage For Beginners
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with Async
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewAngular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategies
 
MeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentMeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenment
 
Full Stack Unit Testing
Full Stack Unit TestingFull Stack Unit Testing
Full Stack Unit Testing
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
 
Practical JavaScript Promises
Practical JavaScript PromisesPractical JavaScript Promises
Practical JavaScript Promises
 
Week6
Week6Week6
Week6
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 

Viewers also liked

How to get fit for halloween
How to get fit for halloweenHow to get fit for halloween
How to get fit for halloweenAndrew Barnett
 
Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...
Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...
Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...Global Water Initiative - West Africa
 
Kasus bunuh diri di korea selatan
Kasus bunuh diri di korea selatanKasus bunuh diri di korea selatan
Kasus bunuh diri di korea selatansepta0209
 
Kids collection In Chennai
Kids collection In ChennaiKids collection In Chennai
Kids collection In Chennaisaree123
 
Rollin & Co Presents
Rollin & Co PresentsRollin & Co Presents
Rollin & Co PresentsRichard Lim
 
ผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหารผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหารsuwananfangsub
 
Accessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOC
Accessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOCAccessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOC
Accessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOCFrancisco Iniesto
 
Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...
Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...
Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...Global Water Initiative - West Africa
 
An Introduction to Climate Change - Grand Junction
An Introduction to Climate Change - Grand JunctionAn Introduction to Climate Change - Grand Junction
An Introduction to Climate Change - Grand JunctionConservationColorado
 
Evaluations économiques des barrages: Réflexions sur les choix de développement
Evaluations économiques des barrages: Réflexions sur les choix de développementEvaluations économiques des barrages: Réflexions sur les choix de développement
Evaluations économiques des barrages: Réflexions sur les choix de développementGlobal Water Initiative - West Africa
 
voskresenochka obrazovatelnaya programma
voskresenochka obrazovatelnaya programmavoskresenochka obrazovatelnaya programma
voskresenochka obrazovatelnaya programmaYana Mazurova
 
Iisrt akshata ht
Iisrt akshata htIisrt akshata ht
Iisrt akshata htIISRT
 
ผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหารผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหารsuwananfangsub
 

Viewers also liked (15)

How to get fit for halloween
How to get fit for halloweenHow to get fit for halloween
How to get fit for halloween
 
Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...
Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...
Le barrage de Diama (Sénégal): Evaluation des avantages sociaux et environnem...
 
Kasus bunuh diri di korea selatan
Kasus bunuh diri di korea selatanKasus bunuh diri di korea selatan
Kasus bunuh diri di korea selatan
 
Used to
Used to   Used to
Used to
 
Kids collection In Chennai
Kids collection In ChennaiKids collection In Chennai
Kids collection In Chennai
 
Rollin & Co Presents
Rollin & Co PresentsRollin & Co Presents
Rollin & Co Presents
 
ผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหารผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหาร
 
Accessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOC
Accessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOCAccessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOC
Accessibility analysis in MOOC platforms. A case study: UNED COMA and UAb iMOOC
 
Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...
Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...
Etude comparative de la valeur actuelle des barrages de Niandouba et Confluen...
 
An Introduction to Climate Change - Grand Junction
An Introduction to Climate Change - Grand JunctionAn Introduction to Climate Change - Grand Junction
An Introduction to Climate Change - Grand Junction
 
Evaluations économiques des barrages: Réflexions sur les choix de développement
Evaluations économiques des barrages: Réflexions sur les choix de développementEvaluations économiques des barrages: Réflexions sur les choix de développement
Evaluations économiques des barrages: Réflexions sur les choix de développement
 
voskresenochka obrazovatelnaya programma
voskresenochka obrazovatelnaya programmavoskresenochka obrazovatelnaya programma
voskresenochka obrazovatelnaya programma
 
Iisrt akshata ht
Iisrt akshata htIisrt akshata ht
Iisrt akshata ht
 
Ohio driving school
Ohio driving schoolOhio driving school
Ohio driving school
 
ผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหารผลิตภัณฑ์เสริมอาหาร
ผลิตภัณฑ์เสริมอาหาร
 

Similar to The Scalactic Way

JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesCody Yun
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based TestingC4Media
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive ShellGiovanni Lodi
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testingVincent Pradeilles
 
Test driven node.js
Test driven node.jsTest driven node.js
Test driven node.jsJay Harris
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka codeMykhailo Kotsur
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...Databricks
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...Matthew Tovbin
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42Yevhen Bobrov
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 

Similar to The Scalactic Way (20)

Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Mockito intro
Mockito introMockito intro
Mockito intro
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based Testing
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive Shell
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
Property Based Testing
Property Based TestingProperty Based Testing
Property Based Testing
 
Test driven node.js
Test driven node.jsTest driven node.js
Test driven node.js
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka code
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
iOS Talks 6: Unit Testing
iOS Talks 6: Unit TestingiOS Talks 6: Unit Testing
iOS Talks 6: Unit Testing
 
ppopoff
ppopoffppopoff
ppopoff
 
Qtp test
Qtp testQtp test
Qtp test
 

Recently uploaded

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
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
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
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
 
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
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
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
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
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
 
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
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

The Scalactic Way

  • 1. The Scalactic Way ScalaDays 2015, San Francisco BillVenners Artima, Inc. Escalate Software
  • 2. Use types to achieve quality. The Scalactic Way
  • 3. Three prongs of the quality pitchfork ScalaTest - quality through tests Scalactic - quality through types SuperSafe - quality through static analysis
  • 4. Scalactic Anyvals // n > 0 PosInt PosLong PosFloat PosDouble // n >= 0 PosZInt PosZLong PosZFloat PosZDouble
  • 6. case class PropertyCheckConfig(   minSuccessful: Int = 100,   maxDiscarded: Int = 500,   minSize: Int = 0,   maxSize: Int = 100,   workers: Int = 1 ) {   require(minSuccessful > 0, "minSuccessful had value " + minSuccessful + ", but must be greater than zero")   require(maxDiscarded >= 0, "maxDiscarded had value " + maxDiscarded + ", but must be greater than or equal to zero")   require(minSize >= 0, "minSize had value " + minSize + ", but must be greater than or equal to zero")   require(maxSize >= 0, "maxSize had value " + maxSize + ", but must be greater than or equal to zero")   require(minSize <= maxSize, "minSize had value " + minSize + ", which must be less than or equal to maxSize, which had value " + maxSize)   require(workers > 0, "workers had value " + workers + ", but must be greater than zero") } PropertyCheckConfig
  • 7. case class PropertyCheckConfiguration(   minSuccessful: PosInt = 100,   maxDiscardedFactor: PosZDouble = 5.0, // This changed in ScalaCheck   minSize: PosZInt = 0,   maxSize: PosZInt = 100,   workers: PosInt = 1 ) {   require(minSize <= maxSize, "minSize had value " + minSize + ", which must be less than or equal to maxSize, which had value " + maxSize) } PropertyCheckConfiguration
  • 8. case class PropertyCheckConfiguration(   minSuccessful: PosInt = 100,   maxDiscardedFactor: PosZDouble = 5,   minSize: PosZInt = 0,   sizeRange: PosZInt = 101,   workers: PosInt = 1 ) PropertyCheckConfiguration
  • 9. intercept[IllegalArgumentException] { PropertyCheckConfiguration(   minSuccessful = 0 ) } intercept[IllegalArgumentException] { PropertyCheckConfiguration(   minSuccessful = -1 ) } Don’t need these tests
  • 10. final class EvenInt private (val value: Int) extends AnyVal { override def toString: String = s"EvenInt($value)" } object EvenInt { def from(value: Int): Option[EvenInt] = if (value % 2 == 1) Some(new EvenInt(value)) else None def apply(value: Int): EvenInt = macro EvenIntMacro.apply } Roll your own with compile-time assertions
  • 11. final class EvenInt private (val value: Int) extends AnyVal { override def toString: String = s"EvenInt($value)" } object EvenInt { def from(value: Int): Option[EvenInt] = if (value % 2 == 0) Some(new EvenInt(value)) else None def apply(value: Int): EvenInt = macro EvenIntMacro.apply } object EvenIntMacro extends CompileTimeAssertions { def apply(c: Context)(value: c.Expr[Int]): c.Expr[EvenInt] = { val notValidMsg = "EvenInt.apply can only be invoked on even Int literals, like EvenInt(3)." val notLiteralMsg = "EveInt.apply can only be invoked on Int literals, like " + "EvenInt(3). Please use EvenInt.from instead." ensureValidIntLiteral(c)(value, notValidMsg, notLiteralMsg) { i => i % 2 == 1 } c.universe.reify { EvenInt.from(value.splice).get } } } Roll your own with compile-time assertions
  • 12. def half(even: Int): Int = { require(even % 2 == 0, s"$even was not even") even / 2 }
  • 13. def half(even: EvenInt): Int = { // Why no require here? even / 2 }
  • 14. Use types where practical to focus and reduce the need for tests (both assert and require). The Scalactic Way
  • 16. Safety, but complexity// ScalaTest 2.0 scala> equal("one") res0: MatcherFactory1[Any,Equality] = equal ("one") // ScalaTest 3.0 scala> equal("one") res0: MatcherFactory1[Any,EvidenceThat[String]#CanEqual] = equal ("one")
  • 17. Safety, but complexity// ScalaTest 2.0 scala> equal ("one") res0: MatcherFactory1[Any,Equality] = equal ("one") // ScalaTest 3.0 scala> equal("one") res0: MatcherFactory1[Any,EvidenceThat[String]#CanEqual] = equal ("one") // ScalaTest 2.0 scala> Some("one") should (be (defined) and not equal "one") // ScalaTest 3.0 scala> Some("one") should (be (defined) and not equal "one") <console>:20: error: could not find implicit value for parameter typeClass2: org.scalactic.enablers.EvidenceThat[String]#CanEqual[Some[String]] Some("one") should not equal "one" ^
  • 19. The Scalactic Way The type system does not offer the best solution to every problem.
  • 20. The SuperSafe Way - Can run all the time - Doesn’t hurt compile time - No warnings, only errors - Not a linter; a “Scala subset policy enforcer”
  • 21.
  • 22. artima.com/flyer SuperSafe, Escalate Stairway to Scala training 
 50% discount at Artima booth Q => A