SlideShare a Scribd company logo
1 of 28
München/HQ Bamberg Berlin Đà Nẵng Dresden Grenoble Hamburg Cologne Leipzig Nuremberg Prague Washington Zug
Make Legacy Code Great Again
Ezekiel Olasehinde
Đà Nẵng, 11/07/2020
11.07.2020 2
About me
Software Engineer
IT Freak
Scrum
Master
Web
Application
Developer
11.07.2020 3
Basic attributes
not
documented
unsupported
technology
not tested
inherited
11.07.2020 4
How is legacy code made?
Technical Debt
Forgotten technology
Ignorance
11.07.2020 5
Technical Debt
11.07.2020 6
Refactoring is a control technique for improving the
design on an existing code base.
What is refactoring ?
11.07.2020 7
Why you should refactor?
11.07.2020 8
Unit test
Prevents regressions
Verification
Documentation
11.07.2020 9
Approval testing
11.07.2020 10
Fixing legacy codes – Where to start?
11.07.2020 11
11.07.2020 12
Customer call
11.07.2020 13
One true legacy validation
…
…
public String doLegacyValidation(ValidatableUser validatableUser) {
//session based validation
if (!UserSession.getInstance().isUserLoggedIn() && validatableUser.isValidationAllowed()) {
return "Validation impossible with logged in user";
}
String errorMessage = "";
//email validation
if (StringUtils.isEmpty(validatableUser.getEmail())) {
errorMessage += "email is required";
} else if (!validatableUser.getEmail().contains("@")) errorMessage += "this is not an email n";
else if (validatableUser.getEmail().contains("@")) {
String[] emailSplit = validatableUser.getEmail().split("@");
if (emailSplit[1].split(".").length < 2)
errorMessage += "Unrecognized email pattern";
}
//zip code validation
try {
int zip = Integer.parseInt(validatableUser.getZipCode());
if (validatableUser.getZipCode().length() < 6) {
errorMessage += "zip code needs to be atleast of length of 6";
} else if (validatableUser.getZipCode().length() > 7) {
errorMessage += "zip code length must not be more than 7";
}
int countOfFives = 0;
for (int a = 0; a < validatableUser.getZipCode().length(); a++) {
if (validatableUser.getZipCode().charAt(a) == '5') {
countOfFives++;
}
}
if (countOfFives < 2) {
errorMessage += "zip code failed the requirement of atleast double 5";
}
if (StringUtils.pathEquals(validatableUser.getUsername(), validatableUser.getPassword().getKey())) {
errorMessage += "Invalid confirm password, kindly check our password policyn";
}
} catch (NumberFormatException n) {
errorMessage += "unrecognized zip code";
}
//username validation
if (Arrays.asList("admin", "systemadmin", "annoymous").contains(validatableUser.getUsername().toLowerCase())) {
errorMessage += "Invalid username, kindly check our username policyn";
} else if (length(validatableUser.getUsername(), ' ') < 6) {
errorMessage += "Invalid username, kindly check our username policyn";
} else if (length(validatableUser.getUsername(), ' ') > 10) {
errorMessage += "Invalid username, kindly check our username policyn";
}
//password validation
if (Arrays.asList("admin", "sysadmin", "anonymous").contains(validatableUser.getPassword().getKey().toLowerCase())) {
errorMessage += "Invalid password, kindly check our password policyn";
} else if (length(validatableUser.getPassword().getKey(), ' ') < 6) {
errorMessage += "Invalid password, kindly check our password policyn";
} else if (length(validatableUser.getPassword().getKey(), ' ') > 10) {
errorMessage += "Invalid password, kindly check our password policyn";
}
if (Arrays.asList("admin", "sysadmin", "anonymous").contains(validatableUser.getPassword().getValue().toLowerCase())) {
errorMessage += "Invalid confirm password, kindly check our password policyn";
} else if (length(validatableUser.getPassword().getValue(), ' ') < 6) {
errorMessage += "Invalid confirm password kindly check our password policyn";
} else if (length(validatableUser.getPassword().getValue(), ' ') > 10) {
errorMessage += "Invalid confirm password, kindly check our password policyn";
}
return errorMessage;
}
…
…
11.07.2020 14
Problem
...
...
if (!UserSession.getInstance().isUserLoggedIn() && validatableUser.isValidationAllowed())
{
return "Validation impossible with logged in user";
}
…
…
11.07.2020 15
Problem
//username validation
if (Arrays.asList("admin", "systemadmin",
"annoymous").contains(validatableUser.getUsername().toLowerCase())) {
errorMessage += "Invalid username, kindly check our username policyn";
} else if (length(validatableUser.getUsername(), ' ') < 6) {
errorMessage += "Invalid username, kindly check our username policyn";
} else if (length(validatableUser.getUsername(), ' ') > 10) {
errorMessage += "Invalid username, kindly check our username policyn";
}
…
…
11.07.2020 16
Eliminate singleton
private final UserSession userSession;
public boolean isValidationAllowed(ValidatableUser validatableUser) {
return !userSession.isUserLoggedIn() && validatableUser.isValidationAllowed();
}
11.07.2020 17
def userSession = Mock(UserSession)
@Subject
def validationProvider = new ValidationProvider(userSession)
@Unroll
def 'validate user session where validation allowed #validationAllowed and userlogged is #isloggedIn'() {
//validation tests
}
Test
11.07.2020 18
Approval Test
11.07.2020 19
Minimum refactoring
public String validateUsername(ValidatableUser validatableUser) {
String validationMessage;
//copied validation logic
...
...
return validationMessage;
}
11.07.2020 20
@Unroll
def 'validate username #username' () {
…
…
}
Test
11.07.2020 21
Approval Test
11.07.2020 22
Minimum refactoring
Zip code Password
Confirm
password
11.07.2020 23
More Refactoring
11.07.2020 24
Concept
11.07.2020 25
End Result
…
…
private final SystemWideUserValidator<RegistrationValidatableUser, DefaultValidationResult> systemWideUserValidator;
public DefaultValidationResult doLegacyValidation(RegistrationValidatableUser validatableUser) throws ValidationImpossibleException {
…..
…..
return systemWideUserValidator.validate(validatableUser);
}
…
…
11.07.2020 26
Refactoring Take Home
Always refactor
Test before
refactoring
Documentation
Don't focus
performance
11.07.2020 27
11.07.2020 28
Innovation Implemented.
mgm technology partners GmbH
Frankfurter Ring 105a
80807 München
Tel.: +49 (89) 35 86 80-0
Fax: +49 (89) 35 86 80-288
http://www.mgm-tp.com
PragMunich Berlin Hamburg Cologne NurembergGrenoble LeipzigDresdenBamberg Đà Nẵng ZugWashington

More Related Content

Similar to Make legacy code great

Final microsoft cloud summit - windows azure building block services
Final   microsoft cloud summit - windows azure building block servicesFinal   microsoft cloud summit - windows azure building block services
Final microsoft cloud summit - windows azure building block servicesstratospheres
 
Persistant Cookies and LDAP Injection
Persistant Cookies and LDAP InjectionPersistant Cookies and LDAP Injection
Persistant Cookies and LDAP InjectionMaulikLakhani
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for youSimon Willison
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps OfflinePedro Morais
 
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능Hyperledger Korea User Group
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013Michelangelo van Dam
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processguest3379bd
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsSimo Ahava
 
Top Ten Tips For Tenacious Defense In Asp.Net
Top Ten Tips For Tenacious Defense In Asp.NetTop Ten Tips For Tenacious Defense In Asp.Net
Top Ten Tips For Tenacious Defense In Asp.Netalsmola
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumberBachue Zhou
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And AnishOSSCube
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Vendic Magento, PWA & Marketing
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 

Similar to Make legacy code great (20)

Final microsoft cloud summit - windows azure building block services
Final   microsoft cloud summit - windows azure building block servicesFinal   microsoft cloud summit - windows azure building block services
Final microsoft cloud summit - windows azure building block services
 
Persistant Cookies and LDAP Injection
Persistant Cookies and LDAP InjectionPersistant Cookies and LDAP Injection
Persistant Cookies and LDAP Injection
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
 
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
[2019.1] 하이퍼레저 패브릭 v1.3, v1.4 새로운 기능
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the process
 
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analystsMeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
MeasureCamp IX (London) - 10 JavaScript Concepts for web analysts
 
Top Ten Tips For Tenacious Defense In Asp.Net
Top Ten Tips For Tenacious Defense In Asp.NetTop Ten Tips For Tenacious Defense In Asp.Net
Top Ten Tips For Tenacious Defense In Asp.Net
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
Intro to Parse
Intro to ParseIntro to Parse
Intro to Parse
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 

Recently uploaded

Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Recently uploaded (20)

Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Make legacy code great

  • 1. München/HQ Bamberg Berlin Đà Nẵng Dresden Grenoble Hamburg Cologne Leipzig Nuremberg Prague Washington Zug Make Legacy Code Great Again Ezekiel Olasehinde Đà Nẵng, 11/07/2020
  • 2. 11.07.2020 2 About me Software Engineer IT Freak Scrum Master Web Application Developer
  • 4. 11.07.2020 4 How is legacy code made? Technical Debt Forgotten technology Ignorance
  • 6. 11.07.2020 6 Refactoring is a control technique for improving the design on an existing code base. What is refactoring ?
  • 7. 11.07.2020 7 Why you should refactor?
  • 8. 11.07.2020 8 Unit test Prevents regressions Verification Documentation
  • 10. 11.07.2020 10 Fixing legacy codes – Where to start?
  • 13. 11.07.2020 13 One true legacy validation … … public String doLegacyValidation(ValidatableUser validatableUser) { //session based validation if (!UserSession.getInstance().isUserLoggedIn() && validatableUser.isValidationAllowed()) { return "Validation impossible with logged in user"; } String errorMessage = ""; //email validation if (StringUtils.isEmpty(validatableUser.getEmail())) { errorMessage += "email is required"; } else if (!validatableUser.getEmail().contains("@")) errorMessage += "this is not an email n"; else if (validatableUser.getEmail().contains("@")) { String[] emailSplit = validatableUser.getEmail().split("@"); if (emailSplit[1].split(".").length < 2) errorMessage += "Unrecognized email pattern"; } //zip code validation try { int zip = Integer.parseInt(validatableUser.getZipCode()); if (validatableUser.getZipCode().length() < 6) { errorMessage += "zip code needs to be atleast of length of 6"; } else if (validatableUser.getZipCode().length() > 7) { errorMessage += "zip code length must not be more than 7"; } int countOfFives = 0; for (int a = 0; a < validatableUser.getZipCode().length(); a++) { if (validatableUser.getZipCode().charAt(a) == '5') { countOfFives++; } } if (countOfFives < 2) { errorMessage += "zip code failed the requirement of atleast double 5"; } if (StringUtils.pathEquals(validatableUser.getUsername(), validatableUser.getPassword().getKey())) { errorMessage += "Invalid confirm password, kindly check our password policyn"; } } catch (NumberFormatException n) { errorMessage += "unrecognized zip code"; } //username validation if (Arrays.asList("admin", "systemadmin", "annoymous").contains(validatableUser.getUsername().toLowerCase())) { errorMessage += "Invalid username, kindly check our username policyn"; } else if (length(validatableUser.getUsername(), ' ') < 6) { errorMessage += "Invalid username, kindly check our username policyn"; } else if (length(validatableUser.getUsername(), ' ') > 10) { errorMessage += "Invalid username, kindly check our username policyn"; } //password validation if (Arrays.asList("admin", "sysadmin", "anonymous").contains(validatableUser.getPassword().getKey().toLowerCase())) { errorMessage += "Invalid password, kindly check our password policyn"; } else if (length(validatableUser.getPassword().getKey(), ' ') < 6) { errorMessage += "Invalid password, kindly check our password policyn"; } else if (length(validatableUser.getPassword().getKey(), ' ') > 10) { errorMessage += "Invalid password, kindly check our password policyn"; } if (Arrays.asList("admin", "sysadmin", "anonymous").contains(validatableUser.getPassword().getValue().toLowerCase())) { errorMessage += "Invalid confirm password, kindly check our password policyn"; } else if (length(validatableUser.getPassword().getValue(), ' ') < 6) { errorMessage += "Invalid confirm password kindly check our password policyn"; } else if (length(validatableUser.getPassword().getValue(), ' ') > 10) { errorMessage += "Invalid confirm password, kindly check our password policyn"; } return errorMessage; } … …
  • 14. 11.07.2020 14 Problem ... ... if (!UserSession.getInstance().isUserLoggedIn() && validatableUser.isValidationAllowed()) { return "Validation impossible with logged in user"; } … …
  • 15. 11.07.2020 15 Problem //username validation if (Arrays.asList("admin", "systemadmin", "annoymous").contains(validatableUser.getUsername().toLowerCase())) { errorMessage += "Invalid username, kindly check our username policyn"; } else if (length(validatableUser.getUsername(), ' ') < 6) { errorMessage += "Invalid username, kindly check our username policyn"; } else if (length(validatableUser.getUsername(), ' ') > 10) { errorMessage += "Invalid username, kindly check our username policyn"; } … …
  • 16. 11.07.2020 16 Eliminate singleton private final UserSession userSession; public boolean isValidationAllowed(ValidatableUser validatableUser) { return !userSession.isUserLoggedIn() && validatableUser.isValidationAllowed(); }
  • 17. 11.07.2020 17 def userSession = Mock(UserSession) @Subject def validationProvider = new ValidationProvider(userSession) @Unroll def 'validate user session where validation allowed #validationAllowed and userlogged is #isloggedIn'() { //validation tests } Test
  • 19. 11.07.2020 19 Minimum refactoring public String validateUsername(ValidatableUser validatableUser) { String validationMessage; //copied validation logic ... ... return validationMessage; }
  • 20. 11.07.2020 20 @Unroll def 'validate username #username' () { … … } Test
  • 22. 11.07.2020 22 Minimum refactoring Zip code Password Confirm password
  • 25. 11.07.2020 25 End Result … … private final SystemWideUserValidator<RegistrationValidatableUser, DefaultValidationResult> systemWideUserValidator; public DefaultValidationResult doLegacyValidation(RegistrationValidatableUser validatableUser) throws ValidationImpossibleException { ….. ….. return systemWideUserValidator.validate(validatableUser); } … …
  • 26. 11.07.2020 26 Refactoring Take Home Always refactor Test before refactoring Documentation Don't focus performance
  • 28. 11.07.2020 28 Innovation Implemented. mgm technology partners GmbH Frankfurter Ring 105a 80807 München Tel.: +49 (89) 35 86 80-0 Fax: +49 (89) 35 86 80-288 http://www.mgm-tp.com PragMunich Berlin Hamburg Cologne NurembergGrenoble LeipzigDresdenBamberg Đà Nẵng ZugWashington

Editor's Notes

  1. date title : software enginner
  2. Why should you trust what I say, 2+ years of working with the greatest legacy code 8+ month rewriing/rewriting and implementing configurable components for the project
  3. Unspupported technology Java 1 to 14 You code is not documented, it’s difficult to understand how the code is supposed to work Unsupported technology Not tested Inherited
  4. find a good question : how much legacy code do you think you've made - Explain how you're forced to create legacy code : my resolution
  5. Technical is usually created due to time pressure, we can call them ”The Little Hack” 1. Example : how I was forced to create a technical debt Technical debt is similar to Monetary debt in the sense that they accumulates until fulfilled Technical debt and legacy code as whole leads to refactoring
  6. Transition: how do we ensure were refactoring correctly ?
  7. Expected demo time: ~ 5 - 6 mins?
  8. Too much information – make sure the pointers are connected to things said in the speech – need more information How many take-aways can one personally remember? Choose the most important