Source Code Rejuvenation is not Refactoring

Similar documents
DAT159 Refactoring (Introduction)

Imagine you ve written a piece of code but then accidentally deleted and lost it.

Living and Working with Aging Software. Ralph Johnson. University of Illinois at Urbana-Champaign

A Catalog and Classification of Fortran Refactorings

Modern Refactoring. II Escola de Informática Teórica e Métodos Formais

Refactoring. Chen Tang March 3, 2004

The Pivot framework: Design and Implementation

COURSE 11 DESIGN PATTERNS

Extract Slice Refactoring. Rani Ettinger, Programming Tools Group, May 19th, 2003

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture

Prototype Environment for Refactoring Clean Programs

Kerievsky_book.fm Page 355 Thursday, July 8, :12 PM. Index

Restructuring. What is restructuring? Tudor Gîrba Reengineering life cycle. What? forward engineering. reverse engineering

C++14 and Concepts. Bjarne Stroustrup. Texas A&M University

Type Inference auto for Note: Note:

I m sure you have been annoyed at least once by having to type out types like this:

Extended abstract. The Pivot: A brief overview

COMP 354 TDD and Refactoring

McCa!"s Triangle of Quality

Beyond the Refactoring Browser: Advanced Tool Support for Software Refactoring

Evolving Software Quality Knowledge. Daniel Speicher

Model refactoring within a Sequencer TOMAŽ KOS 1, TOMAŽ KOSAR 2, JURE KNEZ 1, MARJAN MERNIK 2

Concepts for the C++0x Standard Library: Iterators

Objectives: On completion of this project the student should be able to:

Eclipse CDT refactoring overview and internals

Understading Refactorings

Refactoring in the Context of Programming Language Evolution

Runtime Concepts for the C++ Standard Template Library

Editing Code. SWE 795, Spring 2017 Software Engineering Environments

Reengineering II. Transforming the System

Refactoring via Database Representation

Classification and Summarization of Software Refactoring Researches: A Literature Review Approach

Martin P. Robillard and Gail C. Murphy. University of British Columbia. November, 1999

Detaching and Reconstructing the Documentary Structure of Source Code

Standard-Library Exception Safety

Abstract: Refactorings are used to improve the internal structure of software without changing its external behavior.

Copy Constructors & Destructors

Static rules of variable scoping in Erlang

SAFIRA: A Tool for Evaluating Behavior Preservation

Automatic Detection of Refactorings for Libraries and Frameworks

An Example of Code Refactoring with Legacy Code in a Flight Model Software

Software Reengineering P1: Intro & Organization. Martin Pinzger Delft University of Technology

Object-Oriented Programming for Scientific Computing

Refactoring, 2nd Ed. A love story. Michael Hunger

Refactoring Practice: How it is and How it Should be Supported

A Proposal to Add a Logical Const Wrapper to the Standard Library Technical Report

Concepts for the C++0x Standard Library: Iterators (Revision 2)

security model. The framework allowed for quickly creating applications that examine nancial data stored in a database. The applications that are gene

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

Chapter 17: Linked Lists

Dynamic Storage Exercise

arxiv: v1 [cs.pl] 17 Sep 2013

A Proposal to Add a Const-Propagating Wrapper to the Standard Library

Analysis of the Test Driven Development by Example

The SIGCSE 2001 Maze Demonstration Program

Refactoring with Eclipse

Object-Oriented Programming for Scientific Computing

Intermediate Programming, Spring 2017*

Model Refactoring in Web Applications

Iterator Concepts for the C++0x Standard Library

Model-View-Controller

Reduction of Program-generation Times by Transformation-sequence Optimization

Towards End-User Adaptable Model Versioning: The By-Example Operation Recorder

AntiPatterns. EEC 421/521: Software Engineering. AntiPatterns: Structure. AntiPatterns: Motivation

Bring Back the Obvious Definition of count()

Refactoring Myths FOCUS: REFACTORING

Adaptive Refactoring Using a Core-Based Clustering Approach

Template based set of collection classes STL collection types (container types)

Initializer Lists for Standard Containers

E xtr B e y CS R m oy 6704, e T a P n a Spring r n o d J g ia n 2002 r g a S m hu m ing

Challenges in Model Refactoring

Searching for Refactoring Opportunities to apply the Strategy Pattern

Automated Model Transformations Based on STRIPS Planning

by Pearson Education, Inc. All Rights Reserved. 2

Tool Support for Complex Refactoring to Design Patterns

Tool Support for Refactoring Duplicated OO Code

Automating Big Refactorings for Componentization and the Move to SOA

Employing Query Technologies for Crosscutting Concern Comprehension

Tackling Design Patterns Chapter 3: Template Method design pattern and Public Inheritance. 3.1 Introduction... 2

11. Generic Programming and Design Patterns. 8. Juli 2011

CPEG 852 Advanced Topics in Computing Systems The Dataflow Model of Computation

Templates and Vectors

Fascinating Observation Monitor-based Clamant Code Smell Detection Using Python

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Automated Support for Program Refactoring using Invariants

CSC 408F/CSC2105F Lecture Notes

Towards the integration of security patterns in UML Component-based Applications

Software Design and Analysis CSCI 2040

Software Evolution. Dr. James A. Bednar. With material from

Test Driven Development. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Tobias Pulls and Eivind Nordby

Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates

More STL algorithms. Design Decisions. Doc No: N2569= Reply to: Matt Austern Date:

Pattern-Oriented Reengineering of a Network System

void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) {

GA-driven Automatic Refactoring based on Design Patterns

The following topics will be covered in this course (not necessarily in this order).

C++ INTERFACE CLASSES STRENGTHENING ENCAPSULATION

Eclipse Support for Using Eli and Teaching Programming Languages

Shading Languages. Ari Silvennoinen Apri 12, 2004

What is an algorithm?

Transcription:

Source Code Rejuvenation is not Refactoring Peter Pirkelbauer Damian Dechev Bjarne Stroustrup Texas A&M University SOFSEM 2010 Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 1 / 18

Programming Language Evolution Evolving a language in and for the real world: C++ 1991-2006. [Str07] Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 2 / 18

Overview 1 What is Source Code Rejuvenation? 2 Tool support for Rejuvenation 3 What is Refactoring? 4 Conclusion Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 3 / 18

What is Source Code Rejuvenation? Definition Detection of outdated coding styles and idioms Automatic replacement of old code with modern language features or libraries. Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 4 / 18

Source Code Rejuvenation Goals Preserve or improve a program s behavior Raise the level of abstraction in source code Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 5 / 18

Container Initialization in C++0x C++0x Initializer List // initializes a vector with 3 elements: 1, 2, 3 vector<int> vec = {1, 2, 3; Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 6 / 18

Container Initialization in C++ Consecutive push_backs vector<int> vec; vec.push_back(1); vec.push_back(2); vec.push_back(3); Copying from an array static const int a[] = {1, 2, 3; vector<int> vec(a, a+sizeof(a)/sizeof(int)); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 7 / 18

Container Initialization in C++ Consecutive push_backs vector<int> vec; vec.push_back(1); vec.push_back(2); vec.push_back(3); Copying from an array static const int a[] = {1, 2, 3; vector<int> vec(a, a+sizeof(a)/sizeof(int)); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 7 / 18

Container Initialization in C++ Consecutive push_backs vector<int> vec; vec.push_back(1); vec.push_back(2); vec.push_back(3); Copying from an array static const int a[] = {1, 2, 3; vector<int> vec(a, a+sizeof(a)/sizeof(int)); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 7 / 18

Container Initialization in C++ Consecutive push_backs vector<int> vec; vec.push_back(1); vec.push_back(2); vec.push_back(3); Copying from an array static const int a[] = {1, 2, 3; vector<int> vec(a, a+sizeof(a)/sizeof(int)); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 7 / 18

Source Code Rejuvenation Goals Preserve or improve a program s behavior Raise the level of abstraction in source code Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 8 / 18

C++ Concepts - A Quick Introduction Unconstrained code template <class Iterator> Iterator random_elem(iterator first, Iterator last) { typename Iterator::difference len = distance(first, last); advance(first, rand()%len); return first; C++ concepts specify syntactic and semantic properties concept RandomElemIter <typename Iterator> { Iterator::Iterator(const Iterator&); // copy constructor typename Iterator::difference; // associated type Iterator::distance distance(iterator&, Iterator&); void advance(iterator&, Iterator::distance&);... template<randomelemiter Iterator> Iterator random_elem(iterator first, Iterator last); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 9 / 18

C++ Concepts - A Quick Introduction Unconstrained code template <class Iterator> Iterator random_elem(iterator first, Iterator last) { typename Iterator::difference len = distance(first, last); advance(first, rand()%len); return first; C++ concepts specify syntactic and semantic properties concept RandomElemIter <typename Iterator> { Iterator::Iterator(const Iterator&); // copy constructor typename Iterator::difference; // associated type Iterator::distance distance(iterator&, Iterator&); void advance(iterator&, Iterator::distance&);... template<randomelemiter Iterator> Iterator random_elem(iterator first, Iterator last); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 9 / 18

C++ Concepts - A Quick Introduction Unconstrained code template <class Iterator> Iterator random_elem(iterator first, Iterator last) { typename Iterator::difference len = distance(first, last); advance(first, rand()%len); return first; C++ concepts specify syntactic and semantic properties concept RandomElemIter <typename Iterator> { Iterator::Iterator(const Iterator&); // copy constructor typename Iterator::difference; // associated type Iterator::distance distance(iterator&, Iterator&); void advance(iterator&, Iterator::distance&);... template<randomelemiter Iterator> Iterator random_elem(iterator first, Iterator last); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 9 / 18

C++ Concepts - A Quick Introduction Unconstrained code template <class Iterator> Iterator random_elem(iterator first, Iterator last) { typename Iterator::difference len = distance(first, last); advance(first, rand()%len); return first; C++ concepts specify syntactic and semantic properties concept RandomElemIter <typename Iterator> { Iterator::Iterator(const Iterator&); // copy constructor typename Iterator::difference; // associated type Iterator::distance distance(iterator&, Iterator&); void advance(iterator&, Iterator::distance&);... template<randomelemiter Iterator> Iterator random_elem(iterator first, Iterator last); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 9 / 18

C++ Concepts - A Quick Introduction Unconstrained code template <class Iterator> Iterator random_elem(iterator first, Iterator last) { typename Iterator::difference len = distance(first, last); advance(first, rand()%len); return first; C++ concepts specify syntactic and semantic properties concept RandomElemIter <typename Iterator> { Iterator::Iterator(const Iterator&); // copy constructor typename Iterator::difference; // associated type Iterator::distance distance(iterator&, Iterator&); void advance(iterator&, Iterator::distance&);... template<randomelemiter Iterator> Iterator random_elem(iterator first, Iterator last); Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 9 / 18

Concept Recovery advance Input iterator template<class Iter, class Dist> void advance(iter& iterator, Dist dist, input_iterator_tag) { while (dist ) ++iterator; advance Random access iterator template<class Iter, class Dist> void advance(iter& iterator, Dist dist, random_access_iterator_tag) { iterator += dist; Propagating requirements into random_elem Which advance exhibits minimal requirements? Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 10 / 18

Concept Recovery - w/ workaround analysis advance Input iterator template<class Iter, class Dist> void advance(iter& iterator, Dist dist, input_iterator_tag) { while (dist ) ++iterator; advance Random access iterator template<class Iter, class Dist> void advance(iter& iterator, Dist dist, random_access_iterator_tag) { iterator += dist; Propagating requirements into random_elem Which advance exhibits minimal requirements? Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 11 / 18

Source Code Rejuvenation - Summary Key Points Raises level of abstractions (lowers software entropy) Modern code is more concise (easier to read and maintain) Code rejuvenation can improve program behavior Code rejuvenation is directed Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 12 / 18

Tool support for Rejuvenation to C++0x - Pivot The Pivot Industrial C++ Frontend Intermediate representation (IPR) frontend independent preserves high level details ready for most C++0x features external representation (XPR) human read- and writable 1:1 correspondence to IPR Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 13 / 18

What is refactoring? Re factoring Factor multiple reoccurring code into a single function Broader Definition An automatic and behavior preserving code transformation that improves source code that was subject to gradual structural deterioration over its life time. [OJ93] Broader Definition Improves the design of existing code [FBB + 99] Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 14 / 18

Refactoring Examples Repeated (user driven) maintenance tasks Class specification Class generalization [Opd92] Towards pattern Away from patterns [Ker04] Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 15 / 18

Refactoring Examples (cont d) Elimination of bad code Code smells Anti-pattern Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 16 / 18

Refactoring versus Rejuvenation Source Code Rejuvenation Refactoring Transformation Source-to-source Source-to-source Behavior preserving Behavior improving Behavior preserving Directed yes no Raises the level of abstraction Drivers Language / library evolution Feature extensions Design changes Indicators Workaround techniques / idioms Code smells Anti-patterns Applications One-time source code migration Recurring maintenance tasks Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 17 / 18

Thank You! Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 18 / 18

Martin Fowler, Kent Beck, John Brant, William Opdyke, and Don Roberts. Refactoring: improving the design of existing code. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1999. Joshua Kerievsky. Refactoring to Patterns. Pearson Higher Education, 2004. William F. Opdyke and Ralph E. Johnson. Creating abstract superclasses by refactoring. In CSC 93: Proceedings of the 1993 ACM conference on Computer science, pages 66 73, New York, NY, USA, 1993. ACM. William F. Opdyke. Refactoring object-oriented frameworks. PhD thesis, University of Illinois at Urbana-Champaign, Champaign, IL, USA, 1992. UMI Order No. GAX93-05645. Bjarne Stroustrup. Evolving a language in and for the real world: C++ 1991-2006. In HOPL III: Proceedings of the third ACM SIGPLAN conference on History of programming languages, pages 4 1, New York, NY, USA, 2007. ACM. Parasol Lab (Texas A&M) Source Code Rejuvenation is not Refactoring Jan 25 th, 2010 18 / 18