Searched for ""

Frustrated Learning Rails? Here is What You Should Do.

You were new to Rails, Web Development, or even programming. But you decided to give Rails a try. You thought it might be challenging but doable, like climbing a hill. Unfortunately, as you spent more and more time with Rails, things got more and more confusing. Each time when you were stuck and searched for a solution, you encountered some new words: Bundler, MVC, ERB, TDD, ActiveRecord Associations… There were conventions after conventions. You felt all you did was googling and copy-pasting and had trouble gluing all the components together. You started to lose confidence and wonder if you would ever learn Rails or… Continue reading

Design Pattern: Simple Factory and Cheesecake Factory

Design patterns in life and Ruby – gain an intuitive understanding of OO design patterns by linking them with real-life examples.   Factory Patterns are about encapsulating object creation. But before diving into details of these patterns, let’s talk about cheesecakes. Because cheesecakes are about … happiness! Let’s focus our gaze at six of my personal favorites: Original Cheesecake, Ore0 Cheesecake, Coffee Cheesecake, Tiramisu Cheesecake, S’mores Cheesecake, and Hazelnut Cheesecake. Here is how we make a cheesecake: def make_cheesecake(type) cheesecake = nil case type when ‘oreo’ cheesecake = OreoCheesecake.new when ‘coffee’ cheesecake = CoffeeCheesecake.new when ‘tiramisu’ cheesecake = TiramisuCheesecake.new when… Continue reading

Design Pattern: Template Method and Chipotle

Design patterns in life and Ruby – gain an intuitive understanding of OO design patterns by linking them with real-life examples.   Template Method is the most commonly used design pattern in programming and real life. Before we dive into details of the pattern, let’s learn an important life lesson: Chipotle 101: How to Order in Chipotle. There are four steps involved: Choose a “vessel”: Burrito vs. Bowl vs. Tacos vs. Salad Add meat: Chicken vs Steak vs. Barbacoa vs. Carnitas vs. Vegetarian Add toppings: Tomato vs. Corn vs. Green Chili vs. Red Chili Add extras & drinks: Chips vs…. Continue reading

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

Read Sidekiq Source Code with Me Conference Talks Design Patterns in Life and Ruby Series From Hello World to Six Job Offers From Facebook, Airbnb, Salesforce… Weekly Learnings My weekly learnings on the journey of becoming a tech lead. Week #17: Seeking Approvals at Work Exhausts Me Week #16: Three Lessons from A Frustrating Meeting Week #15: Project Planning: A Spike with First Principles Thinking Week #14: Fear No Awkwardness — Chatting is Good Week #13: The Power of One-on-One Meetings and Personal Connections Week #12: How to communicate effectively for bigger impacts Week #11: Communication: Getting on the Same… Continue reading