Skip to content

Refactoring Workshop (at the Coding Café)

Refactoring Workshop (at the Coding Café)

Details

We'll explore how to refactor JavaScript code — but also Python 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 unreusable code, and anti-patterns. And with each line the nightmare grows. Aaaaargh. :p

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

Have a look the following function:

function getFnName (fn) {

var f = typeof fn === 'function'

var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^(]+)/))

return (!f && 'not a function') || (s && s[1] || 'anonymous')

}

It's part of Uppy, an open-source JS file loader. This is definitely not horrible code but it's the kind that makes you ask questions:

• What do f and s mean? How would you properly name them?

• What's with the array in the 2nd line?

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 JavaScript.

• You want to improve your JS or refactoring skills, ideally both.

• You have a laptop and can bring it — this is a workshop.

If you already know JS 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 Python (https://www.meetup.com/PizzaPy-PH/events/232944935/) 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. :)

Photo of Javascript Cebu group
Javascript Cebu
See more events
IT Park · Cebu