refactoring tools for perl code

17
REFACTORING TOOLS IN PERL

Upload: dagfinnr

Post on 11-May-2015

230 views

Category:

Software


5 download

DESCRIPTION

Slides from presentation at Mojoconf. Discusses my Extract Method refactoring implementation for Perl.

TRANSCRIPT

Page 1: Refactoring tools for Perl code

REFACTORING TOOLS IN PERL

Page 2: Refactoring tools for Perl code

WHAT IS REFACTORINGRefactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior

Page 3: Refactoring tools for Perl code

REFACTORING CATALOG

• ▶Add Parameter

• ▶Change Bidirectional Association to Unidirectional

• ▶Change Reference to Value

• ▶Change Unidirectional Association to Bidirectional

• ▶Change Value to Reference

• ▶Collapse Hierarchy

• ▶Consolidate Conditional Expression

• ▶Consolidate Duplicate Conditional Fragments

• ▶Decompose Conditional

• ▶Duplicate Observed Data

• ▶Dynamic Method Definition

• ▶Eagerly Initialized Attribute

• ▶Encapsulate Collection

Page 4: Refactoring tools for Perl code

THE GOALS

• Make code more readable and comprehensible

• Eliminate duplication

Page 5: Refactoring tools for Perl code

WHY?

• Lots of time is spent reading code

• Bugs hide in obscure code

• Duplication makes code rot

• LEARNING!

Page 6: Refactoring tools for Perl code

START OUT BRAINDEAD, GET BETTER

Page 7: Refactoring tools for Perl code

TOOLS?????

Page 8: Refactoring tools for Perl code

JAVA REFACTORINGIn Eclipse

Page 9: Refactoring tools for Perl code

JAVASCRIPT REFACTORINGIn WebStorm

Page 10: Refactoring tools for Perl code

PERL REFACTORING

Page 11: Refactoring tools for Perl code

PPIx::EditorTools

• Supports Vim and Emacs

• RenameVariable (safe renaming)

• RenamePackageFromPath

• IntroduceTemporaryVariable

Page 12: Refactoring tools for Perl code

My extensions

• Supports Vim only

• ExtractMethod

• ConvertVarToAttribute

Page 13: Refactoring tools for Perl code

Why refactor long methods?

• Readability—make the essential logic clear

• Isolated testing

• Isolated editing

• Avoid comments getting out of sync

Page 14: Refactoring tools for Perl code

ARCHITECTUREAnalyzer

VariableSorter

CodeGenerator

CodeEditor

Page 15: Refactoring tools for Perl code

ANALYZER CLASSES

Page 16: Refactoring tools for Perl code

CURRENT STATUS

• Mostly safe with “normal” code.

• No fancy installation available

• Use the README athttps://github.com/dagfinnr/perl-extract-method

Page 17: Refactoring tools for Perl code

[email protected]

[email protected]

• Github, Twitter (theoretically): dagfinnr