Refactoring a wall of JavaScript from dev.to project

We refactor a wall of JavaScript code with Raddevon, in thisvideo. We take a function that's 5 screens high, and extract methods to uncover the underlying structure. We're using a method objectrefactoring towards the end of the video. Also, we're experimenting with the naming process, inspired byNaming as a process.This video was originally streamed on my Twitch channel. If you'd like to be notified, when I stream, you can subscribe on Twitch or on Twitter This video was originally

Continue Reading

acts_as_list refactoring part 3

I refactor acts_as_list Ruby gem again: watch as I choose better names, strip unnecessary variables, work with some ActiveRecord internals and make code intent clearer. In this refactoring adventure I'm going to focus on just one 11-line method, and surprisingly, there's a lot of things that can be improved in just one method. You don't need to read part 2 and part 1 to understand this article. acts_as_list is a Rails gem. It allows you to treat Rails model

Continue Reading

acts_as_list refactoring part 2

In this post I'm continuing refactoring of acts_as_list gem I started in part 1. As you might remember, I've split .acts_as_list method into several modules, each module dedicated to an option passed to the method. E.g. ColumnMethodDefiner module defines methods related to the column option (the option defines column name for storing record's list position). This post is dedicated to refactoring of the ColumnMethodDefiner module. Improving ColumnMethodDefiner module So, I've extracted code related to column option of .acts_as_list to

Continue Reading

acts_as_list refactoring part 1

Today I'm going to refactor acts_as_list Rails library. It allows to treat Rails model records as part of an ordered list and offers methods like #move_to_bottom and #move_higher. Step 1: .acts_as_list introduction .acts_as_list is available as a class method in ActiveRecord::Base when acts_as_list gem is loaded. Here's an excerpt from .acts_as_list definition: Using ClassMethods module is customary in Rails, but it's not a requirement to be familiar with it to read this article. All you need to know is

Continue Reading

CreateSend refactoring part 2

Today I'm continuing to refactor a library called CreateSend. The first part is here. In part 1 I've finished all class methods of Base classs and now I'm going to refactor instance methods. Step 1: initialize method initialize (see above ↑) chooses not to use named arguments, and treats method arguments as an array of many arguments. And yet, it only processes one argument from the whole args array. It's misleading to accept arguments and throw them away. It

Continue Reading

CreateSend refactoring part 1

Today I'm going to refactor a part of Ruby library called CreateSend. I'll work on lib/createsend/createsend.rb, which contains CreateSend::CreateSend class and some other stuff. Introduction CreateSend is a base class for accessing CampaignMonitor API. It provies .user_agent to set HTTP user agent and .exchange_token to get OAuth access token. In summary, it's a Ruby wrapper for accessing API. Classes like Campaign inherit from CreateSend to add specific methods to work with campaigns, etc. First look The first things declared

Continue Reading

PaginatedResource refactoring

Today I'm going to refactor a class from Digital Ocean Droplet Kit, a library to control droplets (that's what Digital Ocean calls virtual machines). The class is called PaginatedResource and you can find the original source here. The idea behind the class is that it fetches elements from an external source on demand, and you just call #each and don't worry about fetching. How PaginatedResource works Take a look: Elements are fetched from external source one page at a

Continue Reading

Ninefold CLI refactoring

Today I'm going to review and refactor some code from Ninefold CLI. I picked a method I could make better. Ninefold is a hosting company and pick_app is apparently responsible for selecting an app for CLI to work with. What's good about this code: Long method names like app_from_dot_ninefold_file. Easy to understand what the method does.

Continue Reading
Web Analytics