1 / 13

Refactoring with R#

Refactoring with R#. Giorgetti Alessandro Ricci Gian Maria. Giorgetti Alessandro. Owner of SID s.r.l. Blog: http://www.nablasoft.com/guardian Email: guardian@nablasoft.com. Ricci Gian Maria. MVP Team System Blog: http://www.nablasoft.com/ alkampfer [ Eng ]

sirius
Download Presentation

Refactoring with R#

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Refactoring with R# Giorgetti Alessandro Ricci Gian Maria

  2. Giorgetti Alessandro Owner of SID s.r.l. Blog: http://www.nablasoft.com/guardian Email: guardian@nablasoft.com

  3. Ricci Gian Maria MVP Team System Blog: http://www.nablasoft.com/alkampfer [Eng] http://blogs.ugidotnet.org/rgm [Ita] Email: alkampfer@nablasoft.com

  4. Refactoring Purposes • Clean-up the code • Improve readability • Improve the ‘code maintenance’ • Implement a ‘Separation of Concerns’ in your application • Allow better testability • Improve performances appling some ‘best practices’

  5. Prerequisites to Refactoring • Understand what the code does • Understand what the code is supposed to do (sometimes they do not match) • Knowledge of what you are going to do (do not blindly follow some practices or use tools without knowing how the work and the impact they have). You are altering (someone else’s) code, so always be carefull and assure yourself to preserve the original functionalities.

  6. The Refactoring Pipeline Refactoring can be a very complex operation, especially depending on the legacy code you are working on. Sometimes is wise to divide the task in multiple iterations, and work on a single task a time. This way you can test what you are doing and it’s easier to revert back in case of errors. Let’s see some common steps:

  7. The Refactoring Pipeline • Analyze the legacy code. • Write down some objectives you want to accomplish with refactoring (like: beautify code and improve readability, separate business logic code from presentation, improve performace, testability, etc…). • Assign a priority to all these task and start an iteration for any of them.

  8. The Refactoring Pipeline The Iteration Chain should be something like: • Think what you are going to do (for example if you are isolating business code from presentation code, define a set of classes and interface and so on…). • Write down some documentation about the changes you are going to do. • Implement your solution. • Add some tests for the new component eventually written. • Verify that the whole system works.

  9. Demo – Refactoring of an Image Gallery Our final goal will be: • Structurate the application • Less code bloating • More classes with small methods in them

  10. Demo - Refactoring an Image Gallery Defining the iterations: • Step 0 - Analyze the code. • Step 1 - Isolate the tasks, separate concerns, make the methods smaller, improve readability and code maintenace. • Step 2- Define application layers and reduce couplings, especially the ‘persistence coupling’; we end up with a layered application usually: presentation, services, repository layers. • Step 3 – Apply an MVP/MVC/MVVM pattern and move code to testable classes.

  11. Demo - refactortoreachtestability • We start from a web formwhereall the logicis inside the code behind • Wewillmove, stepbystep, to a custom and simpleimplementationof MVC • Weadd test for the logicof the page • The goal ishaving a web page so simplethatnot a simpleifshouldremain in code behind.

  12. Tips & Tricks • Use a CDN service when possible to deliver library services (AJAX, jQuery and so on) (http://www.asp.net/ajax/cdn/) • Consider using Javascript or jQuery for simple tasks to avoid unneeded PostBacks • Test…test…test…

  13. Questions ? We hope NOT, cause we are TIRED and we want to EAT and DRINK!

More Related