SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
back to basics


          www.webshell.it                twitter.com/paolopolce
mercoledì 23 novembre 11
back to basics
           no matter how good your software development
           process is, you will still have to write some code
                            at some point.



                                                     twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Engineering



                                twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Engineering

                           • Software Projects Failure Reports
                                           60
                             Successful
                             Challenged
                                           45
                             Failed

                                           30


                                           15


                                            0
                                                 1995      2001

                                                                  twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Engineering

                           •   Engineering components are real, while
                               software is not.

                           •   Interactions are more predictable in
                               engineering.

                           •   Software is required to change during
                               development.

                           •   There has always been the attempt to carry
                               out software projects as if they were
                               engineering products. But it never worked.
                                                                        twitter.com/paolopolce
mercoledì 23 novembre 11
Bad news.
                           Programming is not engineering.




                                                             twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Science



                                       twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Science
                           •   The scientific method is “a method of procedure
                               that has characterized natural science since the 17th
                               century, consisting in systematic observation,
                               measurement, and experiment, and the formulation,
                               testing, and modification of hypotheses”




                                                                              twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Science
                           •   The scientific method is “a method of procedure
                               that has characterized natural science since the 17th
                               century, consisting in systematic observation,
                               measurement, and experiment, and the formulation,
                               testing, and modification of hypotheses”



                                        debug driven design?



                                                                              twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Art



                                                twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Art


                           • In fact, as in film,
                             music, sculpture,
                             painting and all the
                             other arts... software
                             is...



                                                      twitter.com/paolopolce
mercoledì 23 novembre 11
Writing Software Is Art
                                                              Men
                                                              Women

                           • In fact, as in film,
                                                        90


                              music, sculpture,        67,5

                              painting and all the
                                                        45
                              other arts... software
                              is...                    22,5


                                                         0
                                                              2011
                           equally distributed between men and women
                                                                twitter.com/paolopolce
mercoledì 23 novembre 11
Very disappointing.
         Programming is either not an art, or is not perceived as such.




                                                             twitter.com/paolopolce
mercoledì 23 novembre 11
There is no “Book”.
            Programming sits somewhere between engineering, science
              and art. Do not expect to find “The Book” that makes
                         everything clear about software.




                                                          twitter.com/paolopolce
mercoledì 23 novembre 11
Who writes software?
                  I have met software architects, software analystis, even
                         software evangelists and then... resources!




                                                                   twitter.com/paolopolce
mercoledì 23 novembre 11
Technical Skills Matter!



                                                  twitter.com/paolopolce
mercoledì 23 novembre 11
Do lots of deliberate practice
                           (J. Jagger “97 things every programmer should Know”)



       Athletes know the difference between training and performing.




                                                                                  twitter.com/paolopolce
mercoledì 23 novembre 11
TDD with MockObjects



                                             twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator



                    • as a user I want a NewsAggregator
                           that shows me news of my interest so
                           that I can read something, rather than
                           having to listen to this very boring
                           keynote.


                                                            twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                      design



                    • a NewsAggregator is something that
                     • receives user input in some way
                     • fetches the news somehow...       ???

                     • displays the news somewhere ???
                                                  ???
                                                        twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                         design



                           • are we supposed to write a
                             NewsAggregator without knowing how
                             it will get the news and how it will show
                             them to us !?
                                                  Yes, we are.


                                                                 twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                               signature candidates...


                    public class NewsAggregator {

                    	 public ????? show(String searchQuery) {...}
                    }




                                                                    twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                 signature candidates...


                    public class NewsAggregator {

                    	 public List<News> show(String searchQuery) {...}
                    }




               we tend to add useless getters only to be able to test our object via assertions
               on its internal state (i.e. the collection of news). But we are not supposed to access
               an object’s internals.
               Getters (and Setters) break the most important OOP principle: Encapsulation.
               List<News> is only a data container and is allowed to have a getter ;).
               But NewsAggregator is not a value object.
                                                                                          twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                   signature candidates...

                     public class NewsAggregator {

                     	 public void show(String searchQuery) {...}
                     }



                 ... but how do we test it, now ?!


                 Tip: replace the word “method” with “message”.

                 rather than saying “call the method Show() on the NewsAggregator”, we will say “send the message
                 Show() to the object NewsAggregator”.




                                                                                                       twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                 testing without accessing the state...

               Following the Single Responsibility Principle, we don’t want our object to do all
               the work. Instead, we ask the NewsAggregator to collaborate with other two
               objects: a NewsFetcher and a Display.
                                                                             note: I don’t generally
                                                                             prefix interfaces with the
               Create two empty interfaces.                                  “I”, especially in Java.

               public interface INewsFetcher {}
               public interface IDisplay {}


               Update the signature.

               public class NewsAggregator {

               	     public void show(String searchQuery,
                                      INewsFetcher newsFetcher,
                                      IDisplay anOutputDisplay) {...}
               }



                                                                                            twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                               testing without accessing the state...

               So far, we haven’t written any working code. We have only established that our
               NewsAggregator should work with a NewsFetcher and a Display which we have
               not written yet. And we are not going to!

               We’ll keep our focus on the NewsAggregator and “mock out” the two
               collaborators.

               	 public class NewsAggregatorTest {
               ...
                    public void setUp() throws Exception {
                  	 	 m_context = new Mockery();
                  	 	 m_mockDisplay = m_context.mock(IDisplay.class);
                  	 	 m_mockNewsFetcher = m_context.mock(INewsFetcher.class);
               	 }
               }


                                                                                      twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                    testing without accessing the state...

              	     @Test
              	     public void testNewsAggregator() {
              	     	 final List<News> fakeNews = new Vector<News>();
              	     	 fakeNews.add(new News("a news"));
              	     	 fakeNews.add(new News("some other news"));

              	     	      m_context.checking(new Expectations() {
              	     	      	 {
              	     	      	 	 oneOf(m_mockNewsFetcher).fetch("conferences");
              	     	      	 	 will(returnValue(fakeNews));
              	     	      	 	 exactly(2).of(m_mockDisplay).display(with(any(News.class)));
              	     	      	 }
              	     	      });

              	     	      NewsAggregator newsAggregator = new NewsAggregator();
              	     	      newsAggregator.show("conferences", m_mockNewsFetcher, m_mockDisplay);

              	     }




                                                                                       twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                            testing without accessing the state...

             There is still no need to implement any of the
             collaborators. We only provide them with the signatures
             needed for the test.

              public interface IDisplay {
              	 void display(News notizia);
              }

              public interface INewsFetcher {
              	 List<News> fetch(String queryString);
              }




                                                                     twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator


              public class NewsAggregator {

              	 public void show(String searchQuery,
                                 INewsFetcher newsFetcher,
                                 IDisplay anOutputDisplay) {

              	     	      List<News> someNews = newsFetcher.fetch(searchQuery);
              	     	      for (News aNews : someNews) {
              	     	      	 anOutputDisplay.display(aNews);
              	     	      }
              	     }
              }




                                                                        twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                       keep the focus!


                           •   The nice thing about the MockObjects
                               technique is that it lets you focus on what you
                               are testing.

                           •   We don’t know how the NewsFetcher or the
                               Display will be implemented. And we actually
                               don’t care. What we do know is that once the
                               collaborators will be available, our
                               NewsAggregator will work.


                                                                         twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                best practices with mockobjects

                           •   do not Mock value objects

                                •   It’s very bad and useless.

                           •   do not Mock classes.

                                •   It’s a code smell you can easily avoid.

                           •   avoid retro-fitting mocks into existing tests.

                           •   only mock interfaces.


                                                                              twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                     refactoring

              public class NewsAggregator {

              	     public void show(String searchQuery,
                                       INewsFetcher newsFetcher,
                                       IDisplay anOutputDisplay) {...}
              }


                                           move const dependencies
                                              to the constructor
              public class NewsAggregator {
              	 public NewsAggregator(INewsFetcher newsFetcher, IDisplay aDisplay) {...}
              	 public void show(String searchQuery) {...}
              }


                                                                               twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                   typical usage


                                                      constructor injection
              NewsAggregator aggregator =
                   new NewsAggregator(
                        new GoogleNewsAggregator(),
                        new ConsoleDisplay());




              aggregator.show("sport");




                                                                 twitter.com/paolopolce
mercoledì 23 novembre 11
Object Composition



                                                twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                  go patterns go!

             GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher()


              CompositeNewsFetcher(G,Y, B)

             NoDuplicatesDecoratorNewsFetcher(C)

              new NewsAggregator( NoDupes, new ConsoleDisplay())


                                                                   twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                  go patterns go!

             GoogleNewsFetcher() YahooNewsFetcher() CompositeNewsFetcher
                                                     BingNewsFetcher()
                                                       List<News> fetch(String query)
                                                       {
              CompositeNewsFetcher(G,Y, B)             gNews = m_googleFetcher.fetch(query);
                                                       yNews = m_yahooFetcher.fetch(query);
                                                       bNews = m_bingFetcher.fetch(query);

                                                     return g + y + b;
             NoDuplicatesDecorator       NewsFetcher }(C)

              new NewsAggregator( NoDupes, new ConsoleDisplay())


                                                                           twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                  go patterns go!

             GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher()


              CompositeNewsFetcher(G,Y, B)

             NoDuplicatesDecoratorNewsFetcher(C)

              new NewsAggregator( NoDupes, new ConsoleDisplay())


                                                                   twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                         go patterns go!

             GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher()
                NoDupesDecoratorNewsFetcher

                           List<News> fetch(String query)
                           {
              Composite                                     (G,Y, B)
                           someNews = m_Fetcher.fetch(query);
                                          NewsFetcher
                           return removeDuplicates(someNews);
                           }


             NoDuplicatesDecoratorNewsFetcher(C)

              new NewsAggregator( NoDupes, new ConsoleDisplay())


                                                                       twitter.com/paolopolce
mercoledì 23 novembre 11
Story #1 - News Aggregator
                                  go patterns go!

             GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher()


              CompositeNewsFetcher(G,Y, B)

             NoDuplicatesDecoratorNewsFetcher(C)

              new NewsAggregator( NoDupes, new ConsoleDisplay())


                                                                   twitter.com/paolopolce
mercoledì 23 novembre 11
Getters vs Messages

                               The Concert

                                                 twitter.com/paolopolce
mercoledì 23 novembre 11
Push your design, try to:
                           •   remove getters

                           •   remove singletons, or at least move them to the constructor,
                               and use them as a service locator

                           •   remove train wrecks

                           •   refactor as you go.

                           •   split responsibility as soon as your method reaches 5 or 10
                               lines of code.

                           •   do not make your tests more complicated than the actual
                               code, or you will have to test the tests.


                                                                                    twitter.com/paolopolce
mercoledì 23 novembre 11
Push your design, try to:


                           •   don’t be skeptical!

                           •   learn new stuff.You haven’t finished yet. No one has.

                           •   make your code a pleasant place to live in (see Richard Gabriel’s “code
                               habitability”)




                                                                                             twitter.com/paolopolce
mercoledì 23 novembre 11
Credits

                    •      mock roles, not objects                    (Mackinnon/Freeman/Pryce/Walnes)


                            •   http://www.jmock.org/oopsla2004.pdf



                    •      97 things every programmer should know                                        (K. Henney et al.)


                            •   http://www.amazon.com/Things-Every-Programmer-Should-Know/dp/0596809484


                    •      why writing software is not like engineering (T. Parr)
                            •   http://www.cs.usfca.edu/~parrt/doc/software-not-engineering.html




                                                                                                           twitter.com/paolopolce
mercoledì 23 novembre 11

Weitere ähnliche Inhalte

Kürzlich hochgeladen

The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 

Kürzlich hochgeladen (20)

The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 

Empfohlen

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
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
 

Empfohlen (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
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
 

Back to basics

  • 1. back to basics www.webshell.it twitter.com/paolopolce mercoledì 23 novembre 11
  • 2. back to basics no matter how good your software development process is, you will still have to write some code at some point. twitter.com/paolopolce mercoledì 23 novembre 11
  • 3. Writing Software Is Engineering twitter.com/paolopolce mercoledì 23 novembre 11
  • 4. Writing Software Is Engineering • Software Projects Failure Reports 60 Successful Challenged 45 Failed 30 15 0 1995 2001 twitter.com/paolopolce mercoledì 23 novembre 11
  • 5. Writing Software Is Engineering • Engineering components are real, while software is not. • Interactions are more predictable in engineering. • Software is required to change during development. • There has always been the attempt to carry out software projects as if they were engineering products. But it never worked. twitter.com/paolopolce mercoledì 23 novembre 11
  • 6. Bad news. Programming is not engineering. twitter.com/paolopolce mercoledì 23 novembre 11
  • 7. Writing Software Is Science twitter.com/paolopolce mercoledì 23 novembre 11
  • 8. Writing Software Is Science • The scientific method is “a method of procedure that has characterized natural science since the 17th century, consisting in systematic observation, measurement, and experiment, and the formulation, testing, and modification of hypotheses” twitter.com/paolopolce mercoledì 23 novembre 11
  • 9. Writing Software Is Science • The scientific method is “a method of procedure that has characterized natural science since the 17th century, consisting in systematic observation, measurement, and experiment, and the formulation, testing, and modification of hypotheses” debug driven design? twitter.com/paolopolce mercoledì 23 novembre 11
  • 10. Writing Software Is Art twitter.com/paolopolce mercoledì 23 novembre 11
  • 11. Writing Software Is Art • In fact, as in film, music, sculpture, painting and all the other arts... software is... twitter.com/paolopolce mercoledì 23 novembre 11
  • 12. Writing Software Is Art Men Women • In fact, as in film, 90 music, sculpture, 67,5 painting and all the 45 other arts... software is... 22,5 0 2011 equally distributed between men and women twitter.com/paolopolce mercoledì 23 novembre 11
  • 13. Very disappointing. Programming is either not an art, or is not perceived as such. twitter.com/paolopolce mercoledì 23 novembre 11
  • 14. There is no “Book”. Programming sits somewhere between engineering, science and art. Do not expect to find “The Book” that makes everything clear about software. twitter.com/paolopolce mercoledì 23 novembre 11
  • 15. Who writes software? I have met software architects, software analystis, even software evangelists and then... resources! twitter.com/paolopolce mercoledì 23 novembre 11
  • 16. Technical Skills Matter! twitter.com/paolopolce mercoledì 23 novembre 11
  • 17. Do lots of deliberate practice (J. Jagger “97 things every programmer should Know”) Athletes know the difference between training and performing. twitter.com/paolopolce mercoledì 23 novembre 11
  • 18. TDD with MockObjects twitter.com/paolopolce mercoledì 23 novembre 11
  • 19. Story #1 - News Aggregator • as a user I want a NewsAggregator that shows me news of my interest so that I can read something, rather than having to listen to this very boring keynote. twitter.com/paolopolce mercoledì 23 novembre 11
  • 20. Story #1 - News Aggregator design • a NewsAggregator is something that • receives user input in some way • fetches the news somehow... ??? • displays the news somewhere ??? ??? twitter.com/paolopolce mercoledì 23 novembre 11
  • 21. Story #1 - News Aggregator design • are we supposed to write a NewsAggregator without knowing how it will get the news and how it will show them to us !? Yes, we are. twitter.com/paolopolce mercoledì 23 novembre 11
  • 22. Story #1 - News Aggregator signature candidates... public class NewsAggregator { public ????? show(String searchQuery) {...} } twitter.com/paolopolce mercoledì 23 novembre 11
  • 23. Story #1 - News Aggregator signature candidates... public class NewsAggregator { public List<News> show(String searchQuery) {...} } we tend to add useless getters only to be able to test our object via assertions on its internal state (i.e. the collection of news). But we are not supposed to access an object’s internals. Getters (and Setters) break the most important OOP principle: Encapsulation. List<News> is only a data container and is allowed to have a getter ;). But NewsAggregator is not a value object. twitter.com/paolopolce mercoledì 23 novembre 11
  • 24. Story #1 - News Aggregator signature candidates... public class NewsAggregator { public void show(String searchQuery) {...} } ... but how do we test it, now ?! Tip: replace the word “method” with “message”. rather than saying “call the method Show() on the NewsAggregator”, we will say “send the message Show() to the object NewsAggregator”. twitter.com/paolopolce mercoledì 23 novembre 11
  • 25. Story #1 - News Aggregator testing without accessing the state... Following the Single Responsibility Principle, we don’t want our object to do all the work. Instead, we ask the NewsAggregator to collaborate with other two objects: a NewsFetcher and a Display. note: I don’t generally prefix interfaces with the Create two empty interfaces. “I”, especially in Java. public interface INewsFetcher {} public interface IDisplay {} Update the signature. public class NewsAggregator { public void show(String searchQuery, INewsFetcher newsFetcher, IDisplay anOutputDisplay) {...} } twitter.com/paolopolce mercoledì 23 novembre 11
  • 26. Story #1 - News Aggregator testing without accessing the state... So far, we haven’t written any working code. We have only established that our NewsAggregator should work with a NewsFetcher and a Display which we have not written yet. And we are not going to! We’ll keep our focus on the NewsAggregator and “mock out” the two collaborators. public class NewsAggregatorTest { ... public void setUp() throws Exception { m_context = new Mockery(); m_mockDisplay = m_context.mock(IDisplay.class); m_mockNewsFetcher = m_context.mock(INewsFetcher.class); } } twitter.com/paolopolce mercoledì 23 novembre 11
  • 27. Story #1 - News Aggregator testing without accessing the state... @Test public void testNewsAggregator() { final List<News> fakeNews = new Vector<News>(); fakeNews.add(new News("a news")); fakeNews.add(new News("some other news")); m_context.checking(new Expectations() { { oneOf(m_mockNewsFetcher).fetch("conferences"); will(returnValue(fakeNews)); exactly(2).of(m_mockDisplay).display(with(any(News.class))); } }); NewsAggregator newsAggregator = new NewsAggregator(); newsAggregator.show("conferences", m_mockNewsFetcher, m_mockDisplay); } twitter.com/paolopolce mercoledì 23 novembre 11
  • 28. Story #1 - News Aggregator testing without accessing the state... There is still no need to implement any of the collaborators. We only provide them with the signatures needed for the test. public interface IDisplay { void display(News notizia); } public interface INewsFetcher { List<News> fetch(String queryString); } twitter.com/paolopolce mercoledì 23 novembre 11
  • 29. Story #1 - News Aggregator public class NewsAggregator { public void show(String searchQuery, INewsFetcher newsFetcher, IDisplay anOutputDisplay) { List<News> someNews = newsFetcher.fetch(searchQuery); for (News aNews : someNews) { anOutputDisplay.display(aNews); } } } twitter.com/paolopolce mercoledì 23 novembre 11
  • 30. Story #1 - News Aggregator keep the focus! • The nice thing about the MockObjects technique is that it lets you focus on what you are testing. • We don’t know how the NewsFetcher or the Display will be implemented. And we actually don’t care. What we do know is that once the collaborators will be available, our NewsAggregator will work. twitter.com/paolopolce mercoledì 23 novembre 11
  • 31. Story #1 - News Aggregator best practices with mockobjects • do not Mock value objects • It’s very bad and useless. • do not Mock classes. • It’s a code smell you can easily avoid. • avoid retro-fitting mocks into existing tests. • only mock interfaces. twitter.com/paolopolce mercoledì 23 novembre 11
  • 32. Story #1 - News Aggregator refactoring public class NewsAggregator { public void show(String searchQuery, INewsFetcher newsFetcher, IDisplay anOutputDisplay) {...} } move const dependencies to the constructor public class NewsAggregator { public NewsAggregator(INewsFetcher newsFetcher, IDisplay aDisplay) {...} public void show(String searchQuery) {...} } twitter.com/paolopolce mercoledì 23 novembre 11
  • 33. Story #1 - News Aggregator typical usage constructor injection NewsAggregator aggregator = new NewsAggregator( new GoogleNewsAggregator(), new ConsoleDisplay()); aggregator.show("sport"); twitter.com/paolopolce mercoledì 23 novembre 11
  • 34. Object Composition twitter.com/paolopolce mercoledì 23 novembre 11
  • 35. Story #1 - News Aggregator go patterns go! GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher() CompositeNewsFetcher(G,Y, B) NoDuplicatesDecoratorNewsFetcher(C) new NewsAggregator( NoDupes, new ConsoleDisplay()) twitter.com/paolopolce mercoledì 23 novembre 11
  • 36. Story #1 - News Aggregator go patterns go! GoogleNewsFetcher() YahooNewsFetcher() CompositeNewsFetcher BingNewsFetcher() List<News> fetch(String query) { CompositeNewsFetcher(G,Y, B) gNews = m_googleFetcher.fetch(query); yNews = m_yahooFetcher.fetch(query); bNews = m_bingFetcher.fetch(query); return g + y + b; NoDuplicatesDecorator NewsFetcher }(C) new NewsAggregator( NoDupes, new ConsoleDisplay()) twitter.com/paolopolce mercoledì 23 novembre 11
  • 37. Story #1 - News Aggregator go patterns go! GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher() CompositeNewsFetcher(G,Y, B) NoDuplicatesDecoratorNewsFetcher(C) new NewsAggregator( NoDupes, new ConsoleDisplay()) twitter.com/paolopolce mercoledì 23 novembre 11
  • 38. Story #1 - News Aggregator go patterns go! GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher() NoDupesDecoratorNewsFetcher List<News> fetch(String query) { Composite (G,Y, B) someNews = m_Fetcher.fetch(query); NewsFetcher return removeDuplicates(someNews); } NoDuplicatesDecoratorNewsFetcher(C) new NewsAggregator( NoDupes, new ConsoleDisplay()) twitter.com/paolopolce mercoledì 23 novembre 11
  • 39. Story #1 - News Aggregator go patterns go! GoogleNewsFetcher() YahooNewsFetcher() BingNewsFetcher() CompositeNewsFetcher(G,Y, B) NoDuplicatesDecoratorNewsFetcher(C) new NewsAggregator( NoDupes, new ConsoleDisplay()) twitter.com/paolopolce mercoledì 23 novembre 11
  • 40. Getters vs Messages The Concert twitter.com/paolopolce mercoledì 23 novembre 11
  • 41. Push your design, try to: • remove getters • remove singletons, or at least move them to the constructor, and use them as a service locator • remove train wrecks • refactor as you go. • split responsibility as soon as your method reaches 5 or 10 lines of code. • do not make your tests more complicated than the actual code, or you will have to test the tests. twitter.com/paolopolce mercoledì 23 novembre 11
  • 42. Push your design, try to: • don’t be skeptical! • learn new stuff.You haven’t finished yet. No one has. • make your code a pleasant place to live in (see Richard Gabriel’s “code habitability”) twitter.com/paolopolce mercoledì 23 novembre 11
  • 43. Credits • mock roles, not objects (Mackinnon/Freeman/Pryce/Walnes) • http://www.jmock.org/oopsla2004.pdf • 97 things every programmer should know (K. Henney et al.) • http://www.amazon.com/Things-Every-Programmer-Should-Know/dp/0596809484 • why writing software is not like engineering (T. Parr) • http://www.cs.usfca.edu/~parrt/doc/software-not-engineering.html twitter.com/paolopolce mercoledì 23 novembre 11