Throwing away bad code and writing something new from scratch is both risky and expensive. You need to avoid this temptation and instead learn to master small improvements over time.
Refactoring is the art of improving code without changing user behavior. Adding dedicated refactoring time to your workflow and sprints can pay for itself many times over in both added source code flexibility and application stability.
In this workshop we will review refactoring concepts from a high level and then explore example cases found in many iOS projects. As a group we'll refactor and discuss the benefits of our changes. We'll then work on our own (or in pairs) to execute what we've learned and then demonstrate the results for the class.
This workshop is targeted at those iOS developers who are getting over the hump of learning iOS and now want to know how to write higher quality iOS code. This workshop is capped at 12 people to make sure there is plenty of time for questions and individual attention.
Related Video: Let's Play: Refactor the Mega Controller!
About the Instructor
My name is Mike Zornek and I am a senior developer and amateur user interface critic with a rich background in Apple technologies; Mac development since 2001 and iPhone development since 2009, active CocoaHeads leader for the Philadelphia chapter.
My teaching experiences include being an adjunct professor for Drexel University as well as a instructor for Big Nerd Ranch where I ran week long iOS classes for many well known corporate clients.
Students should come prepared with a Mac laptop, setup for iOS development with Xcode. We'll be using the stable Xcode 8.3.2 release (with Swift 3) during our demos and labs. If you do not own a laptop, let us know and we'll see what else can be arranged.
There may be some time dedicated to previewing the new refactoring tools of Xcode 9 but seeing as it will still be in beta for this workshop date it is not something we'll be using for our actual work.
Before the workshop, students will be provided a short questionnaire in order to gauge their personal goals and experiences. As best as I can, I will make sure to include examples and references in the workshop to match people's specific needs and questions.
Students will also be given access to a code base for a simple iOS Receipts app that will be the focus of our group exercise. Be prepared to spend some pre-class time reviewing this.
Opening Lecture (30m)
- What is refactoring?
- Why do we refactor?
- How do we define “good code”?
- Importance of testing as we refactor.
- Ideas for how to handle refactor time in busy client projects.
Group Refactoring Demo (80m)
Through the use of a custom built project with lots of "bad code", we will, as a group, explore the project and look for improvement opportunities. Specifically we’ll look for opportunities related to:
- Massive View Controllers
- Auto Layout
- Storyboard Management
- More (TBD)
We’ll execute solutions as a group, sometimes with live coding and sometimes with prebuilt solutions to account for time.
Individual Refactoring Lab (80m)
After break, we’ll have a generous lab time for students to take what they've learned about refactoring and apply it to either their own projects or the sample project we have supplied. Pairing is welcome during lab but not required.
Result Demo (30m)
To end the class we’ll ask some of the students to come to the front and demonstrate how they were able to refactor their sample projects.
Closing Thoughts (10m)
To end the workshop I’ll provide some focused reading and other refactor resources.