SlideShare a Scribd company logo
Code Hygiene: Lessons from
Scala
Hila Noga
CTO @ Hello Heart
A story about language adoption
Why Scala?
Runs on the JVM, supports Java libraries
Statically typed, combines functional and OOP styles and all that
jazz
Productive
Fun
All our brilliant friends loved it
A perilous Journey
Steep learning curve
Learning new ways to think is HARD!
Not enough guidance, we learned as we went
The result?
Some pretty ugly code in our
codebase!
Scala: The good, the Bad and the
Dirty
The good: It gives you
all the toys
The bad: It gives you
all the toys
Code Hygiene: Lessons from Scala
The dirty?
WTF, Scala, Seriously?!
“An expert is a man woman who
has made all the mistakes which
can be made, in a narrow field.”
Niels Bohr
Coding is an exercise in reading comprehension
You spend more time reading code than writing code
Code should be written in order to be read
So it should be clean and self-documenting
Clean up your mess!
Coherent what?!
Scala gives you a million valid, good and simple ways to do the
same thing.
You might think that’s a good thing...
The zoo example
Because what is a lecture without some silly code examples...
Error handling
Error handling
Error handling
Error handling
much options
wow
WAT DO?
Async computation
Async computation
This can get busy quickly if you have many levels of nesting...
Async computation
Which should you use?!
Async computation and error handling with
futures
Lesson: Have a
convention
Follow the rule of least
surprise
Prefer a convention that’s
easy to read and understand
Prefer small functions that
do one thing and have
meaningful names
Have a training plan
Refactoring is Magic
You always learn new things. Unless you are dead.
Leave every place you visit a little bit cleaner than the way you
found it.
How can you do it without fear?
Lesson: Write
testable code,
and TEST IT!
Keep testing in mind when
writing your code
Small functions with no side
effects are easy to test
We use ScalaTest
Example shamelessly stolen from the Scala Test website
A less obvious point...
Use the type system to make things explicit
Use the type system to make things explicit
Use the type system to make things explicit
Use the type system to make things explicit
Use the type system to make things explicit
Now if you do something illegal, your code won’t compile
Lesson: Let
your compiler
help you
Make your assumptions
about the code explicit
Make your code self-
documenting
Catch errors early
Why wouldn’t you?!
Into the lion’s den
Compare this:
Quick! What does this code do?
So much information you just.don’t.care about in here!
To this:
Wait... Can we improve this?
A bit of magic:
So much easier on the eyes!
Lesson: The
right level of
abstraction
creates
expressive
code
The code is the best system
documentation
It should read like a story of
what the system does
Lesson: You CAN have
too much of a good
thing
OMG! It’s almost as if it’s a
coherent worldview!
“Clean code always looks like it was
written by someone who cares”
~ Michael Feathers

More Related Content

PPTX
Java Sorting Algorithms
PPTX
Introduction to Programming Contests
ODP
How to code
PDF
Advanced java script essentials v1
PDF
Scottish Ruby Conference 2014
PDF
Culture And Aesthetic Revisited
PPTX
Recipe of a rockstar developer
PDF
What Happens to Everyone, When Everyone Learns to Code - by Farrah Bostic at ...
Java Sorting Algorithms
Introduction to Programming Contests
How to code
Advanced java script essentials v1
Scottish Ruby Conference 2014
Culture And Aesthetic Revisited
Recipe of a rockstar developer
What Happens to Everyone, When Everyone Learns to Code - by Farrah Bostic at ...

Similar to Code Hygiene: Lessons from Scala (20)

PPTX
Teach Yourself to Build Web Apps
PPTX
Hack your carrer : teach yourself coding
PDF
The Holistic Programmer
PDF
Challenges of moving a java team to scala
PPT
What does OOP stand for?
PPT
Planning JavaScript and Ajax for larger teams
PDF
Js basics
PDF
Os Keysholistic
PDF
Raspberry pi education_manual
PDF
Raspberry pi education_manual
PPTX
Lesson 1.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PDF
A smarter way to learn python (en)
PDF
A smarter way to learn java script
PDF
A smarter way to learn java script
PPT
You shouldneverdo
PPTX
On Readability of Code
ODP
Introduction to Scala JS
PDF
C# o basico
PPTX
TIFF Nexus: Compile With Style
PPTX
This presentation was generated by GPT-3
Teach Yourself to Build Web Apps
Hack your carrer : teach yourself coding
The Holistic Programmer
Challenges of moving a java team to scala
What does OOP stand for?
Planning JavaScript and Ajax for larger teams
Js basics
Os Keysholistic
Raspberry pi education_manual
Raspberry pi education_manual
Lesson 1.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
A smarter way to learn python (en)
A smarter way to learn java script
A smarter way to learn java script
You shouldneverdo
On Readability of Code
Introduction to Scala JS
C# o basico
TIFF Nexus: Compile With Style
This presentation was generated by GPT-3
Ad

Recently uploaded (20)

PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
medical staffing services at VALiNTRY
PDF
Nekopoi APK 2025 free lastest update
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
medical staffing services at VALiNTRY
Nekopoi APK 2025 free lastest update
Odoo Companies in India – Driving Business Transformation.pdf
Digital Strategies for Manufacturing Companies
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Upgrade and Innovation Strategies for SAP ERP Customers
L1 - Introduction to python Backend.pptx
Transform Your Business with a Software ERP System
Which alternative to Crystal Reports is best for small or large businesses.pdf
Softaken Excel to vCard Converter Software.pdf
Odoo POS Development Services by CandidRoot Solutions
Design an Analysis of Algorithms II-SECS-1021-03
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Essential Infomation Tech presentation.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How Creative Agencies Leverage Project Management Software.pdf
Ad

Code Hygiene: Lessons from Scala

Editor's Notes

  • #2: Hila Noga CTO at Hello Heart A startup that helps people with high Blood Pressure and other heart-related medical conditions understand and engage with their health. Now, it turns out that engaged patients tend to heal better than disengaged one - so we are really proud of what we do. I came here today to tell you what I learned about clean code after 4 years of working with Scala
  • #3: And I want to start by telling you the story of how we adopted Scala As I said, I am the CTO of Hello Heart but I didn’t start as a CTO, Started as a developer, first task in Hello Heart was to write our server code in Scala
  • #4: We chose Scala because of all sorts of reasons that seemed good at the time like The fact that we come from the Java world and felt comfortable with the Java ecosystem and technologies Static typing (I’m strict like that), functional Productive All the cool kids love it “OMG, you must use Scala, you will love Scala, you must use it!”
  • #5: Adopting Scala hasn’t been an easy journey One of the reasons is that Scala is a language with a learning curve so steep it’s practically a wall OOP -> Functional (new way of thinking) No guidance
  • #6: Learning as we go - some pretty ugly code in our codebase You could say that about many languages, but Scala has some special properties that make it extremely problematic in that respect
  • #7: Love it as a developer (amusement park for software engineers). Still undecided as a CTO Reason: It’s a mixed bag
  • #8: Whatever you want - scala has it! Functions? Objects? No problem! Implicits? For sure! Static typing? Duck typing? Type parameters? Traits? You got it! Funky syntax? Symbolic names? Brackets? Semicolons? Dots and marks galore? It’s all there! Use it or don’t - the language doesn’t care Glorious pieces of code, the language will not limit you in any way
  • #9: Then there’s the bad thing about Scala, which is that it gives you all the toys
  • #10: With certain programming languages favoured in big enterprises - can’t do anything too good, but can’t do anything too horrific either Which is a good thing in certain settings (saying as a CTO, would have been really angry if someone said it to me as a developer) No people running rampant and being creative with their programming Reasonable, working code written at a reasonable pace Not too good but not too bad either Easy to find people that can maintain it
  • #11: But in Scala, if you don’t know what you are doing (or, sadly, if you know too much for your own good) You can shoot yourself in the foot, and that’s bound to get messy
  • #12: WTF, Scala, Seriously?! All this features mean that you can easily get a codebase that looks like it was profanityped by a developer with massive anger management problems and a very dirty mouth
  • #13: Having made many of the possible mistakes with this language and having fixed a good deal of them, I’m here to tell you what scala taught me about clean code
  • #14: We like to imagine developers as people who spew large amounts of code but in fact we spend more time reading code than writing it Read to learn Read to modify & extend Read to debug It follows that your code should be written in order to be read Your compiler doesn’t care if your code is obfuscated!
  • #15: Strive for clean code - to make our lives easier
  • #17: Time to get codey in here
  • #18: True to its Java origins... Scala does not believe in checked exceptions and it seems like most of the developed world doesn’t either...
  • #19: Algebric data types
  • #22: What should you do? Combine the approaches? How do you combine libraries that take different approaches into your codebase?
  • #25: Does exactly the same The difference is syntactic
  • #27: We use futures with for comprehensions (one way to rule async computations and error handling beautifully) Why we chose this style? Built in async and error handling Reads like a story Promotes small functions with meaningful names That do just one thing
  • #28: Having a coherent codebase is more important than writing a single solution Follow the rule of least surprise Pick one way & know why
  • #29: Unified code requires refactoring and makes it easier to refactor You will always learn new things Always haunted by the fear of breaking things
  • #30: Example - writing tests with Scala Test Functional style
  • #32: Let your compiler help you by choosing the right type for the job
  • #33: If you forget to check the returned value, you get a bug
  • #34: There are other ways to handle options more elegantly
  • #39: Back to the zoo example
  • #40: Example: Use functional features to abstract away implementation details
  • #41: Example: Use functional features to abstract away implementation details
  • #42: Example: Use functional features to abstract away implementation details
  • #43: Example: Use functional features to abstract away implementation details We simply fed the lions...
  • #45: Here’s the thing about Scala - it allows you to write code so good it comes right out of the other side and turns bad
  • #46: We spend more time reading code than writing it -> write code that’s easy to read Always write your code in the correct level of abstraction so it reads like a story So it should be clean and self documenting Make sure your functions are small, do one thing and are properly named Follow the rule of least surprise And to that end, choose one solution to each problem But refactor your ugly-ass old code to reflect your new understanding of the language Make sure you have tests so that you don’t break your stuff when you do it And let your compiler help you by making things explicit Because it makes your code less surprising And because why wouldn’t you? But keep in mind that you can have too much of a good thing!
  • #47: Quote I found on the interwebz Questions?