Searched for ""

When to Refactor

Keep hearing all these good things about refactoring but don’t know where to start? Here are seven cases where refactoring can help.   Case 1: When you need to make a change but it’s difficult to do so. for each desired change, make the change easy (warning: this may be hard), then make the easy change — Kent Beck (@KentBeck) September 25, 2012 Instead of trying to make a difficult change, first, refactor the code so you can make the change easily. Then make the easy change.   Case 2: When you need to understand a piece of code. When… Continue reading

Code Smell Cheat Sheet

Want to refactor some code but don’t know where to start? Just implemented a functionality and want to clean up the code? Need to review a gigantic pull request and find it hard to understand? Start with spotting and removing code smells.     I designed this cheat sheet to help you identify code smells. The first column describes symptoms of a code smell. The second column lists the name of a code smell. This cheat sheet is my notes from the wonderful Refactoring book written by Martin Fowler. I strongly recommend you to get a copy if you don’t have… Continue reading

Combining has_many :through with polymorphic associations in ActiveRecord

You read the Rails guide and thought you have understood the has_many :through association and polymorphic associations. Your app models needed both. Unfortunately, the guide didn’t explain how to combine these two together.  Wondering why on earth the guide would leave out the most important yet complicated part, you had no choice but try to put them together yourself hoping you would get it right. Your has_many :through associations seemed right. Your polymorphic associations also seemed identical to the examples in the guide. But ActiveRecord kept throwing errors: Could not find the association :foo in model Bar, Cannot have a has_many… Continue reading

Featured Thoughts On Life: Stealing and remixing ideas in public Design Patterns in Life and Ruby Series From Hello World to Six Job Offers From Facebook, Airbnb, Salesforce… My Journey Of Becoming A Tech Lead. Became a tech lead on Sept 2019 and paused the series. Week #20: A wrong way to build for the long-term: committing to premature designs Week #19: What Matters to Me At Work? Week #18: An Attempt to Stop Thinking About Work Outside of Work Week #17: Seeking Approvals at Work Exhausts Me Week #16: Three Lessons from A Frustrating Meeting Week #15: Project Planning:… Continue reading

One Year at Gusto — the 15 things I learned

Every morning, I wake up knowing I’m one of the luckiest people in the world. Having the privilege to be an engineer at Gusto is definitely one of the things that back up my belief. I’m extremely grateful for the support, trust, and freedom provided by the team. Learning opportunities and resources are abundant — sometimes I feel like a kid swimming in a huge ball pool, and all I want to do is scream and play! With that being said, there is no better time than first year anniversary to reflect on and summarize what I learned in the… Continue reading

Proc <> Code Block Conversion and Ampersand(&) in Ruby

This is the last part of a three-part series where we take a close look at Code Block, Proc, Lambda, and Closure in Ruby. In Part 1, we covered: Definitions of Code Block, Proc, Lambda, and Closure Constructions Calling a Code Block/Proc/Lambda Passing and Returning Procs In Part 2, we covered: Scopes, Universes, and Lunch Boxes Differences between Procs and Lambdas   In this post, the last part of the series, we will discuss:   Proc <> Code Block Conversion and Ampersand(&) A Code Block VS An Argument In the Context of A Method Behind the Scenes of [‘hello’, ‘world’].map(&:upcase)   Let’s dive… Continue reading

Scopes, Universes, & Lunch Boxes; Procs vs Lambdas in Ruby

This is part 2 of a three-part series. Part 1 covers the following four fundamentals: Definitions of Code Block, Proc, Lambda, and Closure Constructions Calling a Code Block/Proc/Lambda Passing and Returning Procs Part 2, this post, covers Scopes, Universes, and Lunch Boxes [FUN STUFF] Differences between a Proc and a Lambda Part 3 covers: Proc <> Code Block Conversion and Ampersand(&)   The most important takeaways from part 1 are the definitions: a code block is a block of code a proc is an object that contains a code block a lambda is a special type of proc A closure is a… Continue reading

Code Blocks, Procs, Lambdas, and Closures in Ruby

Code blocks and other members of the closure family are something near to many Rubyists’ hearts. They are extremely powerful, flexible, and, when used well, elegant. They are the cornerstones of Ruby’s functional style of programming. In this series, we will take a look at procs, code blocks, lambdas, and closures in Ruby and explore the differences between them and how to use them. I was afraid of all these names for a long time. But after taking a really close look at each one of them and their relationships to each other, I realized they were not that scary at… Continue reading