ICONFINDER www.iconfinder.com. ICONFINDER Founded 2007 2007-2012 2012 2014 -Django based web application -PostgreSQL -Elasticsearch -Amazon Elastic Compute.

Slides:



Advertisements
Similar presentations
Module 7. Simplifying Conditional Expressions Course: Refactoring.
Advertisements

A practical guide John E. Boal TestDrivenDeveloper.com.
© 2010 Shawn A. Bohner Software Construction and Evolution - CSSE 375 Even more Bad Smells in Code Shawn & Steve Q1 Shawn & Steve Hint 
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 2 Composing Methods Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring: Improving the Design of Existing Code © Martin Fowler, Martin Fowler.
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
George Blank University Lecturer. REFACTORING Improving the Design of Existing Code Supplement to Ian Sommerville, Software Engineering, Chapter 20 Prepared.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
Computer Science 240 Principles of Software Design.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Refactoring – III Measured Smells. Smells Covered 1. Comments 2. Long method 3. Large Class 462.
Program Refactoring Mitch Soden Union College. Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
Refactoring Improving the structure of existing code Refactoring1.
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
SE: CHAPTER 7 Writing The Program
SWE 316: Software Design and Architecture Objectives Lecture # 20 Improving the existing design: Refactoring SWE 316: Software Design and Architecture.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Refactoring1 Improving the structure of existing code.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring Advanced Software Engineering Dr Nuha El-Khalili.
Refactoring1 Improving the structure of existing code.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Software Construction and Evolution - CSSE 375 Dealing with Generalization Steve and Shawn Left – In the 1990 movie “The Freshman,” Matthew Broderick,
Refactoring. DCS – SWC 2 Refactoring ”A change made to the internal structure of software to make it easier to understand and cheaper to modify without.
Module 9. Dealing with Generalization Course: Refactoring.
Catalog of Refactoring (1) Composing Methods. Code Smells Long methods Dubious temporary variables Dubious methods.
Refactoring (1). Software Evolution Cope with change Feature bloat Design decay Code duplications “Pattern time is refactoring time” Make future changes.
A (Very) Simple Example Consolidate duplicate conditional fragments if (isSpecialDeal()) { total = price * 0.95; send (); } else { total = price * 0.98;
Principles and examples
Steve Chenoweth Office Phone: (812) Cell: (937)
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
Module Road Map Refactoring Why Refactoring? Examples
Reviewing Code A guide to smelling another developer’s source code.
Behavioral Design Patterns
A Very Common Series of Techniques
Refactoring SENG 301 © Refactoring: Improving the Design of Existing Code, Martin Fowler, Kent Beck Source:
Refactoring II 21-Sep-18.
Refactoring and Code Smells
Software Construction and Evolution - CSSE 375 Composing Methods
Overview of Eclipse Lectures
Informatics 122 Software Design II
Code Smells 1.
//code refactoring Rename Method Introduce Assertion
Improving the structure of existing code
Refactoring and Code Smells
Advanced Programming Behnam Hatami Fall 2017.
Refactoring II 5-Feb-19.
Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described.
Software Design Principles
Refactoring and Code Smells
Informatics 122 Software Design II
Refactoring.
Refactoring and Code Smells
Presentation transcript:

ICONFINDER

ICONFINDER Founded Django based web application -PostgreSQL -Elasticsearch -Amazon Elastic Compute cloud -LAMP stack -xcache for php bytecode caching -Mod_pagespeed -1 virtual machine 16GB RAM 16 core Huge Refactoring

Why change existing code?

Money -Business perspective -Save resources save money

User Experience -If you improve performance you are likely to improve user experience Fun Fact -Amazon, Google and Bing reported to losing 1% of revenue for every tenth of a second slower their site gets.Amazon

Technical Debt -Intentionally cut corners to complete software -Code that is sub par and hard to maintain -Causing difficulties for extending the code base -Get rid of technical debt - save time

A better solution -New solutions -Better ways of doing things -What does not changing the solution mean? -Investing in the future? If it ain’t broke don’t fix it!

Refactoring Refactoring is the process of modifying a software system internally without altering the the external behavior of the code. Goals -Improve internal structure -Ease of understanding

Refactoring - When When should you refactor? -When you add function -When you need to find a bug -As you do a code review -The rule of three (related to the DRY principle)

Interactive Activity 1 Quiz 1 Show example of a code with smell and get them thinking about smell/refactoring to lead into lecture

class Print def print_owing outstanding = 0.0 # print banner puts “************************” puts “**Customer Owes ***” puts “************************” #calculate do |order| outstanding += order.amount end #print details puts(“name: puts(“amount: #{outstanding}) puts “************************” puts “**Customer Owes ***” puts “************************” end What can we find wrong in this code?

Code Smells A code smell is a surface indication that usually corresponds to a deeper problem in the system

Code Smells -Duplicate code -Long Method -Long parameter list -Case statements -Large class -Shotgun surgery -Parallel inheritance hierarchies …….

Duplicate Code Duplicate code: two code fragments that look almost identical Code Smell

Duplicate Code -In two methods, same class -In two sibling subclasses -Duplication in middle of method -Different algorithm, same thing Code Smell

Long Method The longer a procedure is the more difficult it is to understand. Too long too hard to understand Code Smell

Refactorings -Extract method -Pull up method -Extract surrounding method -Replace parameters with method -Move method -Extract class -Tease apart inheritance -Extract hierarchy ….

Extract Method Use extract method if you have a code fragment that can be grouped together, by turning the fragment into a method whose name explains purpose of the method Extract Method - Refactoring

Extract Method -Most common refactoring -Improves usability of method -Easier to understand -Overriding is easier Extract Method - Refactoring

Class Print def print_owing outstanding = 0.0 # print banner puts “************************” puts “**Customer Owes ***” puts “************************” #calculate do |order| outstanding += order.amount end #print details puts(“name: puts(“amount: #{outstanding}) puts “************************” puts “**Customer Owes ***” puts “************************” end What bad smells can we identify within this method and how do we refactor them? Extract Method - Refactoring

Extract Method: Mechanics 1.Create new method, name after intention 2.Copy extracted code into target method Extract Method - Refactoring

class Print def print_owing outstanding = 0.0 print_banner #calculate do |order| outstanding += order.amount end #print details puts(“name: puts(“amount: #{outstanding}) print_banner end # print banner def print_banner puts “************************” puts “**Customer Owes ***” puts “************************” end It is easy for us to extract the print banner segment because no local variables are affected Extract Method - Refactoring

Extract Method: Mechanics 1.Create new method, name after intention 2.Copy extracted code into target method 3.Scan for references to variables local to source method Extract Method - Refactoring

class Print def print_owing outstanding = 0.0 print_banner #calculate do |order| outstanding += order.amount end #print details puts(“name: puts(“amount: #{outstanding}) print_banner end def print_banner # print banner puts “************************” puts “**Customer Owes ***” puts “************************” dnd end What happens when a local variables is referenced in the code you wish to extract. Extract Method - Refactoring

class Print def print_owing outstanding = 0.0 print_banner #calculate do |order| outstanding += order.amount end print_details (outstanding) print_banner end def print_details(amount) #print details puts(“name: puts(“amount: #{amount}) end def print_banner # print banner puts “************************” puts “**Customer Owes ***” puts “************************” end Local variable read only vs manipulated Extract Method - Refactoring

Extract Method: Mechanics 1.Create new method, name after intention 2.Copy extracted code into target method 3.Scan for references to variables local to source method 4.Look for temp variables 5.Is local variable modified by extracted method? Extract Method - Refactoring

class Print def print_owing outstanding = 0.0 print_banner #calculate do |order| outstanding += order.amount end print_details (outstanding) print_banner end def print_details(outstanding) #print details puts(“name: puts(“amount: #{outstanding}) end def print_banner # print banner puts “************************” puts “**Customer Owes ***” puts “************************” end temps & reassigning a local variable Extract Method - Refactoring

def print_owing printBanner outstanding = get_outstanding() print_details(outstanding) printBanner end def get_outstanding #calculate outstanding outstanding = do |order| outstanding += order.amount end outstanding end def print_details(outstanding) #print details puts(“name: #{_name}) puts(“amount: #{outstanding}) end def print_banner # print banner puts “************************” puts “**Customer Owes ***” puts “************************” end reassigning a local variables can be complicated. Extract Method - Refactoring

Extract Method: Mechanics 1.Create new method, name after intention 2.Copy extracted code into target method 3.Scan for references to variables local to source method 4.Look for temp variables 5.Is local variable modified by extracted method? 6.Replace extracted code in source with a call to target 7.compile and test Extract Method - Refactoring

class Print def print_owing outstanding = 0.0 # print banner puts “************************” puts “**Customer Owes ***” puts “************************” #calculate do |order| outstanding += order.amount end #print details puts(“name: puts(“amount: #{outstanding}) puts “************************” puts “**Customer Owes ***” puts “************************” end Original Code with code smells Extract Method - Refactoring

class Print def print_owing printBanner outstanding = get_outstanding() print_details(outstanding) printBanner end def get_outstanding #calculate outstanding outstanding = do |order| outstanding += order.amount end outstanding end def print_details(amount) #print details puts(“name: #{_name}”) puts(“amount: #{amount}”) end def print_banner # print banner puts “************************” puts “**Customer Owes ***” puts “************************” end Extract Method - Refactoring Refactored

Interactive Exercise 2 Quiz 2 Refactor the code below

class Print def tuition_owed(previousAmount) balance = previousAmount * 1.2 #print banner puts “*************************” puts “**University of Memphis**” puts *************************** #print details puts(“name: puts(“amount: #{balance}) #calculate do |course| balance += course.amount end #print banner puts “*************************” puts “**University of Memphis**” puts “*************************” end Extract Method - Refactoring

class Print def tuition_owed(previousAmount) balance = calculate_balance(previousAmount * 1.2) print_banner print_details(balance) print_banner end def do |course| balance += course.amount end balance end def print_details amount puts(“name: puts(“amount: #{amount}) end def print_banner puts “*************************” puts “**University of Memphis**” puts “*************************” end Extract Method - Refactoring Refactored

Pull Up Method - Refactoring Use pull up method if you have methods with identical results on subclasses.

Pull Up Method - Mechanics -Inspect the method to ensure they are identical -Chose a common signature for both methods -Create new method in superclass -Delete one subclass method and test -Continue to delete subclass method and test until all duplicate methods are deleted

Pull Up Method - Refactoring In this case let us assume the create_bill(date) method are identical in both method. Thus we refactor as shown above

Interactive Exercise 3 Quiz 3