SlideShare une entreprise Scribd logo
1  sur  17
Refactoring
Group 1
 Bad Smells in Code

 Building Tests

 Composing Methods


   Confidential          2
Bad Smells in Code


Who          What            When


Where        Why             How

              Confidential          3
Confidential   4
…..
<app key=“ContactEmailAddress” value=“jdoe@initrode.com” />
…..

                                             app.config (revision 1)




…..
<app key=“sContactEmailAddress” value=“jdoe@initrode.com” />
…..

                                             app.config (revision 2)




                              Confidential                             5
// I decided not to use built-in feature to
                                                                     convert string to boolean

                                                                     if ( is_string($switch) ) {
                                                                            switch ($switch) {
      Public Function Save() As Boolean                                        case 'false' :
        Try                                                                    case 'down' :
           SaveMeeting()                                                       case 'off' :
        Catch ex As Exception                                                  case 'not' :
           Throw ex                                                            case '0' :
        End Try                                                                case '' :
      End Function                                                                $switch = false;
                                                                                  break;

                                                                               default :
                                                                                 $switch = true;
                                                                                 break;
                                                                           }
                                                                     }
<a href="/the/path/to/the/url"
onclick="window.open(this.getAttribute('href'),'_blank');return false;">
 link text
</a>


                                                          Confidential                                             6
// Translates Roman Numbers to
                                                           Decimal Numbers
Function GetNewGuid()                                      public string rom2num(string r)
  Dim cnGuid, rsGuid                                       {
                                                              if (r == "I") return "1";
  Set cnGuid = CreateObject("ADODB.Connection")               if (r == "II") return "2";
  Set rsGuid = CreateObject("ADODB.Recordset")                if (r == "III") return "3";
                                                              if (r == "IV") return "4";
  cnGuid.Open = _                                             if (r == "V") return "5";
    "Provider=SQLOLEDB.1;" +                                  if (r == "VI") return "6";
    "Data Source=<production server>; " +                     if (r == "VII") return "7";
    "Initial Catalog=<production DB> " +                      if (r == "VIII") return "8";
    "user id = '********';" +                                 if (r == "IX") return "9";
    "password='*********'""                                   //
                                                              // Snipped LOTS of "code" here
  rsGuid.Open "SELECT newid() as Guid", cnGuid                //
                                                              if (r == "MMVIII") return "2008";
  If Not rsGuid.EOF Then                                      if (r == "MMIX") return "2009";
     GetNewGuid = rsGuid("Guid").Value                        if (r == "MMX") return "2010";
  End If                                                      if (r == "MMXI") return "2011";
End Function                                                  return "E";
                                                           }




                                            Confidential                                          7
function checkdata() {
  dataok = true;
  t1 = document.forms.signup.firstName.value;
  t2 = document.forms.signup.lastName.value;
  t9 = document.forms.signup.locale.options.selectedIndex;
  t10 = document.forms.signup.currency.options.selectedIndex;
  t11 = document.forms.signup.timezone.options.selectedIndex;
  t12 = document.forms.signup.packetType.options.selectedIndex;
  t13 = document.forms.signup.captcha_code.value;
  if (t1 == '' || t2 == '„ ) {
      alert("Please fill-up all the fields");
      dataok = false; return(dataok);}
  if (t4 != t5) {
      alert("Please enter the password again");
      dataok = false; return(dataok);}
  if (t9 == 0) {
      alert("Please select a locale");
      dataok = false; return(dataok);}
  if (t10 == 0) {
      alert("Please select a currency");
      dataok = false; return(dataok);}
  return(dataok);
}




                                Confidential                      8
// Self-document code

private bool TrueBecauseThisEventDoesNotRegistrictBasedUponActivityType()
{
  return true;
}

private bool FalseBecauseNoActivityTypesAreAvailableForUsersWhoAreNotLoggedIn()
{
  return false;
}


private bool NoActivityTypesAreAttachedToThisEvent(IEnumerable<ActivityType>
activityTypes)
{
  return activityTypes.Any() == false;
}




                                    Confidential                                  9
# Find the last 200 transactions
    logging.debug( "Finding the last 600 transactions" )
    ConnMysql.query("select Id from Transactions order by ts desc limit 0,10000 ")




private void EditTDemensions(bool blnYes)
{
   //bln is the introvert of blnYes
   bool bln = (blnYes ? false : true);

    //Display or Hide buttons
    btnDemensionsEdit.Visible = bln;
    btnDemensionsSave.Visible = blnYes;
    btnDemensionsCancel.Visible = blnYes;
}




                                     Confidential                                    10
 Bad Smells in Code

   Building Tests

 Composing Methods


   Confidential        11
Self-testing Code




      Confidential   12
Without Self-testing Code

Developer jobs




 Fix bugs   Others

                     Confidential   13
 Bad Smells in Code


 Building Tests

   Composing Methods


   Confidential        14
Catalog of Refactorings


Composing Methods Simplifying Conditional
Moving Features    Expressions
 Between Objects   Making Method Calls
Organizing Data    Simpler
                   Dealing with
                    Generalization


                   Confidential           15
Inline Method
  Extract Method
                           Substitute Algorithm
Replace Temp with Query           Inline Temp
         Introduce Explaining Variable

  Replace Method with Method Object
    Split Temporary Variable
Remove Assignments to Parameters
                   Confidential             16
THANK YOU

Contenu connexe

Tendances

Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
Wait queue
Wait queueWait queue
Wait queueRoy Lee
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6Richard Jones
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayNatasha Murashev
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testingVisual Engineering
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScriptSimon Willison
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiMark
 
Hardened JavaScript
Hardened JavaScriptHardened JavaScript
Hardened JavaScriptKrisKowal2
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기Wanbok Choi
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8XSolve
 
PHP Traits
PHP TraitsPHP Traits
PHP Traitsmattbuzz
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbsesiddharthjha34
 
RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017Wanbok Choi
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعةشرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعةجامعة القدس المفتوحة
 
Swift internals
Swift internalsSwift internals
Swift internalsJung Kim
 

Tendances (20)

Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Wait queue
Wait queueWait queue
Wait queue
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6
 
Specs2
Specs2Specs2
Specs2
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
 
Hardened JavaScript
Hardened JavaScriptHardened JavaScript
Hardened JavaScript
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8
 
PHP Traits
PHP TraitsPHP Traits
PHP Traits
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbse
 
RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعةشرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Swift internals
Swift internalsSwift internals
Swift internals
 

En vedette

FCP Webinar 7 - 13th April 2011
FCP Webinar 7 - 13th April 2011FCP Webinar 7 - 13th April 2011
FCP Webinar 7 - 13th April 2011Dent
 
Soal quizz lp3i manyar-corel draw
Soal quizz lp3i manyar-corel drawSoal quizz lp3i manyar-corel draw
Soal quizz lp3i manyar-corel drawprihardini
 
Firefox OSの何が嬉しいか
Firefox OSの何が嬉しいかFirefox OSの何が嬉しいか
Firefox OSの何が嬉しいかTakao Sumitomo
 
Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014
Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014
Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014Duy Lâm
 
Overview of character encoding
Overview of character encodingOverview of character encoding
Overview of character encodingDuy Lâm
 
KMS TechCon 2014 - Interesting in JavaScript
KMS TechCon 2014 - Interesting in JavaScriptKMS TechCon 2014 - Interesting in JavaScript
KMS TechCon 2014 - Interesting in JavaScriptDuy Lâm
 
Amazon Web Services
Amazon Web ServicesAmazon Web Services
Amazon Web ServicesDuy Lâm
 
Building creative expression
Building creative expressionBuilding creative expression
Building creative expressionrichardofaustin
 
Caching and IPC with Redis
Caching and IPC with RedisCaching and IPC with Redis
Caching and IPC with RedisKMS Technology
 
Advantages of Cassandra's masterless architecture
Advantages of Cassandra's masterless architectureAdvantages of Cassandra's masterless architecture
Advantages of Cassandra's masterless architectureDuy Lâm
 
Visual Resume
Visual ResumeVisual Resume
Visual ResumeCriser01
 

En vedette (14)

FCP Webinar 7 - 13th April 2011
FCP Webinar 7 - 13th April 2011FCP Webinar 7 - 13th April 2011
FCP Webinar 7 - 13th April 2011
 
Soal quizz lp3i manyar-corel draw
Soal quizz lp3i manyar-corel drawSoal quizz lp3i manyar-corel draw
Soal quizz lp3i manyar-corel draw
 
Firefox OSの何が嬉しいか
Firefox OSの何が嬉しいかFirefox OSの何が嬉しいか
Firefox OSの何が嬉しいか
 
Copyright rev0.5
Copyright rev0.5Copyright rev0.5
Copyright rev0.5
 
Copyright rev0.3
Copyright rev0.3Copyright rev0.3
Copyright rev0.3
 
Mocha
Mocha Mocha
Mocha
 
Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014
Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014
Building Single-page Web Applications with AngularJS @ TechCamp Sai Gon 2014
 
Overview of character encoding
Overview of character encodingOverview of character encoding
Overview of character encoding
 
KMS TechCon 2014 - Interesting in JavaScript
KMS TechCon 2014 - Interesting in JavaScriptKMS TechCon 2014 - Interesting in JavaScript
KMS TechCon 2014 - Interesting in JavaScript
 
Amazon Web Services
Amazon Web ServicesAmazon Web Services
Amazon Web Services
 
Building creative expression
Building creative expressionBuilding creative expression
Building creative expression
 
Caching and IPC with Redis
Caching and IPC with RedisCaching and IPC with Redis
Caching and IPC with Redis
 
Advantages of Cassandra's masterless architecture
Advantages of Cassandra's masterless architectureAdvantages of Cassandra's masterless architecture
Advantages of Cassandra's masterless architecture
 
Visual Resume
Visual ResumeVisual Resume
Visual Resume
 

Similaire à Refactoring group 1 - chapter 3,4,6

Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113SOAT
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesAndrey Karpov
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConRafael Dohms
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practicesManav Gupta
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboardsDenis Ristic
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Eyal Vardi
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 TrainingChris Chubb
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 

Similaire à Refactoring group 1 - chapter 3,4,6 (20)

Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 Training
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Refactoring group 1 - chapter 3,4,6

  • 2.  Bad Smells in Code  Building Tests  Composing Methods Confidential 2
  • 3. Bad Smells in Code Who What When Where Why How Confidential 3
  • 5. ….. <app key=“ContactEmailAddress” value=“jdoe@initrode.com” /> ….. app.config (revision 1) ….. <app key=“sContactEmailAddress” value=“jdoe@initrode.com” /> ….. app.config (revision 2) Confidential 5
  • 6. // I decided not to use built-in feature to convert string to boolean if ( is_string($switch) ) { switch ($switch) { Public Function Save() As Boolean case 'false' : Try case 'down' : SaveMeeting() case 'off' : Catch ex As Exception case 'not' : Throw ex case '0' : End Try case '' : End Function $switch = false; break; default : $switch = true; break; } } <a href="/the/path/to/the/url" onclick="window.open(this.getAttribute('href'),'_blank');return false;"> link text </a> Confidential 6
  • 7. // Translates Roman Numbers to Decimal Numbers Function GetNewGuid() public string rom2num(string r) Dim cnGuid, rsGuid { if (r == "I") return "1"; Set cnGuid = CreateObject("ADODB.Connection") if (r == "II") return "2"; Set rsGuid = CreateObject("ADODB.Recordset") if (r == "III") return "3"; if (r == "IV") return "4"; cnGuid.Open = _ if (r == "V") return "5"; "Provider=SQLOLEDB.1;" + if (r == "VI") return "6"; "Data Source=<production server>; " + if (r == "VII") return "7"; "Initial Catalog=<production DB> " + if (r == "VIII") return "8"; "user id = '********';" + if (r == "IX") return "9"; "password='*********'"" // // Snipped LOTS of "code" here rsGuid.Open "SELECT newid() as Guid", cnGuid // if (r == "MMVIII") return "2008"; If Not rsGuid.EOF Then if (r == "MMIX") return "2009"; GetNewGuid = rsGuid("Guid").Value if (r == "MMX") return "2010"; End If if (r == "MMXI") return "2011"; End Function return "E"; } Confidential 7
  • 8. function checkdata() { dataok = true; t1 = document.forms.signup.firstName.value; t2 = document.forms.signup.lastName.value; t9 = document.forms.signup.locale.options.selectedIndex; t10 = document.forms.signup.currency.options.selectedIndex; t11 = document.forms.signup.timezone.options.selectedIndex; t12 = document.forms.signup.packetType.options.selectedIndex; t13 = document.forms.signup.captcha_code.value; if (t1 == '' || t2 == '„ ) { alert("Please fill-up all the fields"); dataok = false; return(dataok);} if (t4 != t5) { alert("Please enter the password again"); dataok = false; return(dataok);} if (t9 == 0) { alert("Please select a locale"); dataok = false; return(dataok);} if (t10 == 0) { alert("Please select a currency"); dataok = false; return(dataok);} return(dataok); } Confidential 8
  • 9. // Self-document code private bool TrueBecauseThisEventDoesNotRegistrictBasedUponActivityType() { return true; } private bool FalseBecauseNoActivityTypesAreAvailableForUsersWhoAreNotLoggedIn() { return false; } private bool NoActivityTypesAreAttachedToThisEvent(IEnumerable<ActivityType> activityTypes) { return activityTypes.Any() == false; } Confidential 9
  • 10. # Find the last 200 transactions logging.debug( "Finding the last 600 transactions" ) ConnMysql.query("select Id from Transactions order by ts desc limit 0,10000 ") private void EditTDemensions(bool blnYes) { //bln is the introvert of blnYes bool bln = (blnYes ? false : true); //Display or Hide buttons btnDemensionsEdit.Visible = bln; btnDemensionsSave.Visible = blnYes; btnDemensionsCancel.Visible = blnYes; } Confidential 10
  • 11.  Bad Smells in Code  Building Tests  Composing Methods Confidential 11
  • 12. Self-testing Code Confidential 12
  • 13. Without Self-testing Code Developer jobs Fix bugs Others Confidential 13
  • 14.  Bad Smells in Code  Building Tests  Composing Methods Confidential 14
  • 15. Catalog of Refactorings Composing Methods Simplifying Conditional Moving Features Expressions Between Objects Making Method Calls Organizing Data Simpler Dealing with Generalization Confidential 15
  • 16. Inline Method Extract Method Substitute Algorithm Replace Temp with Query Inline Temp Introduce Explaining Variable Replace Method with Method Object Split Temporary Variable Remove Assignments to Parameters Confidential 16

Notes de l'éditeur

  1. Who is it about?  other presentsWhat happened?  other presentsWhen did it take place?Where did it take place?  computerWhy did it happen?  other presentsHow did it happen?  other presentsGive audience some real example indications that there is trouble that can be solved by a refactoringhttp://thedailywtf.com/Articles/FAIL-FAIL,FAIL-FAIL,FAIL-FAIL-and-More.aspxhttp://thedailywtf.com/Comments/The-Bit-Setter.aspxhttp://thedailywtf.com/Comments/Mybad.aspxhttp://thedailywtf.com/Articles/Self-Documenting.aspxhttp://thedailywtf.com/Articles/Roman-Enumeration.aspx
  2. Add a Hungarian Notation prefix to a configuration file setting, in case we weren&apos;t sure that &apos;ContactEmailAddress&apos; was a string
  3. This is to convert a string to false value and don’t want to use built-in language feature
  4. self-document code 
  5. what the link between the 3 numbers is
  6. Vaccine is kind of alike to self-testing code. It operates the system (virus) on real environment (body) in safe manner so that issues can be found at very soon
  7. Some time is spent figuring out what ought to be going on, some time is spent designing, but most time is spent debugging. Fixing the bug is usually pretty quick, but finding it is a nightmare
  8. Sample coffee script to demonstrate : extract method, introduce explaining variable, replace temp with queryStoryBoard = require &apos;./storyboard&apos;Constants = require &apos;./core/Constants&apos;class ViewerScreen extends GameScreenplayerMovesInChineseChess: (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.PLAYER_MOVES_IN_CHINESE_CHESS_TABLE if response.code == Global.CODE.BROADCASTING_REQUEST if response.data.player == Constants.HOST_ROLE @view.startTopTimer() @view.stopBottomTimer() else response.data.player == Constants.GUEST_ROLE @view.stopTopTimer() @view.startBottomTimer()killChineseChess: (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.KILL_CHINESE_CHESS_TABLE if response.code == Global.CODE.BROADCASTING_REQUEST data = response.data if @match.status &lt; Global.GAME_STATUS.PLAYING @msgBar.showdata.username + &apos; &apos; + Global.MUI.HAS_QUITEDhostKicksGuestOutOfChineseChess : (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.KICKS_GUEST_OUT_OF_CHINESE_CHESS_TABLE if response.code == Global.CODE.BROADCASTING_REQUEST data = response.data @msgBar.show @match.host.username + &apos; &apos; + Global.MUI.KICKS + &apos; &apos; + @match.guest.usernamedetailsOfTableCallback: (response) -&gt; if response.group == Global.GROUP.CHINESE_CHESS and response.type == Global.TYPE.GET_DETAILS_OF_CHINESE_CHESS_TABLE if response.code == Global.CODE.SUCCESSFUL_REQUEST data = response.data if @match.status &gt;= Global.GAME_STATUS.WAITING then# ... else if response.code == Global.CODE.FAILED_REQUEST# ...