SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
IMUTABILIDADE
FW7 | Roberto Umbelino
Programação
O QUE ÉI M U T A B I L I D A D E É A U M A C A R A C T E R Í S T I C A O U
Q U A L I D A D E D E A L G O Q U E N Ã O P O D E S E R
A L T E R A D O .
IMUTABILIDADE
E S S E É O T O B Y
Toby é um belo cachorrinho, ele
nasceu sendo um cachorro.
M A S E L E C R E S C E U
O Toby cresceu mas mesmo assim ele
continuou sendo um cachorro.
O F I M D A L I N H A
PASMEM, o Toby se manteve como um
cachorro até o final de sua vida.
O Toby nunca vai poder ser uma galinha, uma vez
que ele foi "criado" como cachorro, irá
permanecer cachorro até o final de sua vida.
FREDERICA
T R A Z E N D O P A R A O C O N T E X T O
D A P R O G R A M A Ç Ã O
E NA
PROGRAMAÇÃO?
I N Í C I O
Tudo aquilo que for
criado/instanciado deve manter o
estado.
F I M
Deve permanecer o mesmo estado
até o final do seu ciclo de vida.
C O M O F A Ç O P A R A A L T E R A R U M V A L O R ?
NA PRÁTICA
Apesar de não ser possível alterar algo imutável, é
possível usá lo para criação de um novo valor, uma
variável.
Imutável
Não é possível realizar a mutação do valor da
variável, mas sempre que necessário pode ser
criado uma nova variável apartir de outra.
Inicialmente entender e trabalhar com
imutabilidade é realmente confuso, porque na
grande maioria das vezes aprendemos a fazer a
solução mutando os valores, porque aparenta ser
mais simples e "mais fácil" de resolver.
AHH AGORA EU ENTENDI
Vilão Side Effects
Um código mutável não tem a garantia de que
quando ser executado irá realizar a mesma
operação.
EXEMPLO DE SIDE EFFECT
MUTÁVEL
G R A N D E C H A N C E D E G E R A R O S
F A M O S O S S I D E E F F E C T S , T E
D E I X A N D O N A S E X T A F E I R A A
N O I T E C O R R I G I N D O O E R R O .
IMUTÁVEL
S E M S I D E E F F E C T S , P A R A V O C Ê
F I C A R T R A N Q U I L Ã O C U R T I N D O O
B A T I D Ã O .
PRÓS
C l e a n c o d e
P e n s a m e n t o f u n c i o n a l
E v i t a r s i d e e f f e c t s
CONTRAS
C o m p l e x i d a d e
C a r o p a r a m e m ó r i a
EXEMPLOSE X E M P L O S N A P R Á T I C A D E A L G U N S C E N Á R I O S R E A I S .
BORAPRATICAR?
PUSH NO ARRAY
CONCATENANDO
VALORES NA STRING
SOMANDO VALORES DO
ARRAY
AGRUPANDO VALORES
C O N S I D E R A Ç Õ E S F I N A I S
A imutabilidade apesar de complexa no começo
é muito válida de ser aplicada, os ganhos de
legibilidade de código e principalmente a
diminuição de bugs no código fazem o eforço
valer a pena.
A FW7 possui um respositório público de desafios
no github para ajudar e estimular os
desenvolvedores a realizar a solução de problemas
de forma mais criativa possível.
Lá você irá poder praticar muito a imutabilidade.
EXTRA
OBRIGADO

Mais conteúdo relacionado

Destaque

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Destaque (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Imta-: Imutabilidade na programação

  • 1. IMUTABILIDADE FW7 | Roberto Umbelino Programação
  • 2. O QUE ÉI M U T A B I L I D A D E É A U M A C A R A C T E R Í S T I C A O U Q U A L I D A D E D E A L G O Q U E N Ã O P O D E S E R A L T E R A D O . IMUTABILIDADE
  • 3. E S S E É O T O B Y Toby é um belo cachorrinho, ele nasceu sendo um cachorro. M A S E L E C R E S C E U O Toby cresceu mas mesmo assim ele continuou sendo um cachorro. O F I M D A L I N H A PASMEM, o Toby se manteve como um cachorro até o final de sua vida.
  • 4. O Toby nunca vai poder ser uma galinha, uma vez que ele foi "criado" como cachorro, irá permanecer cachorro até o final de sua vida. FREDERICA
  • 5. T R A Z E N D O P A R A O C O N T E X T O D A P R O G R A M A Ç Ã O E NA PROGRAMAÇÃO?
  • 6. I N Í C I O Tudo aquilo que for criado/instanciado deve manter o estado. F I M Deve permanecer o mesmo estado até o final do seu ciclo de vida.
  • 7.
  • 8. C O M O F A Ç O P A R A A L T E R A R U M V A L O R ? NA PRÁTICA
  • 9. Apesar de não ser possível alterar algo imutável, é possível usá lo para criação de um novo valor, uma variável.
  • 10. Imutável Não é possível realizar a mutação do valor da variável, mas sempre que necessário pode ser criado uma nova variável apartir de outra.
  • 11. Inicialmente entender e trabalhar com imutabilidade é realmente confuso, porque na grande maioria das vezes aprendemos a fazer a solução mutando os valores, porque aparenta ser mais simples e "mais fácil" de resolver. AHH AGORA EU ENTENDI
  • 12. Vilão Side Effects Um código mutável não tem a garantia de que quando ser executado irá realizar a mesma operação.
  • 13. EXEMPLO DE SIDE EFFECT
  • 14. MUTÁVEL G R A N D E C H A N C E D E G E R A R O S F A M O S O S S I D E E F F E C T S , T E D E I X A N D O N A S E X T A F E I R A A N O I T E C O R R I G I N D O O E R R O . IMUTÁVEL S E M S I D E E F F E C T S , P A R A V O C Ê F I C A R T R A N Q U I L Ã O C U R T I N D O O B A T I D Ã O .
  • 15. PRÓS C l e a n c o d e P e n s a m e n t o f u n c i o n a l E v i t a r s i d e e f f e c t s CONTRAS C o m p l e x i d a d e C a r o p a r a m e m ó r i a
  • 16. EXEMPLOSE X E M P L O S N A P R Á T I C A D E A L G U N S C E N Á R I O S R E A I S . BORAPRATICAR?
  • 21. C O N S I D E R A Ç Õ E S F I N A I S A imutabilidade apesar de complexa no começo é muito válida de ser aplicada, os ganhos de legibilidade de código e principalmente a diminuição de bugs no código fazem o eforço valer a pena.
  • 22. A FW7 possui um respositório público de desafios no github para ajudar e estimular os desenvolvedores a realizar a solução de problemas de forma mais criativa possível. Lá você irá poder praticar muito a imutabilidade. EXTRA