The simplest thing that could possibly work

Emanuele DelBono
Emanuele DelBonoSoftware Engineer (owner) at CodicePlastico srl
The simplest thing that could possibly work
Emanuele DelBono - CodicePlastico
Cos’è il codice “semplice”?
/
/
OrderController
public IEnumerable<OrderRes> GetOrders(int orderId)
{
return _dbGateway.Execute<OrderRes>("SP_GET_ORDER", orderId);
}
Disclaimer
● Tutto quello che dico può essere giusto e condiviso ma anche sbagliato e
discorde dalle vostre opinioni, tutto dipende dal contesto, dai gusti e dalla
vostra esperienza. ☮💙
● L’obbiettivo di un team agile è consegnare software funzionante
SIMPLE CODE
I costi di sviluppo crescono esponenzialmente all’aumentare della complessità
La seniority ha un ruolo?
E’ facile scrivere codice semplice?
Simplicity and elegance are unpopular because they require hard work and
discipline to achieve and education to be appreciated
(Edsger W. Dijkstra)
Cos’è il codice “semplice”?
● Facile da leggere
● Facile da capire
● Facile da cambiare e mantenere (o da cancellare)
Cos’è il codice “semplice”?
Assert.That(x).Should().Be().Greater().Than(42)
assert(x > 42)
The simplest thing that could possibly work
[
{
"id": 1,
"title": "Clean Code",
"authors": [ "Robert C. Martin" ],
"year": 2008
},
{
"id": 2,
"title": "Structure and Interpretation of Computer Programs",
"authors": [ "H. Abelson", “G. J. Sussman" ],
"year": 1984
}
]
The simplest thing that could possibly work
The simplest thing that could possibly work
The simplest thing that could possibly work
PERCHÉ ACCADE
Fretta di consegnare
Troppo design up-front
Troppi cambi di requisiti
Inesperienza
Il software è un prodotto secondario di un processo di apprendimento
ziobrando
The simplest thing that could possibly work
The simplest thing that could possibly work
ESEMPI e SPUNTI
The hello world
public static class Program
{
public static void SayHello(ISettingReader sr, IMessageComposer mc)
{
var message = sr.Get("MESSAGE");
var formattedMessage = mc.CreateMessage(new Capitalizer());
var printer =
PrinterFactory.createPrinter(sr.Get("CONFIGURED_PRINTER"));
printer.print(formattedMessage);
}
}
Astrazioni errate
const Page1 = (props)
=
>
{
return (
<div class="container">
{
/
*
content
*
/
}
<div class="pop-up-dialog-error-one">
<h3>Inserire il nome del cliente
<
/
h3>
<div class="dialog-body">
<img src="trash"
/
>
<button value="Ok" onClick={onOnCustomer}
/
>
<
/
div>
<
/
div>
<div class="pop-up-dialog-error-two">
<h3>Errore durante il salvataggio
<
/
h3>
<div class="dialog-body">
<img src="error"
/
>
<button value="Ok" onClick={onSaveError}
/
>
<
/
div>
<
/
div>
<
/
div>
)
}
Astrazioni errate
const dialog = (props)
=
>
{
return (
<div class="pop-up-dialog">
<h3>{props.title}
<
/
h3>
<div class="dialog-body">
<img src={props.icon}
/
>
<button value="Ok" onClick={props.onOk}
/
>
<
/
div>
<
/
div>
)
}
const dialog = (props)
=
>
{
let buttons;
if (props.isYesNo) {
buttons = <div>
<button value="Yes" onClick={props.onYes}
/
>
<button value="No" onClick={props.onNo}
/
>
<
/
div>
} else {
buttons = <button value="Ok" onClick={props.onOk}
/
>
}
return (
<div class="pop-up-dialog">
<h3>{props.title}
<
/
h3>
<div class="dialog-body">
<img src={props.icon}
/
>
{buttons}
<
/
div>
<
/
div>
)
}
duplication is far cheaper than the wrong abstraction
prefer duplication over the wrong abstraction
Sandi Metz
Domain model monolitico
Bounded Context
CRUD con CQRS/ES
Alternative?
● Se è davvero solo CRUD: Rails/Django/Phoenix
● Oppure (CQS)
○ Separare lettura e scrittura (stesso db)
○ Salvare sempre tutti gli eventi
○ Salvare lo stato sul db
Microservizi!
The simplest thing that could possibly work
Servizi “logici”
Process Manager
Siamo sicuri che la Single Page Application sia sempre la scelta giusta?
Useless layers
Framework
● Non sempre semplificano
● Rendono il codice meno flessibile
● La magia (metaprogrammazione, macro, AOP, mixin, classi base) rende il
codice complesso da capire
● Disaccoppiare con ACL
● Preferire librerie a framework
Il linguaggio ha un impatto sulla semplicità?
STRUMENTI UTILI
Misurare
● Cyclomatic complexity
● Afferent Coupling
● Efferent Coupling
● Depth of inheritance
● Instability
● Abstraction level
● …
Modularizzare
Idee dall’FP: Funzioni pure e strutture dati immutabili
● Idee dalla programmazione funzionale
● Funzioni pure senza side effect
● Strutture dati immutabili
● High order function
I buoni vecchi principi
● DRY
● KISS
● OCP
● YAGNI
● SOLID or CUPID
● Composition over inheritance
● Be explicit
Approccio Prototipo/MVP
● Scrivere codice come se non ci fosse un domani
● Soluzioni quick&dirty per arrivare al risultato
● Validare il risultato
● Buttare e ricominciare
Test Driven Development Write
a failing
test
Make
the test
pasS
Refactor
Il TDD è Lo strumento
per scrivere codice semplice.
Obbliga a pensare cosa devi fare.
Focus su uno scope ridotto.
Le regole
● Non si può scrivere codice nuovo applicativo a meno che lo si faccia per
far diventare verde un test
● Non si può scrivere più di uno unit test che fallisce (gli errori di
compilazione sono fallimenti)
● Non è consentito scrivere codice di produzione non necessario a superare
l'unico test rosso
test "Scan empty code should return 0" do
assert Checkout.scan("")
=
=
0
end
defmodule Checkout do
def scan(_code) do
0
end
end
Test Driven Development
○ Un test difficile da scrivere è indice di complessità del codice che
dovrà testare
○ Troppo setup
○ Troppe dipendenze
○ Test poco parlante
Test Driven Development
○ Ragioni da utente in modo dichiarativo
○ Favorisce l’ortogonalità delle dipendenze
○ Non scriviamo mai codice inutile
○ Il design emerge un po’ alla volta
○ Accorcia feedback loop
○ I test fanno da documentazione
The simplest thing that could possibly work
The simplest thing that could possibly work
The simplest thing that could possibly work
4 rules of simple design
● Test Pass
● Express intent
● No duplication
● Small
As simple as possible, but no simpler. (Einstein)
The simplest thing that could possibly work
The simplest thing that could possibly work
EMANUELE DELBONO
Founder & Software developer @ CodicePlastico
emanuele@codiceplastico.com
@emadb
Grazie
emanuele@codiceplastico.com
1 of 61

Recommended

Cos’è la felicità per te? by
Cos’è la felicità per te?Cos’è la felicità per te?
Cos’è la felicità per te?Alessandro Colla
157 views58 slides
L'arte dello sviluppatore.pdf by
L'arte dello sviluppatore.pdfL'arte dello sviluppatore.pdf
L'arte dello sviluppatore.pdfMarco Fracassi
177 views59 slides
Book summary - What got you here Won't get you there by
Book summary - What got you here Won't get you thereBook summary - What got you here Won't get you there
Book summary - What got you here Won't get you thereNordiana Noordin
8.8K views24 slides
Ball Point Game: Self-organizing Your Flow of Work by
Ball Point Game: Self-organizing Your Flow of WorkBall Point Game: Self-organizing Your Flow of Work
Ball Point Game: Self-organizing Your Flow of WorkMark Grove
182 views28 slides
Ansoff matrix and disruptive innovation final v1.2 r mc donnell by
Ansoff matrix and disruptive innovation final v1.2 r mc donnell Ansoff matrix and disruptive innovation final v1.2 r mc donnell
Ansoff matrix and disruptive innovation final v1.2 r mc donnell Rich McDonnell
209 views17 slides
Mastering Feedback: You, the Team, the Product by
Mastering Feedback: You, the Team, the ProductMastering Feedback: You, the Team, the Product
Mastering Feedback: You, the Team, the ProductErin 'Folletto' Casali
19.6K views63 slides

More Related Content

What's hot

How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund... by
How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund...How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund...
How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund...Lighter Capital
1K views26 slides
Atomic Habits Virtual Workshop - Whole Book Summary by
Atomic Habits Virtual Workshop - Whole Book SummaryAtomic Habits Virtual Workshop - Whole Book Summary
Atomic Habits Virtual Workshop - Whole Book SummaryDr. Kristin Palmer
1K views146 slides
Out of the box thinking by
Out of the box thinkingOut of the box thinking
Out of the box thinkingSameer Mathur
1.4K views29 slides
Lego For Extended Scrum Simulation by
Lego For Extended Scrum SimulationLego For Extended Scrum Simulation
Lego For Extended Scrum SimulationAlexey Krivitsky
9.9K views8 slides
Good To Great by
Good To GreatGood To Great
Good To Greatswchase
2.2K views71 slides
The power of questions by
The power of questionsThe power of questions
The power of questionsMark Gillow
1.9K views23 slides

What's hot(9)

How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund... by Lighter Capital
How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund...How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund...
How To Raise Capital: Understanding Your Funding Stack & Optimizing Your Fund...
Lighter Capital1K views
Atomic Habits Virtual Workshop - Whole Book Summary by Dr. Kristin Palmer
Atomic Habits Virtual Workshop - Whole Book SummaryAtomic Habits Virtual Workshop - Whole Book Summary
Atomic Habits Virtual Workshop - Whole Book Summary
Out of the box thinking by Sameer Mathur
Out of the box thinkingOut of the box thinking
Out of the box thinking
Sameer Mathur1.4K views
Lego For Extended Scrum Simulation by Alexey Krivitsky
Lego For Extended Scrum SimulationLego For Extended Scrum Simulation
Lego For Extended Scrum Simulation
Alexey Krivitsky9.9K views
Good To Great by swchase
Good To GreatGood To Great
Good To Great
swchase2.2K views
The power of questions by Mark Gillow
The power of questionsThe power of questions
The power of questions
Mark Gillow1.9K views
What got you here; won't get you there by Vinod Mehra
What got you here; won't get you thereWhat got you here; won't get you there
What got you here; won't get you there
Vinod Mehra5.7K views
Tribal Leadership - Create the place where you long to belong (PPT) by Portia Tung
Tribal Leadership - Create the place where you long to belong (PPT)Tribal Leadership - Create the place where you long to belong (PPT)
Tribal Leadership - Create the place where you long to belong (PPT)
Portia Tung12K views

Similar to The simplest thing that could possibly work

Stop Meeting, Start Coding! by
Stop Meeting, Start Coding!Stop Meeting, Start Coding!
Stop Meeting, Start Coding!Giulio Roggero
841 views26 slides
Pro php refactoring by
Pro php refactoringPro php refactoring
Pro php refactoringFrancesco Trucchia
646 views30 slides
Wpc2019 - Distruggere DevOps, la storia di un vero team by
Wpc2019 - Distruggere DevOps, la storia di un vero teamWpc2019 - Distruggere DevOps, la storia di un vero team
Wpc2019 - Distruggere DevOps, la storia di un vero teamAlessandro Alpi
55 views43 slides
Intoduzione Alle Metodologie Agili by
Intoduzione Alle Metodologie AgiliIntoduzione Alle Metodologie Agili
Intoduzione Alle Metodologie AgiliStefano Leli
908 views51 slides
AngularJS 2.0 by
AngularJS 2.0 AngularJS 2.0
AngularJS 2.0 Vittorio Conte
1.5K views29 slides
Prototipazione Low-Code con AWS Step Functions by
Prototipazione Low-Code con AWS Step FunctionsPrototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step FunctionsCommit University
18 views50 slides

Similar to The simplest thing that could possibly work(20)

Wpc2019 - Distruggere DevOps, la storia di un vero team by Alessandro Alpi
Wpc2019 - Distruggere DevOps, la storia di un vero teamWpc2019 - Distruggere DevOps, la storia di un vero team
Wpc2019 - Distruggere DevOps, la storia di un vero team
Alessandro Alpi55 views
Intoduzione Alle Metodologie Agili by Stefano Leli
Intoduzione Alle Metodologie AgiliIntoduzione Alle Metodologie Agili
Intoduzione Alle Metodologie Agili
Stefano Leli908 views
Prototipazione Low-Code con AWS Step Functions by Commit University
Prototipazione Low-Code con AWS Step FunctionsPrototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step Functions
Java Unit Testing - Introduction by fgianneschi
Java Unit Testing - IntroductionJava Unit Testing - Introduction
Java Unit Testing - Introduction
fgianneschi2K views
Lean Web Solutions with WP [versione italiana] by Carlo Beschi
Lean Web Solutions with WP [versione italiana]Lean Web Solutions with WP [versione italiana]
Lean Web Solutions with WP [versione italiana]
Carlo Beschi1K views
Una fugace occhiata al Test Driven Development (2006) by Roberto Bettazzoni
Una fugace occhiata al Test Driven Development  (2006)Una fugace occhiata al Test Driven Development  (2006)
Una fugace occhiata al Test Driven Development (2006)
Roberto Bettazzoni478 views
A brief intro to TDD for a JUG-TAA event by Pietro Di Bello
A brief intro to TDD for a JUG-TAA eventA brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA event
Pietro Di Bello927 views
Evolutive User Experience Design by Luca Mascaro
Evolutive User Experience DesignEvolutive User Experience Design
Evolutive User Experience Design
Luca Mascaro958 views
Loosely Coupled Complexity - Unleash the power of your domain model by Francesca1980
Loosely Coupled Complexity - Unleash the power of your domain modelLoosely Coupled Complexity - Unleash the power of your domain model
Loosely Coupled Complexity - Unleash the power of your domain model
Francesca1980618 views
Fe05 test drivenjavascriptdevelopment by DotNetCampus
Fe05   test drivenjavascriptdevelopmentFe05   test drivenjavascriptdevelopment
Fe05 test drivenjavascriptdevelopment
DotNetCampus254 views
Test Driven Development @ Xe.Net by Mauro Servienti
Test Driven Development @ Xe.NetTest Driven Development @ Xe.Net
Test Driven Development @ Xe.Net
Mauro Servienti313 views

More from Emanuele DelBono

Una crescita armoniosa by
Una crescita armoniosaUna crescita armoniosa
Una crescita armoniosaEmanuele DelBono
1.6K views41 slides
A sip of Elixir by
A sip of ElixirA sip of Elixir
A sip of ElixirEmanuele DelBono
411 views35 slides
React.js in real world apps. by
React.js in real world apps. React.js in real world apps.
React.js in real world apps. Emanuele DelBono
6.2K views50 slides
An introduction to React.js by
An introduction to React.jsAn introduction to React.js
An introduction to React.jsEmanuele DelBono
7.3K views97 slides
From ActiveRecord to EventSourcing by
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingEmanuele DelBono
11.1K views44 slides
Ruby seen by a C# developer by
Ruby seen by a C# developerRuby seen by a C# developer
Ruby seen by a C# developerEmanuele DelBono
10.5K views53 slides

The simplest thing that could possibly work

  • 1. The simplest thing that could possibly work Emanuele DelBono - CodicePlastico
  • 2. Cos’è il codice “semplice”? / / OrderController public IEnumerable<OrderRes> GetOrders(int orderId) { return _dbGateway.Execute<OrderRes>("SP_GET_ORDER", orderId); }
  • 3. Disclaimer ● Tutto quello che dico può essere giusto e condiviso ma anche sbagliato e discorde dalle vostre opinioni, tutto dipende dal contesto, dai gusti e dalla vostra esperienza. ☮💙 ● L’obbiettivo di un team agile è consegnare software funzionante
  • 5. I costi di sviluppo crescono esponenzialmente all’aumentare della complessità
  • 6. La seniority ha un ruolo?
  • 7. E’ facile scrivere codice semplice? Simplicity and elegance are unpopular because they require hard work and discipline to achieve and education to be appreciated (Edsger W. Dijkstra)
  • 8. Cos’è il codice “semplice”? ● Facile da leggere ● Facile da capire ● Facile da cambiare e mantenere (o da cancellare)
  • 9. Cos’è il codice “semplice”? Assert.That(x).Should().Be().Greater().Than(42)
  • 12. [ { "id": 1, "title": "Clean Code", "authors": [ "Robert C. Martin" ], "year": 2008 }, { "id": 2, "title": "Structure and Interpretation of Computer Programs", "authors": [ "H. Abelson", “G. J. Sussman" ], "year": 1984 } ]
  • 19. Troppi cambi di requisiti
  • 21. Il software è un prodotto secondario di un processo di apprendimento ziobrando
  • 25. The hello world public static class Program { public static void SayHello(ISettingReader sr, IMessageComposer mc) { var message = sr.Get("MESSAGE"); var formattedMessage = mc.CreateMessage(new Capitalizer()); var printer = PrinterFactory.createPrinter(sr.Get("CONFIGURED_PRINTER")); printer.print(formattedMessage); } }
  • 26. Astrazioni errate const Page1 = (props) = > { return ( <div class="container"> { / * content * / } <div class="pop-up-dialog-error-one"> <h3>Inserire il nome del cliente < / h3> <div class="dialog-body"> <img src="trash" / > <button value="Ok" onClick={onOnCustomer} / > < / div> < / div> <div class="pop-up-dialog-error-two"> <h3>Errore durante il salvataggio < / h3> <div class="dialog-body"> <img src="error" / > <button value="Ok" onClick={onSaveError} / > < / div> < / div> < / div> ) }
  • 27. Astrazioni errate const dialog = (props) = > { return ( <div class="pop-up-dialog"> <h3>{props.title} < / h3> <div class="dialog-body"> <img src={props.icon} / > <button value="Ok" onClick={props.onOk} / > < / div> < / div> ) }
  • 28. const dialog = (props) = > { let buttons; if (props.isYesNo) { buttons = <div> <button value="Yes" onClick={props.onYes} / > <button value="No" onClick={props.onNo} / > < / div> } else { buttons = <button value="Ok" onClick={props.onOk} / > } return ( <div class="pop-up-dialog"> <h3>{props.title} < / h3> <div class="dialog-body"> <img src={props.icon} / > {buttons} < / div> < / div> ) }
  • 29. duplication is far cheaper than the wrong abstraction prefer duplication over the wrong abstraction Sandi Metz
  • 33. Alternative? ● Se è davvero solo CRUD: Rails/Django/Phoenix ● Oppure (CQS) ○ Separare lettura e scrittura (stesso db) ○ Salvare sempre tutti gli eventi ○ Salvare lo stato sul db
  • 38. Siamo sicuri che la Single Page Application sia sempre la scelta giusta?
  • 40. Framework ● Non sempre semplificano ● Rendono il codice meno flessibile ● La magia (metaprogrammazione, macro, AOP, mixin, classi base) rende il codice complesso da capire ● Disaccoppiare con ACL ● Preferire librerie a framework
  • 41. Il linguaggio ha un impatto sulla semplicità?
  • 43. Misurare ● Cyclomatic complexity ● Afferent Coupling ● Efferent Coupling ● Depth of inheritance ● Instability ● Abstraction level ● …
  • 45. Idee dall’FP: Funzioni pure e strutture dati immutabili ● Idee dalla programmazione funzionale ● Funzioni pure senza side effect ● Strutture dati immutabili ● High order function
  • 46. I buoni vecchi principi ● DRY ● KISS ● OCP ● YAGNI ● SOLID or CUPID ● Composition over inheritance ● Be explicit
  • 47. Approccio Prototipo/MVP ● Scrivere codice come se non ci fosse un domani ● Soluzioni quick&dirty per arrivare al risultato ● Validare il risultato ● Buttare e ricominciare
  • 48. Test Driven Development Write a failing test Make the test pasS Refactor Il TDD è Lo strumento per scrivere codice semplice. Obbliga a pensare cosa devi fare. Focus su uno scope ridotto.
  • 49. Le regole ● Non si può scrivere codice nuovo applicativo a meno che lo si faccia per far diventare verde un test ● Non si può scrivere più di uno unit test che fallisce (gli errori di compilazione sono fallimenti) ● Non è consentito scrivere codice di produzione non necessario a superare l'unico test rosso
  • 50. test "Scan empty code should return 0" do assert Checkout.scan("") = = 0 end defmodule Checkout do def scan(_code) do 0 end end
  • 51. Test Driven Development ○ Un test difficile da scrivere è indice di complessità del codice che dovrà testare ○ Troppo setup ○ Troppe dipendenze ○ Test poco parlante
  • 52. Test Driven Development ○ Ragioni da utente in modo dichiarativo ○ Favorisce l’ortogonalità delle dipendenze ○ Non scriviamo mai codice inutile ○ Il design emerge un po’ alla volta ○ Accorcia feedback loop ○ I test fanno da documentazione
  • 56. 4 rules of simple design ● Test Pass ● Express intent ● No duplication ● Small
  • 57. As simple as possible, but no simpler. (Einstein)
  • 60. EMANUELE DELBONO Founder & Software developer @ CodicePlastico emanuele@codiceplastico.com @emadb