Type Safety in an Unsafe World
with Kotlin
Cody Engel, Staff Software Engineer @ PayPal
What is Type
Safety?
It is kind of confusing.
Photo: Matthew Hamilton via Unsplash
Robin Milner, A Theory of Type Polymorphism in Programming
“Well typed programs cannot go wrong.”
Going Wrong
Syntactically valid, but meaningless.
Type Safety by Michael Hicks - http://bit.ly/ple-type-safety
Well Typed
It may crash, but that is by design in Kotlin.
Type Safety by Michael Hicks - http://bit.ly/ple-type-safety
Well Typed, Continued
This is by design in Ruby and may also crash.
Type Safety by Michael Hicks - http://bit.ly/ple-type-safety
Cody Engel, Type Safety in an Unsafe World with Kotlin
“Some languages have stricter behavior
than others.”
What is Kotlin?
It is a strict, yet concise
programming language.
Photo: Marc Reichelt via Unsplash
Define Types
Name can be inferred to be a
String.
Define Mutability
A variable defined as “var”
can change.
Define Structures
Structured data is more
predictable.
Define Nullability
Nullability is opt-in.
Define
Concurrency
Coroutines make
concurrency simpler.
And The Unsafe
World?
That would be our APIs.
Photo: Jason Yoder via Unsplash
is_admin
As a boolean it works well.
Unfortunately, this wasn’t how it was actually modeled.
is_admin
Our permissions class was never safer!
However this is how we would model that information in Kotlin.
is_admin
Okay, technically this isn’t too bad.
Although, it is not the best way to model a boolean with JSON.
is_admin
Extension functions to the
rescue.
This could also be an extension property, but extension functions look better in Keynote 😉
is_admin
Strings can also represent
numeric values which can
represent booleans.
I was pretty excited to make use of extension functions, so it was fine.
is_admin
Unfortunately String already
has a toBoolean function.
And that function is for converting “true” and “false” into a boolean 🤦
is_admin
I can’t recall if this was
actually possible with the
API.
However there is a good chance it could have been possible based on customer configurations.
is_admin
Fortunately, it isn’t too
difficult to add.
Nonetheless, it’d be great if this wasn’t required in the first place 😉
is_admin
It was nullable though.
That’s okay though, nullability is actually pretty simple with Kotlin.
is_admin
Updating our extension
function to be on a nullable
Any works.
Since we type cast on non-null types, the else branch catches our null case.
Making The World
a Safer Place
How to design safer APIs.
Photo: Matthew Rumph via Unsplash
Stick to a strict API when rolling
your own specification.
Use an industry standard
specification, such as Open API.
Look at JSON alternatives such
as Protocol Buffers.
Let’s build some great and safe APIs.
• YouTube - bit.ly/cody-yt

• Twitter - bit.ly/cody-twitter

• Medium - bit.ly/cody-medium
Thanks!

More Related Content

PDF
GraphQL Will Do To REST What JSON Did To XML
PPTX
Whats New In C Sharp 4 And Vb 10
PPTX
How to replace switch with when in kotlin
PPTX
Kotlin for android
PPTX
Concurrent Applications with F# Agents
PDF
YAGNI Principle and Clean Code
PPTX
Ofir Dagan - (Don’t) Blame it on React Native - Codemotion Rome 2019
PDF
Kotlin vs Java • Bapusaheb Patil • TechieAid Talk
GraphQL Will Do To REST What JSON Did To XML
Whats New In C Sharp 4 And Vb 10
How to replace switch with when in kotlin
Kotlin for android
Concurrent Applications with F# Agents
YAGNI Principle and Clean Code
Ofir Dagan - (Don’t) Blame it on React Native - Codemotion Rome 2019
Kotlin vs Java • Bapusaheb Patil • TechieAid Talk

Similar to Type Safety in an Unsafe World With Kotlin (20)

PDF
Kotlin what_you_need_to_know-converted event 4 with nigerians
PPTX
Kotlin as a Better Java
PPTX
Flexible Types in Kotlin - JVMLS 2015
PDF
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
PDF
Kotlin: A pragmatic language by JetBrains
PPTX
Day 2 Compose Camp.pptx
PDF
Privet Kotlin (Windy City DevFest)
PDF
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
PDF
From Java to Kotlin
PPTX
Introduction to Koltin for Android Part I
PDF
Kotlin for Android Developers - 3
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
PDF
2 kotlin vs. java: what java has that kotlin does not
PDF
Taking Kotlin to production, Seriously
PPTX
Kotlin presentation
PDF
Exploring Kotlin
PDF
Kotlin for Android devs
PDF
Be More Productive with Kotlin
PDF
Kotlin Basics
PPTX
kotlin-nutshell.pptx
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin as a Better Java
Flexible Types in Kotlin - JVMLS 2015
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Kotlin: A pragmatic language by JetBrains
Day 2 Compose Camp.pptx
Privet Kotlin (Windy City DevFest)
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
From Java to Kotlin
Introduction to Koltin for Android Part I
Kotlin for Android Developers - 3
Develop your next app with kotlin @ AndroidMakersFr 2017
2 kotlin vs. java: what java has that kotlin does not
Taking Kotlin to production, Seriously
Kotlin presentation
Exploring Kotlin
Kotlin for Android devs
Be More Productive with Kotlin
Kotlin Basics
kotlin-nutshell.pptx
Ad

More from Postman (20)

PDF
Advanced AI and Documentation Techniques
PDF
WeTestAthens: Postman's AI & Automation Techniques
PDF
Elevating Developer Experiences with AI-Powered API Testing & Documentation
PDF
Discovering Public APIs and Public API Network with Postman
PDF
Optimizing Teamwork: Harnessing Collections & Workspaces for Collaboration
PDF
API testing Beyond the Basics AI & Automation Techniques
PDF
Not Your Grandma’s Rate Limiting (slides)
PDF
Five Ways to Automate API Testing with Postman
PDF
How to Scale APIs-as-Product for Future Success
PPTX
Revolutionizing API Development: Collaborative Workflows with Postman
PDF
Everything You Always Wanted to Know About AsyncAPI
PDF
Elevating Event-Driven World: A Deep Dive into AsyncAPI v3
PDF
Five Things You SHOULD Know About Postman
PDF
Integration-, Snapshot- and Performance-Testing APIs
PDF
How ChatGPT led OpenAPI's Recent Spike in Popularity
PDF
Exploring Postman’s VS Code Extension
PDF
2023 State of the API Report: Key Findings and Trends
PDF
Nordic- APIOps is here What will you build in an API First World
PDF
Testing and Developing gRPC APIs
PDF
Testing and Developing GraphQL APIs
Advanced AI and Documentation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Elevating Developer Experiences with AI-Powered API Testing & Documentation
Discovering Public APIs and Public API Network with Postman
Optimizing Teamwork: Harnessing Collections & Workspaces for Collaboration
API testing Beyond the Basics AI & Automation Techniques
Not Your Grandma’s Rate Limiting (slides)
Five Ways to Automate API Testing with Postman
How to Scale APIs-as-Product for Future Success
Revolutionizing API Development: Collaborative Workflows with Postman
Everything You Always Wanted to Know About AsyncAPI
Elevating Event-Driven World: A Deep Dive into AsyncAPI v3
Five Things You SHOULD Know About Postman
Integration-, Snapshot- and Performance-Testing APIs
How ChatGPT led OpenAPI's Recent Spike in Popularity
Exploring Postman’s VS Code Extension
2023 State of the API Report: Key Findings and Trends
Nordic- APIOps is here What will you build in an API First World
Testing and Developing gRPC APIs
Testing and Developing GraphQL APIs
Ad

Recently uploaded (20)

PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PPTX
Computer Software - Technology and Livelihood Education
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PPTX
Matchmaking for JVMs: How to Pick the Perfect GC Partner
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
CNN LeNet5 Architecture: Neural Networks
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
Website Design Services for Small Businesses.pdf
PDF
Salesforce Agentforce AI Implementation.pdf
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Trending Python Topics for Data Visualization in 2025
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
Computer Software - Technology and Livelihood Education
Practical Indispensable Project Management Tips for Delivering Successful Exp...
Matchmaking for JVMs: How to Pick the Perfect GC Partner
Advanced SystemCare Ultimate Crack + Portable (2025)
GSA Content Generator Crack (2025 Latest)
MCP Security Tutorial - Beginner to Advanced
BoxLang Dynamic AWS Lambda - Japan Edition
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
CNN LeNet5 Architecture: Neural Networks
Full-Stack Developer Courses That Actually Land You Jobs
iTop VPN Crack Latest Version Full Key 2025
CCleaner 6.39.11548 Crack 2025 License Key
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Website Design Services for Small Businesses.pdf
Salesforce Agentforce AI Implementation.pdf

Type Safety in an Unsafe World With Kotlin