SlideShare a Scribd company logo
1 of 58
Download to read offline
Design without types
Alex Bolboacă,  @alexboly,  alex.bolboaca@mozaicworks.com
May 2019
Introduction(s)
Why This Talk?
Experiment in minimalism: optional types
Deep questions
Conclusion
Introduction(s)
Slides
Slides published:
https://www.slideshare.net/alexboly/design-without-types
I’m Alex
I’m helping customers
Digital Transformation (mostly for banks recently)
I’m writing a book (publish date in June)
The topic I love the most is software design
“Alex Boly on Design” youtube playlist http://bit.ly/alex-on-design
Why This Talk?
Personal History
Beginner enthusiast (10 - 21 years old):
• BASIC (ZX80 Clone)
• Turbo Pascal
• C
• C++
Stance on types: what are types?
Personal History
Early professional (21 - 30 years old)
• C++
• Java
• C#
Stance on types: probably great.
Personal History
OMG, this book is mindblowing!
Personal History
Software Crafter (30 - 40 years old)
• C++
• python
• groovy
Stance on types: Get out of my comfort zone!
Personal History
Raising the Bar
Personal History
Code Designer (40 - now)
• what can I use to solve problems as quickly as possible?
Stance on types: optional types have distinct advantages
Code Designer
Minimalism
Minimalism in Code - Reasoning
• Custom code is expensive: to build, to test, to change, to refine until it
works, to run, to maintain
• The more lines of code, the higher the probability to have bugs
• Less code => smaller cognitive pressure
Experiment in minimalism: optional
types
Rules
• Type not specified unless it’s important
• No casting
• No thinking about the types used, only about their capabilities
What I’ve expected
• bugs
• weird problems
• need to write more tests
• code that’s more difficult to understand
What I’ve got from optional types
• cleaner & smaller code
• easier to change
• fewer tests than I expected
• fewer bugs than I expected
NB: Some things were enabled by the language (groovy + grails), others are
strongly related to the idea of optional types
Project
• eventrix.co
• web platform for conference organizers
• groovy on grails (JVM language)
Not perfect!
• too much custom code - learned the hard way
Cleaner and smaller code
// Typical Java version
User user = new User(); // Duplication: 3 * User + ';'!!!
var user = new User(); // Optional type: 2 * User + ';'
// Groovy version
def user = new User() // 2 * User
// GORM
def user = User.get(userId)
Cleaner and smaller code
// Functional programming
// C++ lambda
auto increment = [](int value){ return first + 1;};
// C++ lambda with optional type
auto increment = [](auto value){ return first + 1;};
Cleaner and smaller code
// Functional programming
// C++ lambda
auto increment = [](int value){ return first + 1;};
// C++ lambda with optional type
auto increment = [](auto value){ return first + 1;};
// Simplest Groovy lambda
def increment = {it + 1} // optional type
// also some magic: what is 'it'?
Cleaner and smaller code
// C++ get list of names of users
auto names = transform(
users.begin(), users.end(),
[](auto user){ return user.getName(); }
);
Cleaner and smaller code
// C++ get list of names of users
auto names = transform(
users.begin(), users.end(),
[](auto user){ return user.getName(); }
);
// groovy get list of names of users
def names = users*.name
Cleaner and smaller code
// Do the same, assuming User class has firstName and lastName
// C++
auto names = transform(users.begin(), users.end(),
[](auto user){
return user.getFirstName()
+ ” ”
+ users.getLastName();
}
);
Cleaner and smaller code
// Do the same, assuming User class has firstName and lastName
// C++
auto names = transform(users.begin(), users.end(),
[](auto user){
return user.getFirstName()
+ ” ”
+ users.getLastName();
}
);
// groovy
def names = users.collect{it.firstName + ” ” + it.lastName}
A taste of optional types
• Tests using Spock
• Query
• Controller
• Command
Deep questions
Q1: Is the cognitive cost of abstractions worth it?
Salvador Dali - The melting watch
Q2: Is strong typing a form of strong coupling?
Strong Coupling = “when I change X I also need to change Y”.
Example
class UserDbService {
boolean confirmEmail(int userId) {
def user = User.get(userId)
user.emailConfirmed = true
user.save()
}
...
}
class User{
int userId;
...
}
Example
What should be the type of userId?
• int
• long
• GUID
• UserID
Strong Coupling
What if I change the type from int to UserID?
(e.g. my company buys another company and we need to merge the systems)
• change User
• change UserDbService
• and change everywhere where int userId is used
Optional Type => looser coupling
class UserDbService {
boolean confirmEmail(userId) {
def user = User.get(userId)
user.emailConfirmed = true
user.save()
}
...
}
class User{
int userId;
...
}
Q3: How Important Are Names?
// a design pattern we use for
// transactional classes that
// interact with database
class UserDbService {
def confirmEmail(userId) {
def user = User.get(userId)
user.emailConfirmed = true
user.save()
}
...
}
Q4: How Important Are Contracts?
TEST_CASE(”X wins”){
Board board = {
{'X', 'X', 'X'},
{' ', 'O', ' '},
{' ', ' ', 'O'}
};
CHECK(xWins(board));
}
Let’s see the code!
Contract: Coordinates have two values
Contracts?
With minimal types, you need to be very aware of the contracts
Beyond Types: Design Entities
We use clear, well defined design entities:
• Model: class defining the entity structure and mapping to database
Beyond Types: Design Entities
We use clear, well defined design entities:
• Model: class defining the entity structure and mapping to database
• Query: class that encapsulates database queries
Beyond Types: Design Entities
We use clear, well defined design entities:
• Model: class defining the entity structure and mapping to database
• Query: class that encapsulates database queries
• DbCommand: class that saves data to the database
Beyond Types: Design Entities
We use clear, well defined design entities:
• Model: class defining the entity structure and mapping to database
• Query: class that encapsulates database queries
• DbCommand: class that saves data to the database
• DbService: class that is called by Command or BusinessService to
make multiple operations in the database, usually with the help of
DbCommands
Beyond Types: Design Entities
We use clear, well defined design entities:
• Model: class defining the entity structure and mapping to database
• Query: class that encapsulates database queries
• DbCommand: class that saves data to the database
• DbService: class that is called by Command or BusinessService to
make multiple operations in the database, usually with the help of
DbCommands
• BusinessService: class that is called by Command to facilitate a
business process
Beyond Types: Design Entities
We use clear, well defined design entities:
• Model: class defining the entity structure and mapping to database
• Query: class that encapsulates database queries
• DbCommand: class that saves data to the database
• DbService: class that is called by Command or BusinessService to
make multiple operations in the database, usually with the help of
DbCommands
• BusinessService: class that is called by Command to facilitate a
business process
• Command: class that is called by Controller to validate specific HTTP
requests and delegate to the right Services the execution.
Conclusion
Minimalism exerts a positive pressure on design
We still need to understand the code. Without types, how do we understand
it?
• smaller code
Minimalism exerts a positive pressure on design
We still need to understand the code. Without types, how do we understand
it?
• smaller code
• better names
Minimalism exerts a positive pressure on design
We still need to understand the code. Without types, how do we understand
it?
• smaller code
• better names
• clear responsibilities
Minimalism exerts a positive pressure on design
We still need to understand the code. Without types, how do we understand
it?
• smaller code
• better names
• clear responsibilities
• clear contracts
Minimalism exerts a positive pressure on design
We still need to understand the code. Without types, how do we understand
it?
• smaller code
• better names
• clear responsibilities
• clear contracts
• clear tests
Always Optional Types? NO
Clear problem domain, clear solution, not expecting change, used by
specialists => strong types, validation at compile time
Expecting change, evolving problem and solution domain => minimalism,
changeable code, fewer constraints
Let’s think differently!
“I want the compiler to do as much checking for me as possible”
Let’s think differently!
“I want the compiler to do as much checking for me as possible”
vs.
“I want to write the code that makes sense, and the compiler / interpreter to
figure it out”
Thank you!
Come talk to me later and get nice stickers!
Q&A
Q&A

More Related Content

What's hot

JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - IntroductionWebStackAcademy
 
introduction to javascript
introduction to javascriptintroduction to javascript
introduction to javascriptKumar
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
 
Web development basics (Part-2)
Web development basics (Part-2)Web development basics (Part-2)
Web development basics (Part-2)Rajat Pratap Singh
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSergey Karpushin
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)Rajat Pratap Singh
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Codemotion
 
Concurrency for dummies
Concurrency for dummiesConcurrency for dummies
Concurrency for dummiesAzrul MADISA
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
Web development basics (Part-6)
Web development basics (Part-6)Web development basics (Part-6)
Web development basics (Part-6)Rajat Pratap Singh
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
 

What's hot (19)

Java script ppt
Java script pptJava script ppt
Java script ppt
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
introduction to javascript
introduction to javascriptintroduction to javascript
introduction to javascript
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Web development basics (Part-2)
Web development basics (Part-2)Web development basics (Part-2)
Web development basics (Part-2)
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
 
OOP's Part 1
OOP's Part 1OOP's Part 1
OOP's Part 1
 
Concurrency for dummies
Concurrency for dummiesConcurrency for dummies
Concurrency for dummies
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
Web development basics (Part-6)
Web development basics (Part-6)Web development basics (Part-6)
Web development basics (Part-6)
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 

Similar to Design without types experiment in minimalism

Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Fwdays
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 
CBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBoxCBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBoxOrtus Solutions, Corp
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?devObjective
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NETDror Helper
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)David Coulter
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3Sisir Ghosh
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIDirk Ginader
 
Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Codinginspector_fegter
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titaniumNaga Harish M
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumTechday7
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramMichael Heron
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applicationseightbit
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Ortus Solutions, Corp
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Uma Ghotikar
 

Similar to Design without types experiment in minimalism (20)

Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 
Gradle 101
Gradle 101Gradle 101
Gradle 101
 
CBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBoxCBDW2014 - Behavior Driven Development with TestBox
CBDW2014 - Behavior Driven Development with TestBox
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
 
SDWest2005Goetsch
SDWest2005GoetschSDWest2005Goetsch
SDWest2005Goetsch
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 
Javascript done right - Open Web Camp III
Javascript done right - Open Web Camp IIIJavascript done right - Open Web Camp III
Javascript done right - Open Web Camp III
 
Wordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean CodingWordcamp St. Louis - Clean Coding
Wordcamp St. Louis - Clean Coding
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titanium
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a Program
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
Type script
Type scriptType script
Type script
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 

More from Alexandru Bolboaca (20)

Refactor legacy code through pure functions
Refactor legacy code through pure functionsRefactor legacy code through pure functions
Refactor legacy code through pure functions
 
Thinking in Functions
Thinking in FunctionsThinking in Functions
Thinking in Functions
 
Raising the Bar
Raising the BarRaising the Bar
Raising the Bar
 
The Journey to Master Code Design
The Journey to Master Code DesignThe Journey to Master Code Design
The Journey to Master Code Design
 
What is good software design? And why it matters?
What is good software design? And why it matters?What is good software design? And why it matters?
What is good software design? And why it matters?
 
Functional programming in C++
Functional programming in C++Functional programming in C++
Functional programming in C++
 
Agile Technical Leadership
Agile Technical LeadershipAgile Technical Leadership
Agile Technical Leadership
 
TDD As If You Meant It
TDD As If You Meant ItTDD As If You Meant It
TDD As If You Meant It
 
Usable Software Design
Usable Software DesignUsable Software Design
Usable Software Design
 
Hidden loops
Hidden loopsHidden loops
Hidden loops
 
Removing structural duplication
Removing structural duplicationRemoving structural duplication
Removing structural duplication
 
Continuous delivery
Continuous deliveryContinuous delivery
Continuous delivery
 
Why You Should Start Using Docker
Why You Should Start Using DockerWhy You Should Start Using Docker
Why You Should Start Using Docker
 
Pyramid of-developer-skills
Pyramid of-developer-skillsPyramid of-developer-skills
Pyramid of-developer-skills
 
Applied craftsmanship
Applied craftsmanshipApplied craftsmanship
Applied craftsmanship
 
Pyramid of-developer-skills
Pyramid of-developer-skillsPyramid of-developer-skills
Pyramid of-developer-skills
 
Stay focused
Stay focusedStay focused
Stay focused
 
Kanban intro
Kanban introKanban intro
Kanban intro
 
Unit testing-patterns
Unit testing-patternsUnit testing-patterns
Unit testing-patterns
 
Incremental design, simply explained
Incremental design, simply explainedIncremental design, simply explained
Incremental design, simply explained
 

Recently uploaded

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 

Recently uploaded (20)

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 

Design without types experiment in minimalism

  • 1. Design without types Alex Bolboacă,  @alexboly,  alex.bolboaca@mozaicworks.com May 2019
  • 2. Introduction(s) Why This Talk? Experiment in minimalism: optional types Deep questions Conclusion
  • 6. I’m helping customers Digital Transformation (mostly for banks recently)
  • 7. I’m writing a book (publish date in June)
  • 8. The topic I love the most is software design “Alex Boly on Design” youtube playlist http://bit.ly/alex-on-design
  • 10. Personal History Beginner enthusiast (10 - 21 years old): • BASIC (ZX80 Clone) • Turbo Pascal • C • C++ Stance on types: what are types?
  • 11. Personal History Early professional (21 - 30 years old) • C++ • Java • C# Stance on types: probably great.
  • 12. Personal History OMG, this book is mindblowing!
  • 13. Personal History Software Crafter (30 - 40 years old) • C++ • python • groovy Stance on types: Get out of my comfort zone!
  • 15. Personal History Code Designer (40 - now) • what can I use to solve problems as quickly as possible? Stance on types: optional types have distinct advantages
  • 17. Minimalism in Code - Reasoning • Custom code is expensive: to build, to test, to change, to refine until it works, to run, to maintain • The more lines of code, the higher the probability to have bugs • Less code => smaller cognitive pressure
  • 18. Experiment in minimalism: optional types
  • 19. Rules • Type not specified unless it’s important • No casting • No thinking about the types used, only about their capabilities
  • 20. What I’ve expected • bugs • weird problems • need to write more tests • code that’s more difficult to understand
  • 21. What I’ve got from optional types • cleaner & smaller code • easier to change • fewer tests than I expected • fewer bugs than I expected NB: Some things were enabled by the language (groovy + grails), others are strongly related to the idea of optional types
  • 22. Project • eventrix.co • web platform for conference organizers • groovy on grails (JVM language) Not perfect! • too much custom code - learned the hard way
  • 23. Cleaner and smaller code // Typical Java version User user = new User(); // Duplication: 3 * User + ';'!!! var user = new User(); // Optional type: 2 * User + ';' // Groovy version def user = new User() // 2 * User // GORM def user = User.get(userId)
  • 24. Cleaner and smaller code // Functional programming // C++ lambda auto increment = [](int value){ return first + 1;}; // C++ lambda with optional type auto increment = [](auto value){ return first + 1;};
  • 25. Cleaner and smaller code // Functional programming // C++ lambda auto increment = [](int value){ return first + 1;}; // C++ lambda with optional type auto increment = [](auto value){ return first + 1;}; // Simplest Groovy lambda def increment = {it + 1} // optional type // also some magic: what is 'it'?
  • 26. Cleaner and smaller code // C++ get list of names of users auto names = transform( users.begin(), users.end(), [](auto user){ return user.getName(); } );
  • 27. Cleaner and smaller code // C++ get list of names of users auto names = transform( users.begin(), users.end(), [](auto user){ return user.getName(); } ); // groovy get list of names of users def names = users*.name
  • 28. Cleaner and smaller code // Do the same, assuming User class has firstName and lastName // C++ auto names = transform(users.begin(), users.end(), [](auto user){ return user.getFirstName() + ” ” + users.getLastName(); } );
  • 29. Cleaner and smaller code // Do the same, assuming User class has firstName and lastName // C++ auto names = transform(users.begin(), users.end(), [](auto user){ return user.getFirstName() + ” ” + users.getLastName(); } ); // groovy def names = users.collect{it.firstName + ” ” + it.lastName}
  • 30. A taste of optional types • Tests using Spock • Query • Controller • Command
  • 32. Q1: Is the cognitive cost of abstractions worth it? Salvador Dali - The melting watch
  • 33. Q2: Is strong typing a form of strong coupling? Strong Coupling = “when I change X I also need to change Y”.
  • 34. Example class UserDbService { boolean confirmEmail(int userId) { def user = User.get(userId) user.emailConfirmed = true user.save() } ... } class User{ int userId; ... }
  • 35. Example What should be the type of userId? • int • long • GUID • UserID
  • 36. Strong Coupling What if I change the type from int to UserID? (e.g. my company buys another company and we need to merge the systems) • change User • change UserDbService • and change everywhere where int userId is used
  • 37. Optional Type => looser coupling class UserDbService { boolean confirmEmail(userId) { def user = User.get(userId) user.emailConfirmed = true user.save() } ... } class User{ int userId; ... }
  • 38. Q3: How Important Are Names? // a design pattern we use for // transactional classes that // interact with database class UserDbService { def confirmEmail(userId) { def user = User.get(userId) user.emailConfirmed = true user.save() } ... }
  • 39. Q4: How Important Are Contracts? TEST_CASE(”X wins”){ Board board = { {'X', 'X', 'X'}, {' ', 'O', ' '}, {' ', ' ', 'O'} }; CHECK(xWins(board)); }
  • 40. Let’s see the code! Contract: Coordinates have two values
  • 41. Contracts? With minimal types, you need to be very aware of the contracts
  • 42. Beyond Types: Design Entities We use clear, well defined design entities: • Model: class defining the entity structure and mapping to database
  • 43. Beyond Types: Design Entities We use clear, well defined design entities: • Model: class defining the entity structure and mapping to database • Query: class that encapsulates database queries
  • 44. Beyond Types: Design Entities We use clear, well defined design entities: • Model: class defining the entity structure and mapping to database • Query: class that encapsulates database queries • DbCommand: class that saves data to the database
  • 45. Beyond Types: Design Entities We use clear, well defined design entities: • Model: class defining the entity structure and mapping to database • Query: class that encapsulates database queries • DbCommand: class that saves data to the database • DbService: class that is called by Command or BusinessService to make multiple operations in the database, usually with the help of DbCommands
  • 46. Beyond Types: Design Entities We use clear, well defined design entities: • Model: class defining the entity structure and mapping to database • Query: class that encapsulates database queries • DbCommand: class that saves data to the database • DbService: class that is called by Command or BusinessService to make multiple operations in the database, usually with the help of DbCommands • BusinessService: class that is called by Command to facilitate a business process
  • 47. Beyond Types: Design Entities We use clear, well defined design entities: • Model: class defining the entity structure and mapping to database • Query: class that encapsulates database queries • DbCommand: class that saves data to the database • DbService: class that is called by Command or BusinessService to make multiple operations in the database, usually with the help of DbCommands • BusinessService: class that is called by Command to facilitate a business process • Command: class that is called by Controller to validate specific HTTP requests and delegate to the right Services the execution.
  • 49. Minimalism exerts a positive pressure on design We still need to understand the code. Without types, how do we understand it? • smaller code
  • 50. Minimalism exerts a positive pressure on design We still need to understand the code. Without types, how do we understand it? • smaller code • better names
  • 51. Minimalism exerts a positive pressure on design We still need to understand the code. Without types, how do we understand it? • smaller code • better names • clear responsibilities
  • 52. Minimalism exerts a positive pressure on design We still need to understand the code. Without types, how do we understand it? • smaller code • better names • clear responsibilities • clear contracts
  • 53. Minimalism exerts a positive pressure on design We still need to understand the code. Without types, how do we understand it? • smaller code • better names • clear responsibilities • clear contracts • clear tests
  • 54. Always Optional Types? NO Clear problem domain, clear solution, not expecting change, used by specialists => strong types, validation at compile time Expecting change, evolving problem and solution domain => minimalism, changeable code, fewer constraints
  • 55. Let’s think differently! “I want the compiler to do as much checking for me as possible”
  • 56. Let’s think differently! “I want the compiler to do as much checking for me as possible” vs. “I want to write the code that makes sense, and the compiler / interpreter to figure it out”
  • 57. Thank you! Come talk to me later and get nice stickers!