Refactoring Workshop (at the Coding Café)
Details
We'll explore how to refactor Python code — but also JavaScript and Ruby, see below!
What is this about? Well, we all know bad code when we see it. It takes us longer to understand than it should, because there are single-letter names only, or because more if statements are nested than should be allowed by law.
Maintainability suffers from un-reusable code, and anti-patterns. And with each line the nightmare grows.
In this workshop we'll learn what to do about that, about getting from bad code to good code without changing what it intends to do: Refactoring. We'll look at code such as the following.
def find_until(things, t):
f = []
for idx in range(len(things)):
f += things[idx].get('items') or [] if things[idx]['created'] > t else []
return f
This is not horrible code, but it's far from ideal,
because it's the kind that makes you ask questions:
- What do f and t mean? How would you properly name them?
- What's with the or-if-else structure?
How could we rewrite this function so these questions don't pop up
or are trivial to answer? That's what we'll do: In groups of two, we'll analyze such code samples, and then improve them. Afterwards, we'll discuss the different solutions.
For whom is this?
• You are comfortable writing Python.
• You want to improve your Python or refactoring skills, ideally both.
You have a laptop and can bring it — this is a workshop.
If you already know Python and do refactoring at work: All the better!
Maybe you can teach someone something, but even more importantly,
you can work with people /outside your normal circle/. That's usually
best for growing.
Piece of a puzzle
This workshop (http://cebucodecamp.org/p/203/code-refactoring) is brought to you by Cebu Code Camp (http://cebucodecamp.org/), and it will also include code samples for Javascript (https://www.meetup.com/javascript-cebu/events/232800144/) and Ruby. The workshop will happen in parallel to the Coding Café at the TIDE (https://www.meetup.com/The-TIDE-Cebu/events/232659937/). The Café open at 2pm, the workshop will start at 3pm, so just show up anywhere in between. :)