Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MCE^3 - Hannes Verlinde - Let The Symbols Do The Work

143 views

Published on

Syntactic symbol manipulation may be the universal way of deriving new knowledge in science and engineering, but the technique is still rarely used in the act of writing software. We will explore this alternate way of reasoning about code, while demonstrating the power of formal refactoring and its potential for automation.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

MCE^3 - Hannes Verlinde - Let The Symbols Do The Work

  1. 1. Let the symbols do the work
  2. 2. Computing's core challenge is how not to make a mess of it
  3. 3. Move fast and break things
  4. 4. Think like a computer
  5. 5. func inlineCount(fetchedCount: Int, totalCount: Int) -> Int { if (fetchedCount == totalCount) { return fetchedCount } let inlineCount = fetchedCount - 1 let overflowCount = totalCount - inlineCount if overflowCount < minimumOverflowCount { return totalCount - minimumOverflowCount } else { return inlineCount } }
  6. 6. func inlineCount(fetchedCount: Int, totalCount: Int) -> Int { if (fetchedCount == totalCount) { return fetchedCount } let inlineCount = fetchedCount - 1 if totalCount - inlineCount < minimumOverflowCount { return totalCount - minimumOverflowCount } else { return inlineCount } }
  7. 7. func inlineCount(fetchedCount: Int, totalCount: Int) -> Int { if (fetchedCount == totalCount) { return fetchedCount } let inlineCount = fetchedCount - 1 if totalCount - minimumOverflowCount < inlineCount { return totalCount - minimumOverflowCount } else { return inlineCount } }
  8. 8. func inlineCount(fetchedCount: Int, totalCount: Int) -> Int { if (fetchedCount == totalCount) { return fetchedCount } let inlineCount = fetchedCount - 1 return min(inlineCount, totalCount - minimumOverflowCount) }
  9. 9. func inlineCount(fetchedCount: Int, totalCount: Int) -> Int { if (fetchedCount == totalCount) { return fetchedCount } else { return min(fetchedCount - 1, totalCount - minimumOverflowCount) } }
  10. 10. func affectedRows(tappedIndexPath: NSIndexPath?) -> Set<NSIndexPath> { if let selectedIndexPath = selectedIndexPath { if let tappedIndexPath = tappedIndexPath { if tappedIndexPath == selectedIndexPath { return [selectedIndexPath] } else { return [selectedIndexPath, tappedIndexPath] } } else { return [selectedIndexPath] } } else { if let tappedIndexPath = tappedIndexPath { return [tappedIndexPath] } else { return [] } } }
  11. 11. func affectedRows(tappedIndexPath: NSIndexPath?) -> Set<NSIndexPath> { var rows = Set<NSIndexPath>() if let selectedIndexPath = selectedIndexPath { if let tappedIndexPath = tappedIndexPath { if tappedIndexPath == selectedIndexPath { rows.insert(selectedIndexPath) } else { rows.insert(selectedIndexPath) rows.insert(tappedIndexPath) } } else { rows.insert(selectedIndexPath) } } else { if let tappedIndexPath = tappedIndexPath { rows.insert(tappedIndexPath) } } return rows }
  12. 12. func affectedRows(tappedIndexPath: NSIndexPath?) -> Set<NSIndexPath> { var rows = Set<NSIndexPath>() if let selectedIndexPath = selectedIndexPath { if let tappedIndexPath = tappedIndexPath { if tappedIndexPath == selectedIndexPath { rows.insert(selectedIndexPath) rows.insert(tappedIndexPath) } else { rows.insert(selectedIndexPath) rows.insert(tappedIndexPath) } } else { rows.insert(selectedIndexPath) } } else { if let tappedIndexPath = tappedIndexPath { rows.insert(tappedIndexPath) } } return rows }
  13. 13. func affectedRows(tappedIndexPath: NSIndexPath?) -> Set<NSIndexPath> { var rows = Set<NSIndexPath>() if let selectedIndexPath = selectedIndexPath { if let tappedIndexPath = tappedIndexPath { rows.insert(selectedIndexPath) rows.insert(tappedIndexPath) } else { rows.insert(selectedIndexPath) } } else { if let tappedIndexPath = tappedIndexPath { rows.insert(tappedIndexPath) } } return rows }
  14. 14. func affectedRows(tappedIndexPath: NSIndexPath?) -> Set<NSIndexPath> { var rows = Set<NSIndexPath>() if let selectedIndexPath = selectedIndexPath { rows.insert(selectedIndexPath) if let tappedIndexPath = tappedIndexPath { rows.insert(tappedIndexPath) } } else { if let tappedIndexPath = tappedIndexPath { rows.insert(tappedIndexPath) } } return rows }
  15. 15. func affectedRows(tappedIndexPath: NSIndexPath?) -> Set<NSIndexPath> { var rows = Set<NSIndexPath>() if let selectedIndexPath = selectedIndexPath { rows.insert(selectedIndexPath) } if let tappedIndexPath = tappedIndexPath { rows.insert(tappedIndexPath) } return rows }
  16. 16. if condition { doSomething() doSomethingElse() } else { doSomething() } ➡ doSomething() if condition { doSomethingElse() }
  17. 17. 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 - Encapsulate Downcast - Encapsulate Field - Extract Class - Extract Interface - Extract Method - Extract Module - Extract Subclass - Extract Superclass - Extract Surrounding Method - Extract Variable - Form Template Method - Hide Delegate - Hide Method - Inline Temp - Inline Class - Inline Method - Inline Module - Introduce Assertion - Introduce Class Annotation - Introduce Expression Builder - Introduce Foreign Method - Introduce Gateway - Introduce Local Extension - Introduce Named Parameter - Introduce Null Object - Introduce Parameter Object - Isolate Dynamic Receptor - Lazily Initialized Attribute - Move Eval from Runtime to Parse Time - Move Field - Move Method - Parameterize Method - Preserve Whole Object - Pull Up Constructor Body - Pull Up Field - Pull Up Method - Push Down Field - Push Down Method - Recompose Conditional - Remove Assignments to Parameters - Remove Control Flag - Remove Middle Man - Remove Named Parameter - Remove Parameter - Remove Setting Method - Remove Unused Default Parameter - Rename Method - Replace Abstract Superclass with Module - Replace Array with Object - Replace Conditional with Polymorphism - Replace Constructor with Factory Method - Replace Data Value with Object - Replace Delegation With Hierarchy - Replace Delegation with Inheritance - Replace Dynamic Receptor with Dynamic Method Definition - Replace Error Code with Exception - Replace Exception with Test - Replace Hash with Object - Replace Inheritance with Delegation - Replace Loop with Collection Closure Method - Replace Magic Number with Symbolic Constant - Replace Method with Method Object - Replace Nested Conditional with Guard Clause - Replace Parameter with Explicit Methods - Replace Parameter with Method - Replace Record with Data Class - Replace Subclass with Fields - Replace Temp with Chain - Replace Temp with Query - Replace Type Code with Class - Replace Type Code with Module Extension - Replace Type Code With Polymorphism - Replace Type Code with State/Strategy - Replace Type Code with Subclasses - Self Encapsulate Field - Separate Query from Modifier - Split Temporary Variable - Substitute Algorithm
  18. 18. Sure why not?
  19. 19. A leap of faith
  20. 20. The fear of introducing the wrong abstraction
  21. 21. The code is the truth
  22. 22. Let the computer do the work?
  23. 23. The Refactoring Browser
  24. 24. virtual bool VisitDeclStmt(DeclStmt *st) { if (st->isSingleDecl()) { if (VarDecl *varDecl = dyn_cast<VarDecl>(st->getSingleDecl())) { if (varDecl->getName() == variableName) { value = rewriter.getRewrittenText(varDecl->getInit()->getSourceRange()); rewriter.RemoveText(st->getSourceRange()); } } } return true; } virtual bool VisitExpr(Expr *expr) { if (DeclRefExpr *refExpr = dyn_cast<DeclRefExpr>(expr)) { if (refExpr->getNameInfo().getName().getAsString() == variableName) { rewriter.ReplaceText(refExpr->getSourceRange(), value); } } return true; }
  25. 25. What's next?
  26. 26. What else?
  27. 27. Questions

×