POODR Qoutables

I just finished reading Practical Object Oriented Design Ruby(POODR) by Sandi Metz. This book is a must read. It’s essentially a rule book for writing clean, isolated and flexible Object Oriented Code. If you ever found yourself looking at your code and wondering where you should create a new object, if the code is “clean” or whether one of your classes is doing too much. This book works tirelessly to disspell misplaced or unorganized OO code. This digestion is all about me quoting Sandi, at points where I feel her work must be remembered.

Chapter 1

“Object Oriented design requires that you shift from thinking of the World as a collection of predesigned procedures and start modeling the world as a series of messages that pass through objects”.

“Every Application is a collection of code, the codes arrangement is design”

“Design is not an assembly line where similarly trained workers construct identical widgets ; It’s a studio where like minded artists sculpt custom applications.”

“Just as a suclptor has chisels and files, an object oriented designer has tools - Principles and Patterns”

Reverse Engineering to Learn Forward

I believe that you can learn the basics of whatever you would like to implement, by looking out in to the open source world for muse codebases. The purpose of finding a muse codebase is not to rip or steal, it is to learn and inspect. It’s like asking a teacher to show you something but looking into the teachers brain as opposed to directly asking the teacher. Its harder to do but hard things teach more meaningful and memorable lessons.

In this particular post, I will be reverse engineering a code base on Github which is making use of the Stripe Connect API. Personally, I’ve always wanted to use omniauth to develop but I’ve always been scared of it for some reason. Here I will break a fear and learn a new skill and at the same time share a new skill.

I found a person on Github who had a personal project at: https://github.com/dylandrop/givespend-v3/commits/master

Project Overview

This project seems to allow a person to sell items for a charitable cause. It has the idea of a buyer and also a seller. It was not a completely finished product but there are lessons that it teaches about dealing with Omniauth and the Stripe Api in its seller implementation. So Lets break it down.

Multiple Model Form via FormObject Pattern

Sometimes in life you just have to make your life easer. And the first step anybody can take to make their life easier is to not use Accepts_nested_attributes_for when making multiple model forms. The Problem with accepts_nested_attributes_for is that connecting more than two models in a single form is a headache. In Rails the more graceful way to conveniently connect multiple models is to use the Form Object Pattern.

It’s infinitely easier to set up and gives you a higher level of control when it comes to creating very complex forms. The Process goes like this:

  1. Create a PORO in the Model folder of your rails app
  2. Inside the PORO Include ActiveModel::Model
  3. Inside the PORO create attr_accessors representing all the fields of your form
  4. Add your validations for each accessor attribute
  5. Inside the PORO, Create a submit method specifying where you want your data to be submitted to.
  6. Call “FormObjectName”.new and “FormObjectName”.submit when you want to process your form.

AR Association Explorations

Creating ActiveRecord associations are by far one of the most powerful techniques to master when doing rails. And playing with these associations is sort of like an art. Because there are a finite number of associations that you can make in Rails. But you can make connections with them in sooo many interesting ways. As you all know, these associations are made available through the ActiveRecord association methods DSL: has_many, has_one, belongs_to, etc.. These association methods are powerful and if utilized correctly can do wonders for putting rails models together to build interestingly connected business objects.

In this post I will be picking out some associations that I’ve come across out there in the wild(github). The idea is to go over, via repetition how a person would go about reading custom rails associations and therefore informing the creation of custom rails associations. All the while practicing my own rails decoding skills.

The first app that I came across and happened to like can be found here: https://github.com/waterflowseast/waterflowseast/blob/master/app

This application waterfloweast is a great specimen of model associations put to great use. There are 12 models in total and all are very carefully connected in a wide variety of interesting ways. Let us look over these interesting connnections.

How to Debug Date.parse

This post is geared towards people using ruby 2.1.5 specifically. If you find your self needing to parse a string into a date object. You know that you have to require the Date class at the head of your ruby file, like so:

require 'date'

This will give your current model access, to the Date class and its methods. The next step is always to pass the date string into the parse method, like so:

Remembering My First Day

This is a post I wrote to myself on October 13th 2014 on my First day at the Startup Institute. I feel it’s always good to look back at where you are coming from. If not for learning then at the very least, its good for the feelings of Nostalgia.

Debugging Status 500 Errors in Production

Deploying a rails project to Heroku can be a headache. In production on Heroku, you are running your application on their servers. Thus you become the client to your app. If you run across a problem with your user experience such as a bad request, you will recieve a splash page saying that an error has happened. The page will have nothing on it, but a http status code and a prompt for you to check heroku logs if you are the admin. Most times, you will probably be able to figure out the problem if you have a 300 or 400 status code. However, things become very difficult if you get a 500 error in production. The 500 status error means that something went wrong with the code in your application. However, the page that you will get back will have no real information to help you fix your error and your heroku logs will be almost as useless as your heroku error splash page.

Sorting Algorithms

Starting my journey off with topics that I find most interesting seems like a good way to begin. Let’s dive in to a short discussion on some basic algorithms. Algorithms generally insight alot of fear and so it is my hope to ease some of the pain for those not very hip to the matter. Coming from a science background my general way of getting to know things of complexity is by starting with the most empirical examples and then kind of gradually building up from there.

Linear Search

Life Is Better on a Journey

Im in a pickle currently. A few months ago I landed in a pretty cool startup for my first rails development role after leaving my development bootcamp SINY. The experience was amazing, everyday I felt like I was dreaming, I learned alot, spent time with really cool people and became the professional developer I had dreamed about for almost everyday for 2 years. That lasted for 6 months and then my company pivoted. While Im still good friends with everybody, I am now currently looking for a new job, one that pays more and has a bigger team for me to work with. The problem is, Im facing a lack of some quintessential Comp Sci knowledge and without that knowledge, employers have a tough time trusting in my abilities that I currently possess. But people in my opinion should try to spend less time worrying about their problems and more time fixing it. And So….