<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ben Jacobs on Medium]]></title>
        <description><![CDATA[Stories by Ben Jacobs on Medium]]></description>
        <link>https://medium.com/@benjaminpjacobs?source=rss-d46b8107e3cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AUH9wtAjWApY9G4A.</url>
            <title>Stories by Ben Jacobs on Medium</title>
            <link>https://medium.com/@benjaminpjacobs?source=rss-d46b8107e3cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:31:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@benjaminpjacobs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Four Pillars of Object Oriented Programming]]></title>
            <link>https://medium.com/@benjaminpjacobs/the-four-principle-of-object-oriented-programming-f78600f62608?source=rss-d46b8107e3cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/f78600f62608</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ben Jacobs]]></dc:creator>
            <pubDate>Thu, 31 Aug 2017 12:37:35 GMT</pubDate>
            <atom:updated>2019-02-01T17:13:13.385Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post we are going to take a high level look at the four pillars of object oriented programming. If you just said to yourself ‘Pillars? There are pillars?”, then you are in the right place. Through code and real world examples we will illustrate what these principles mean conceptually and practically.</p><p>In order to understand the pillars of OOP let us first define what OOP is:</p><blockquote>Object Oriented Programming is a language model that is organized around <strong>objects</strong> rather than <strong>actions</strong> and <strong>data</strong> rather than <strong>logic</strong>.</blockquote><blockquote>-a quick google search</blockquote><p>To be clear, that does not mean we do not <em>use</em> actions and logic in our code(or at least we should), but that rather than coding out a set of linear instructions in which we pass function to function or input to output we instead build objects. We model things that have attributes. They hold specific types and quantities of data and have methods they can perform. This allows our objects to interact with each other in order to read, write, interpret, calculate, manipulate or otherwise interact with that data.</p><p>So how and why do we do all of this? That is where the four pillars come into play. Here they are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*x8eq0XjqL2RoMsXi8CNo9g.png" /></figure><p><strong>A.P.I.E.</strong> Which is easier to remember. Because A Pie!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmaGQ2eUI1yq3yll_jn9kw.jpeg" /></figure><p>If you are like me then you saw that list and went, “Well… I definitely know what one of those means ¯\_(ツ)_/¯”. And to that I say, “Alas…you know so much more!”</p><p>So let us dive in and take a look at why these are fundamental to OOP and how you are already incorporating them into your code.</p><p>We are going to start with encapsulation(yes, out of order because they make more sense this way). Think of a car.</p><p>Most likely you thought of something along the lines of this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_-Gtr9D_NwZL00B7BQSTQ.jpeg" /></figure><p>Probably not this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*Wpv0chP4bKt3ljLv9FcrLQ.jpeg" /></figure><p>We keep all the inner workings of the car together encapsulated under the hood. The important stuff is stored there to keep it safe from the average user(non mechanics) which ensures the integrity of the system as it was designed. If you’ve ever incurred hefty mechanic fees after messing with something inside your engine then you understand the value and need for encapsulation. We don’t want this to happen to our code either.</p><p>Take this code block for example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbcf91adbc5438600e036bf0d9be84dd/href">https://medium.com/media/fbcf91adbc5438600e036bf0d9be84dd/href</a></iframe><p>We have defined a simple Person class. We encapsulate the data(first name, last name, age) and the functions needed for that data(getter methods for names and a format method for date) inside the class. We have packaged all relevant information together and only the methods within that package can directly manipulate that information. This concept will lead us to further restrict access within our classes to not only maintain the integrity and security of our software but also to facilitate abstraction.</p><p>Abstraction and encapsulation are tightly related. Stepping back into the car analogy, when we interact with a car we only need to know that the gas is on the right, the break is on the left, put it in drive and the steering wheel tells the car where to go. This is abstraction. We are only showed the simplest possible interface and the non-essential information to that interface has been hidden.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*xPOnxiK0DGerMsoeb-gWiw.jpeg" /></figure><p>This is ubiquitous in the code we write from a user clicking a button, and remaining blissfully unaware of event listeners waiting to invoke callback functions, all the way down to the gems and libraries we use ourselves. These are themselves abstractions of functionality we need to use but do not need to build from scratch. It reduces complexity and increases efficiency by making things more intuitive, modular and overall less complicated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f657083f3c91c55794302888a249ec6/href">https://medium.com/media/4f657083f3c91c55794302888a249ec6/href</a></iframe><p>If we look at the above code snippet, based on our person class, we can see that some of the data and functionality has been abstracted. No longer do we have to call “first_name” and “last_name” on our person instance but rather can simply ask the object who it is or how old it is. It returns nicely formatted strings that interpolate the data we have stored or data we have calculated. The user does not need to see this, they only need a simple interface and a result. Additionally, we make our attr readers and age method private to further embody the encapsulation principle and protect access to data the user does not require.</p><p>Next up we come to inheritance. This is often the most easily understood because we are all examples of inheritance. If we go back to our Person class and add a new class, Child, that inherits from Person we can illustrate this point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25e803cd7fb190635d985fc64d74848e/href">https://medium.com/media/25e803cd7fb190635d985fc64d74848e/href</a></iframe><p>When we create a new class that utilizes inheritance we give our child class access to all the architecture of the parent class. As you can see in the example Jane can tell you who she is and how old she is, but she can also tell you what grade she is in. We are able to extend the functionality of a child class without duplicating all the code from the parent. It makes our code reusable and keeps us from repeating ourselves.</p><p>Lastly we have polymorphism. Surely intimidating at first, but if we take it back to high school English and break it down we simply get many(poly) forms(morph). Back to the auto lot.</p><p>Say we have this vintage civic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*_Gloodh14OFo8K1Vt7R2oA.jpeg" /></figure><p>And this Tesla Model X:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*vEq913mmUVBUz0BTpjyZHA.png" /></figure><p>When we sit in the driver’s seat and push on the gas both cars go. But under the hood one is burning gas and the other runs on electricity. To the user both cars will move forward, but inside the engine different things are happening. This is the crux of polymorphism. Functions or methods that are named the same thing can do things differently. This makes our code easier to interact with. If we look back to our Person and Child classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3bf1329f376594b47433b3a86ac5ffe/href">https://medium.com/media/a3bf1329f376594b47433b3a86ac5ffe/href</a></iframe><p>Children are not adults. Perhaps we can reflect that in our code. When you ask a child who they are, they may be a little more informal. They might overshare. If we override the ‘who_am_i?” method in the child class to only offer a first name but additionally offer an age, we still have not changed the interface with the code from the user perspective. We can call that method on an instance of the Person class or the Child class and both will respond. They will do so through different implementations and the output will be slightly different but to a user both work. It is polymorphic.</p><p>A last quick note about polymorphism is that, specifically in inheritance patterns such as this, one of the fundamentally useful aspects of this principle is that affecting or overriding a method in the child class does not change that same method in the parent class. This can be incredibly useful in creating more specialized behaviors down the inheritance chain.</p><p>These pillars keep our work organized, modular and maintainable. They stop us from repeating ourselves, keep our data safe and most importantly make it simpler for our colleagues and our users to interact with. They hold up the object oriented pantheon in all their doric glory so you don’t forget…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmaGQ2eUI1yq3yll_jn9kw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f78600f62608" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beautiful Markup]]></title>
            <link>https://medium.com/@benjaminpjacobs/beautiful-markup-ff8d4875ea20?source=rss-d46b8107e3cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff8d4875ea20</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Ben Jacobs]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 14:46:04 GMT</pubDate>
            <atom:updated>2017-08-18T18:37:47.530Z</atom:updated>
            <content:encoded><![CDATA[<h3>An introduction to HTML Abstracted Markup Language</h3><p>As a backend developer challenges abound in the early days of learning. There are so many new skills to pickup, documentation to read, reps to do and never enough hours in the day or wealth of focus to feel as though a dent is ever made in the back log. One of the biggest challenges for me has been balancing the desire to spread my focus with the understanding that a deep dive into a single framework will probably serve my future aspirations in a more meaningful way. It is through that train of thought that I have limited the learning of things outside the scope of necessary scope of Rails until I feel I have reached a certain level of proficiency. That changed after I discovered <a href="http://haml.info/">HAML</a>.</p><p>One of the beautiful things about Rails is that it handles your views. Within it’s magical inner workings are a variety of tools that simplify many useful tasks. However, within the view, everything needs to be coded using HTML in concert with ERB(embedded Ruby). I have always felt that HTML was cumbersome to read and irritating to write (an opinion possibly shared or potentially scorned by the reader), which makes coding view after view extremely tiresome.</p><p>Enter HAML.</p><p>HTML Abstraction Markup Language or HAML is an alternative to HTML and ERB. It allows the developer to create highly readable markup that expresses the hierarchy of the DOM in a more literal way than HTML. It borrows syntax from CSS, it innately makes certain errors difficult or impossible to make and it’s even easy to learn(it only took me about two days to feel comfortable). However, the main selling point to me was no closing tags!</p><p>Let’s consider the following HTML block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfCK2ba4DbhY678w0r5K2Q.png" /></figure><p>The above is an example of a basic index page. It contains a series of standard tags, classes, an id, and a typical ERB block which renders all the items contained in example to their own divs. It is a lot of markup to accomplish a simple task. Let’s examine the same example in HAML</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpv2shNZcC3KHVEB8yyx5Q.png" /></figure><p>It is immediately clear that the HAML example is cleaner, more concise and well represents the hierarchy of the page. HTML tags are represented with a leading ‘%’. CSS classes are represented with a leading ‘.’ and no quotations. CSS ID’s, which have a leading ‘#’, can also be added after tags or chained along after classes.</p><p>In the case of the common div tag, the %div can be omitted completely and is implied when using a class, such as on line 10 in the iterative block.</p><p>Nesting within tags is represented as indentation. For example, everything that belongs inside the body tags in indented 2 spaces after it. Same for the %h3 and %p tags nested within the ‘.item’ div. The indentation puts both within the div.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PhIl6ssagGmzYdXIiMQCoA.png" /></figure><p>If the example looked like the above, the h3 would be nested within the ‘.item’ div but the p tag and it’s contents would not.</p><p>Again, my favorite part, there is no need for any closing tags. This allows for quicker composition with less overall code. HAML even goes so far as to do away with the need to end blocks of embedded Ruby adding readability and flow to all code blocks</p><p>HAML is not without it’s quirks. It’s opinionated indentation rules can stop you from making certain errors but can also lead errors which would cause no problems in HTML. However this has the unintended side effect of making HAML more uniform between developers. Whether this is a bug or a feature depends upon your perspective.</p><p>Additionally, I have found incorporating JavaScript into HAML to be quite the challenge though certainly not impossible. I would say, the project’s scripting needs may dictate whether the use of this option is preferred or more trouble than it’s worth.</p><p>Fortunately it is easy to dip a toe into the HAML pool without rewriting every ERB. Though they cannot co-exist in the same file they certainly can exist in the same project. This makes it easy to try it out without forcing your entire team to change styles all at once. However, if you do decide that you’d like to convert an entire project, definitely take a look at this <a href="https://github.com/dhl/erb2haml">gem</a> for a quick script to make that process as painless as possible.</p><p>In the end I’m not convinced that HAML will always be the appropriate choice, but it is certainly a tool I enjoy using. It allows for view markup that is concise and readable and plays very nicely with Ruby code. It has sped up my flow and it sure is pretty to look at.</p><p><strong>Resources:</strong></p><p><a href="http://haml.info/docs/yardoc/">HAML Docs</a></p><p><a href="https://www.sitepoint.com/an-introduction-to-haml/">HAML Intro</a></p><p><a href="https://rubygems.org/gems/haml/versions/4.0.7">HAML Gem</a></p><p><a href="https://github.com/dhl/erb2haml">HAML to ERB Gem</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff8d4875ea20" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>