SlideShare a Scribd company logo
1 of 43
Download to read offline
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

More Related Content

Recently uploaded

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 

Recently uploaded (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
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
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
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...
 

Back to Basics: Exploring the Nature of Software Development

  • 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