SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
State of Scala code style
Hello! 
• Jaime Jorge from Codacy 
• Master thesis & company with Scala 
• Scala lover for 4 years
• Why? 
• Questions 
• Code styles 
• OSS Analysis 
• Brief overview of observations
Why care? 
• Expressive language, haters like to call ‘complex’ 
• We’re reviewing code everyday 
• Reduce number of moving parts 
• Onboarding becomes easier
Questions 
• What are the current code styles? 
• Are we respecting them? 
• What might become best practices/standard?
What code styles are 
currently out there?
Gathered code styles 
• Official Scala Style 
• Twitters Effective Scala 
• Apache Spark 
• Bizo Scala Style 
• Kiji project 
• Vertx mod lang 
• Apache Kafka
Method 
• Categories 
• Extract rules from all 
• Understand what they have in common/different
Rules extracted 
• 127 rules total 
• All taken from guidelines
Major differences 
• Max 100 character line 
• Do not use relative imports from other packages 
• Always use braces for ifs except for ternary operator 
behavior 
• Do not use infix notation if method is not an operator 
(map, filter, flatMap)
Major differences 
• Max 80 character line 
• Declarations: 
• Use vals when possible. 
• Use private when possible for member variables. 
• Use named arguments when passing in literal values 
• Options should be used instead of null whenever possible 
• Prefer case classes over tuples
Major differences 
• Adds more than 40 rules to original style guide 
• Introduces Collections, Object Oriented and Functional 
style advice 
• Shows preferences over APIs
Conclusion 
• Built upon Scala Style Guide 
• 127 rules you can choose for your project 
• Some differences are important enough to include in 
Official Scala Style
Are we respecting them?
Answer by 
• Analyzing open source projects for violations of 
Official Scala Style 
• Understand % of compliance 
• Understand number of code style violations 
• Per category 
• Per code pattern
OSS Analysis 
• Analyzed 50 most popular Scala projects
Tools 
• ScalaStyle 
• HairyFotr/linter 
• WartRemover 
• Abide 
• scapegoat 
• Codacy
Results 
• 51% code style compliance on average 
• Inverse correlation between Age of project and Code 
style compliance of project 
• Correlation between number of committers and 
number of violations (expected)
Breakdown 
Curly braces 
Line max 
Method naming 
catching Fatal exceptions 
Mutable fields 
object naming convention 
class naming convention 
others
Other interesting facts 
• Significant violations of Option.get 
• Significant violations of nulls
Limitations of analysis 
• Most popular tend to be libraries 
• May not represent reality in industry perfectly
Conclusions 
• 51% code style compliance on average 
• Naming and formatting biggest culprits 
• Older projects have less compliance 
• Are we respecting them? 
• Answer: we could do a better job.
What might become 
standard?
Areas 
• Collection of rules we see enforced humanly in Pull 
requests and commits
Areas 
• Collections 
• Testing 
• Object oriented programming 
• Functional programming
Collapsing of containers 
Options 
if (startField.isEmpty && endField.isEmpty) Seq("foo", "bar") 
else if (startField.isEmpty && !endField.isEmpty) Seq("foo", endField.get) 
else if (!startField.isEmpty && endField.isEmpty) Seq(startField.get, "bar") 
else Seq(startField.get, endField.get) 
Vs 
Seq(startField.getOrElse("foo"),endField.getOrElse("bar"))
Collapsing of containers 
Futures 
Await.result(client.hGet(foo, bar)).get 
Vs 
client.hGet(foo, bar).map(f => ..)
Collections: optimizations 
From Scapegoat 
• exists(x => x == b) replaceable with contains(b) 
• .filter(x => ).head can be replaced with find(x => ) match { .. } 
• .filter(x =>).headOption can be replaced with find(x => ) 
• .filter(x => Bool).isEmpty can be replaced with !exists(x => Bool) 
• .filter(_.isDefined).map(_.get) can be replaced with flatten 
• .filter(x => Bool).size can be replaced more concisely with with count(x => Bool) 
• sort.filter can be replaced with filter.sort for performance 
• !Traversable.isEmpty can be replaced with Traversable.nonEmpty 
• !Traversable.nonEmpty can be replaced with Traversable.isEmpty
Akka 
Guidelines 
• Immutable messages 
• If state becomes complex, context.become 
• Not expose any state to outside
Unit testing 
Testing with state 
• Consistency in tests 
• Encapsulate test state in a Context object.
Object oriented 
programming 
• Use dependency injection for program modularization 
• The use of traits are highly encouraged 
• Do not use Exceptions for commonplace errors 
• Encode commonplace errors explicitly: using Option or 
(scala.util./com.twitter.util.)Try
Functional programming 
• Options should be used instead of null whenever 
possible 
• Do not overuse Option: if there is a sensible default — a 
Null Object — use that instead. 
• Don’t use pattern matching for conditional execution 
• Only use call-by-name for creating new control 
constructs such as DSLs 
• Prefer case classes over tuples (specially no ._1)
Note: Microservices 
• Style of thinking and code in ‘Your Server as a 
Function’ 
• Server operations through future combinators 
• Declarative programming
Microservices: declarative 
programming 
recordHandletime andThen 
traceRequest andThen 
collectJvmStats andThen 
parseRequest andThen 
logRequest andThen 
recordClientStats andThen 
sanitize andThen 
respondToHealthCheck andThen 
applyTrafficControl andThen 
virtualHostServer
Thanks! 
QA
Exclusive Offer 
Use Codacy for free for 3 months on private repositories 
Promo Code: SCALABAY-LLHLKS

Más contenido relacionado

La actualidad más candente

AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...
AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...
AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...AOE
 
Bsides Knoxville - APT2
Bsides Knoxville - APT2Bsides Knoxville - APT2
Bsides Knoxville - APT2Adam Compton
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaBrian Topping
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Red Gate Software
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...SQALab
 
WordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP HooksWordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP HooksEunus Hosen
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) Jonathan Engelsma
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) Jonathan Engelsma
 
Dave Haeffner's Proven Method to Grading the Quality of Selenium Tests
Dave Haeffner's Proven Method to Grading the Quality of Selenium TestsDave Haeffner's Proven Method to Grading the Quality of Selenium Tests
Dave Haeffner's Proven Method to Grading the Quality of Selenium TestsApplitools
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patternsRahul Singh
 
44 Slides About 22 Modules
44 Slides About 22 Modules44 Slides About 22 Modules
44 Slides About 22 Modulesheyrocker
 
Defensive Coding Crash Course
Defensive Coding Crash CourseDefensive Coding Crash Course
Defensive Coding Crash CourseMark Niebergall
 
Software testing with examples in Angular (and AngularJS)
Software testing with examples in Angular (and AngularJS)Software testing with examples in Angular (and AngularJS)
Software testing with examples in Angular (and AngularJS)Paweł Żurowski
 
Automated Software Testing
Automated Software TestingAutomated Software Testing
Automated Software Testingarild2
 
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Andy Maleh
 
2 the essentials of effective java
2 the essentials of effective java2 the essentials of effective java
2 the essentials of effective javaHonnix Liang
 

La actualidad más candente (20)

AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...
AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...
AOEcon17: Searchperience - The journey from PHP and Solr to Scala and Elastic...
 
Bsides Knoxville - APT2
Bsides Knoxville - APT2Bsides Knoxville - APT2
Bsides Knoxville - APT2
 
Perfect Code
Perfect CodePerfect Code
Perfect Code
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
WordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP HooksWordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP Hooks
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
 
Dave Haeffner's Proven Method to Grading the Quality of Selenium Tests
Dave Haeffner's Proven Method to Grading the Quality of Selenium TestsDave Haeffner's Proven Method to Grading the Quality of Selenium Tests
Dave Haeffner's Proven Method to Grading the Quality of Selenium Tests
 
Introduction To AOP
Introduction To AOPIntroduction To AOP
Introduction To AOP
 
Segue to design patterns
Segue to design patternsSegue to design patterns
Segue to design patterns
 
44 Slides About 22 Modules
44 Slides About 22 Modules44 Slides About 22 Modules
44 Slides About 22 Modules
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Defensive Coding Crash Course
Defensive Coding Crash CourseDefensive Coding Crash Course
Defensive Coding Crash Course
 
Software testing with examples in Angular (and AngularJS)
Software testing with examples in Angular (and AngularJS)Software testing with examples in Angular (and AngularJS)
Software testing with examples in Angular (and AngularJS)
 
Automated Software Testing
Automated Software TestingAutomated Software Testing
Automated Software Testing
 
Testing Tools Classroom Training
Testing Tools Classroom TrainingTesting Tools Classroom Training
Testing Tools Classroom Training
 
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
 
2 the essentials of effective java
2 the essentials of effective java2 the essentials of effective java
2 the essentials of effective java
 

Destacado

Tour d’horizon de scala
Tour d’horizon de scalaTour d’horizon de scala
Tour d’horizon de scalaBenoit Wilcox
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
Six years of Scala and counting
Six years of Scala and countingSix years of Scala and counting
Six years of Scala and countingManuel Bernhardt
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java ProgrammersEnno Runne
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...Helena Edelson
 

Destacado (8)

Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Tour d’horizon de scala
Tour d’horizon de scalaTour d’horizon de scala
Tour d’horizon de scala
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Six years of Scala and counting
Six years of Scala and countingSix years of Scala and counting
Six years of Scala and counting
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
 

Similar a Scala Bay Meetup - The state of Scala code style and quality

TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleNoam Kfir
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
Style & Design Principles 01 - Code Style & Structure
Style & Design Principles 01 - Code Style & StructureStyle & Design Principles 01 - Code Style & Structure
Style & Design Principles 01 - Code Style & StructureNick Pruehs
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"Kazuhiro Sera
 
Enterprise search in Plone using Solr
Enterprise search in Plone using SolrEnterprise search in Plone using Solr
Enterprise search in Plone using SolrCalvin Hendryx-Parker
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovypaulbowler
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Shirish Bari
 
Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8Garth Gilmour
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best PracticesVivek Chawla
 
ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019Rory Graves
 

Similar a Scala Bay Meetup - The state of Scala code style and quality (20)

TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Style & Design Principles 01 - Code Style & Structure
Style & Design Principles 01 - Code Style & StructureStyle & Design Principles 01 - Code Style & Structure
Style & Design Principles 01 - Code Style & Structure
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
 
Enterprise search in Plone using Solr
Enterprise search in Plone using SolrEnterprise search in Plone using Solr
Enterprise search in Plone using Solr
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Code reviews
Code reviewsCode reviews
Code reviews
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
 
ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019
 

Último

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 

Último (20)

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 

Scala Bay Meetup - The state of Scala code style and quality

  • 1. State of Scala code style
  • 2. Hello! • Jaime Jorge from Codacy • Master thesis & company with Scala • Scala lover for 4 years
  • 3. • Why? • Questions • Code styles • OSS Analysis • Brief overview of observations
  • 4. Why care? • Expressive language, haters like to call ‘complex’ • We’re reviewing code everyday • Reduce number of moving parts • Onboarding becomes easier
  • 5. Questions • What are the current code styles? • Are we respecting them? • What might become best practices/standard?
  • 6. What code styles are currently out there?
  • 7. Gathered code styles • Official Scala Style • Twitters Effective Scala • Apache Spark • Bizo Scala Style • Kiji project • Vertx mod lang • Apache Kafka
  • 8. Method • Categories • Extract rules from all • Understand what they have in common/different
  • 9. Rules extracted • 127 rules total • All taken from guidelines
  • 10.
  • 11.
  • 12.
  • 13. Major differences • Max 100 character line • Do not use relative imports from other packages • Always use braces for ifs except for ternary operator behavior • Do not use infix notation if method is not an operator (map, filter, flatMap)
  • 14.
  • 15. Major differences • Max 80 character line • Declarations: • Use vals when possible. • Use private when possible for member variables. • Use named arguments when passing in literal values • Options should be used instead of null whenever possible • Prefer case classes over tuples
  • 16.
  • 17. Major differences • Adds more than 40 rules to original style guide • Introduces Collections, Object Oriented and Functional style advice • Shows preferences over APIs
  • 18. Conclusion • Built upon Scala Style Guide • 127 rules you can choose for your project • Some differences are important enough to include in Official Scala Style
  • 20. Answer by • Analyzing open source projects for violations of Official Scala Style • Understand % of compliance • Understand number of code style violations • Per category • Per code pattern
  • 21. OSS Analysis • Analyzed 50 most popular Scala projects
  • 22. Tools • ScalaStyle • HairyFotr/linter • WartRemover • Abide • scapegoat • Codacy
  • 23.
  • 24. Results • 51% code style compliance on average • Inverse correlation between Age of project and Code style compliance of project • Correlation between number of committers and number of violations (expected)
  • 25. Breakdown Curly braces Line max Method naming catching Fatal exceptions Mutable fields object naming convention class naming convention others
  • 26. Other interesting facts • Significant violations of Option.get • Significant violations of nulls
  • 27. Limitations of analysis • Most popular tend to be libraries • May not represent reality in industry perfectly
  • 28. Conclusions • 51% code style compliance on average • Naming and formatting biggest culprits • Older projects have less compliance • Are we respecting them? • Answer: we could do a better job.
  • 29. What might become standard?
  • 30. Areas • Collection of rules we see enforced humanly in Pull requests and commits
  • 31. Areas • Collections • Testing • Object oriented programming • Functional programming
  • 32. Collapsing of containers Options if (startField.isEmpty && endField.isEmpty) Seq("foo", "bar") else if (startField.isEmpty && !endField.isEmpty) Seq("foo", endField.get) else if (!startField.isEmpty && endField.isEmpty) Seq(startField.get, "bar") else Seq(startField.get, endField.get) Vs Seq(startField.getOrElse("foo"),endField.getOrElse("bar"))
  • 33. Collapsing of containers Futures Await.result(client.hGet(foo, bar)).get Vs client.hGet(foo, bar).map(f => ..)
  • 34. Collections: optimizations From Scapegoat • exists(x => x == b) replaceable with contains(b) • .filter(x => ).head can be replaced with find(x => ) match { .. } • .filter(x =>).headOption can be replaced with find(x => ) • .filter(x => Bool).isEmpty can be replaced with !exists(x => Bool) • .filter(_.isDefined).map(_.get) can be replaced with flatten • .filter(x => Bool).size can be replaced more concisely with with count(x => Bool) • sort.filter can be replaced with filter.sort for performance • !Traversable.isEmpty can be replaced with Traversable.nonEmpty • !Traversable.nonEmpty can be replaced with Traversable.isEmpty
  • 35. Akka Guidelines • Immutable messages • If state becomes complex, context.become • Not expose any state to outside
  • 36. Unit testing Testing with state • Consistency in tests • Encapsulate test state in a Context object.
  • 37.
  • 38. Object oriented programming • Use dependency injection for program modularization • The use of traits are highly encouraged • Do not use Exceptions for commonplace errors • Encode commonplace errors explicitly: using Option or (scala.util./com.twitter.util.)Try
  • 39. Functional programming • Options should be used instead of null whenever possible • Do not overuse Option: if there is a sensible default — a Null Object — use that instead. • Don’t use pattern matching for conditional execution • Only use call-by-name for creating new control constructs such as DSLs • Prefer case classes over tuples (specially no ._1)
  • 40. Note: Microservices • Style of thinking and code in ‘Your Server as a Function’ • Server operations through future combinators • Declarative programming
  • 41. Microservices: declarative programming recordHandletime andThen traceRequest andThen collectJvmStats andThen parseRequest andThen logRequest andThen recordClientStats andThen sanitize andThen respondToHealthCheck andThen applyTrafficControl andThen virtualHostServer
  • 42.
  • 44. Exclusive Offer Use Codacy for free for 3 months on private repositories Promo Code: SCALABAY-LLHLKS