semantic merge - no fear refactoring

28

Upload: psluaces

Post on 24-May-2015

506 views

Category:

Technology


0 download

DESCRIPTION

No fear refactoring in the DVCS age : Enter SemanticMerge . These are the slides of my talk at QCon 2013. http://www.youtube.com/watch?v=GJuHtNZaong&feature=share&list=UUT5MZm9TcduZFstmQp9vRXQ&index=3

TRANSCRIPT

Page 1: Semantic Merge - No fear refactoring
Page 2: Semantic Merge - No fear refactoring

No fear refactoring in the DVCS age

Enter SemanticMerge

pablo santos @psluaces@semanticmerge

meet us at booth #14

Page 3: Semantic Merge - No fear refactoring

Agenda

• How to diff and merge refactored code with SemanticMerge• Under the hood: the inner workings of the tool• Next step: multi-file SemanticMerge• Towards Semantic version control

Page 4: Semantic Merge - No fear refactoring

Tech from the 80’s

• Git and the DVCS pack came in 2005• They went mainstream (GitHub)• They all can do awesome merges• But they rely on old-fashioned diff and merge tools

Page 5: Semantic Merge - No fear refactoring

You can do amazing things with DVCS

Page 6: Semantic Merge - No fear refactoring

You can do amazing things with DVCS• It has greatly improved merge tracking• It does a great job finding the contributors for the

3-way merge

• But at the end of the day… it invokes an external 3-way merge tool to solve the merge

Page 7: Semantic Merge - No fear refactoring

Simple example

Page 8: Semantic Merge - No fear refactoring

Simple example

Page 9: Semantic Merge - No fear refactoring

Simple example

Page 10: Semantic Merge - No fear refactoring

What will a conventional 3-way merge tool do?• No conflict!• And two methods!!

Page 11: Semantic Merge - No fear refactoring

What will a conventional 3-way merge tool do?• No conflict!• And two methods!!

• It simply finds two blocks of text being added and the original block being deleted… Doesn’t care about the code structure

Page 12: Semantic Merge - No fear refactoring

What SemanticMerge does• It *knows* about the methods so…

Page 13: Semantic Merge - No fear refactoring

What is semanticmerge?

• It is a 3-way merge tool (handles src, dst and base).

• It is refactor-aware and programming language-aware.

• Handles merging at the structure level and not textblock level.

• It means: • It first parses the code – creates intermediate

trees.• Then calculates diff pairs: base-src, base-dst.• Then looks for conflicts between pairs.

• Enabling eXtreme Refactoring was always the goal :-)

I guess you all know by now ;-)

Page 14: Semantic Merge - No fear refactoring

How can semanticmerge affect development?We were always motivated by “the cost of change” and how refactoring can greatly help keeping code quality high and reducing maintenance costs.

SemanticMerge is all about helping teams to clean up the code, keep it readable and simple, without restrictions: do it in parallel, fine!

Page 15: Semantic Merge - No fear refactoring

How can semanticmerge affect development?

1) It helps simplifying the merges TODAY already.

2) But more importantly it enables new scenarios that you’re not doing today: clean up the code, move methods, split classes… and just be able to merge it back.

Page 16: Semantic Merge - No fear refactoring

A SemanticMerge scenario

Page 17: Semantic Merge - No fear refactoring

A divergent move case

Page 18: Semantic Merge - No fear refactoring

Detect conflicts that regular tools can’t• What if the same method is modified concurrently

at different lines?• Semantic detects the case and can force the

conflict resolution to be manual – a regular text based merge tool can’t do that because it doesn’t have the context

Page 19: Semantic Merge - No fear refactoring

Under the hood

Page 20: Semantic Merge - No fear refactoring

Creating a tree-like view of the code

namespace Sample [4-26]

int Add(int a, int b) [8-12]

int Mul(int a, int b) [14-18]

int Subst(int a, int b) [20-24]

using System [1]

using System.Text [2]

class Math [6-25]

Page 21: Semantic Merge - No fear refactoring

Processbase

base tree

source destination

Parser

source tree destination tree

Diff er Diff er

Merger

src-base diff s dst-base diff s

result

automatic confl icts

manual confl icts

source ops to apply

Page 22: Semantic Merge - No fear refactoring

Some complex cases – cyclic move

namespace Testnamespace Test

namespace Test

class Socket

class Socket

class DNS

class DNS

class Socket

base

source destination

class Utils

class Utils

class DNSclass Utils

Page 23: Semantic Merge - No fear refactoring

Evil twinnamespace Test

class Socket

base

source

method Connect

namespace Test

class Socket

method Connect

namespace Test

class Socket

method Connect

destination

method Send method Send

Two methods with exactly the same signature can’t be added on the same

location -> conflict

Page 24: Semantic Merge - No fear refactoring

Integrations

• IntelliJ (and Android Studio)• Git, Mercurial, TFS, Plastic SCM, Perforce, SVN…

everything!

Page 25: Semantic Merge - No fear refactoring

Next steps

• JavaScript is the top request• C/C++ - Objective-C• XML• Ruby, Scala…•Mac OS X support• External Parsers (Delphi

already there)

Check UserVoice - http://plasticscm.uservoice.com

Page 26: Semantic Merge - No fear refactoring

Next steps

• Semantic code review – each time you review code you would like to go straight to the point…

• Semantic blame/annotate – calculate the blame considering methods

• Semantic Method History• Semantic repository stats

Page 27: Semantic Merge - No fear refactoring

Multi-file SemanticMerge

Page 28: Semantic Merge - No fear refactoring