<?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 Chris Metzger on Medium]]></title>
        <description><![CDATA[Stories by Chris Metzger on Medium]]></description>
        <link>https://medium.com/@chrismetzgr?source=rss-69b144917d88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nViq-o2kqTEXFG5Y.</url>
            <title>Stories by Chris Metzger on Medium</title>
            <link>https://medium.com/@chrismetzgr?source=rss-69b144917d88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:35:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chrismetzgr/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[On English-Based Programming Languages]]></title>
            <link>https://medium.com/@chrismetzgr/the-most-prevalent-programming-language-is-english-fa528c9070be?source=rss-69b144917d88------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa528c9070be</guid>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[foreign-language]]></category>
            <category><![CDATA[language]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[english-language]]></category>
            <dc:creator><![CDATA[Chris Metzger]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 14:39:22 GMT</pubDate>
            <atom:updated>2018-10-04T19:33:06.639Z</atom:updated>
            <content:encoded><![CDATA[<p>In preparation for Flatiron School’s software engineering bootcamp, others repeatedly told me something meant to get me in the right mindset for absorbing all the new information I was about to encounter: “learning to program is like learning a new language.”</p><p>To some extent, it’s true! Learning a new programming language <em>is</em> learning new grammar and new syntax. But something I take for granted is that English is the <em>lingua franca</em> of programming, and that I’m a native English speaker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*WJiJ5vhEEfPWbJC96H7MBw.png" /></figure><p>While looking at English terms I use everyday as a programmer, like ‘extends,’ ‘initialize,’ and the entire DOM nomenclature, I sometimes have this moment where a word I use frequently starts to look and feel so unfamiliar. I pronounce it slowly, thinking about how strange it looks and how it stands for something I know without really having to think about it. In these moments, when language feels so abstract, I imagine what it’s like to code for people who aren’t fluent in English. I began to realize that it’s easier for me to understand certain shortcuts, like ‘params’ being short for ‘parameters’ or ‘def’ for ‘define,’ because I know English. I began thinking about all of the documentation, forums, and other resources I have access to that might not be available in other languages.</p><p>Several professions use a common language, and there are obvious benefits to adopting terms from one source. But there really isn’t a reason that English is a better language for programming than any other, it’s just that more people who had their hands in creating the technology we use today just happened to be English speakers — specifically American English (CSS doesn’t support the British spelling of ‘colour’, and ‘initialize’ must have a ‘z). English has become the unshakeable standard; Ruby, a prominent coding language, and Vue.js, a JavaScript framework, were created by non-native English speakers and yet are English-based.</p><p>Information technology took off in the United States more than in other countries like Germany and Russia who were developing similar technologies at the time — <a href="https://en.wikipedia.org/wiki/Plankalk%C3%BCl">Plankalkül</a> and Algol respectively — mostly because of World War II (let’s also not forget that much of our modern technology was originally developed for war). With the way information technology has taken over the world, it is essential to know a programming language in order to have a seat at the table where the future is designed. This implies knowing English to some extent.</p><p>A <a href="https://www.cqse.eu/publications/2015-is-this-code-written-in-english-a-study-of-the-natural-language-of-comments-and-identifiers-in-practice.pdf">German study</a> demonstrated that companies in other countries sometimes write comments and identifiers (methods, functions, variables, etc.) in the country’s native language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*C06kREj8WKm1vT2AP4_tuQ.png" /></figure><p>This depends on the size of the company and their prospective growth. Right now, it’s usually in the interest of the company to write all of its documentation in English in case the company grows internationally.</p><p>People have definitely made coding languages that aren’t English-based––Wikipedia has a <a href="https://en.wikipedia.org/wiki/Non-English-based_programming_languages">list</a> of them. The existence of these languages demonstrates that arbitrariness of having English as the <em>lingua franca</em> of software engineering, and points to the powerful innovations that exist in languages other than English.</p><p>Not surprisingly, the majority of the world’s programmers aren’t native English speakers. According to <a href="https://evansdata.com/reports/viewRelease.php?reportID=9">EvansData</a> the US has the most software engineers than any other country, but India will surpass that number by 2023. China has the highest growth rate of programmers, at about an 8% increase per year.</p><p>Americans commonly joke about how we only know one language while citizens of similar countries know multiple languages. In this post, I wanted to reflect on the topic of the prevalence of English-based programming languages and the privilege of being a native English speaker to highlight that:</p><ol><li>There’s nothing inherently special about English that makes it fit for programming, but the global power of the US paved the way for this to be so.</li><li>People who don’t speak English have more obstacles to face and fewer resources at hand when learning programming languages, and we should keep this in mind as we try to make technology more accessible.</li><li>As other countries grow their programming communities and have greater influence on information technology, it would be in our interest to learn their languages.</li></ol><p>What do you think about English being the standard for programming languages? How can we make coding more accessible to people who speak different languages? I’d love to hear your thoughts in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa528c9070be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Polymorphic Associations, and how they work in two directions!]]></title>
            <link>https://medium.com/@chrismetzgr/polymorphic-associations-and-how-to-get-them-to-work-in-two-directions-de2481264f85?source=rss-69b144917d88------2</link>
            <guid isPermaLink="false">https://medium.com/p/de2481264f85</guid>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[polymorphic-association]]></category>
            <dc:creator><![CDATA[Chris Metzger]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 04:49:28 GMT</pubDate>
            <atom:updated>2018-07-19T16:10:39.415Z</atom:updated>
            <content:encoded><![CDATA[<p>I came across polymorphic associations while researching how to best go about creating model associations for a side project I’m currently working on. However, the way I wanted to use them wasn’t like the ways it was most often explained online. I had to figure out how polymorphic associations work in general, and then adjust the process within the laws of these associations to get my idea to work. Even thinking about it now, the topic still confuses me! Brushing up on my basic knowledge about this tool got me scratching my head, but in this blog post I’ll do my best to share my process, and a bit of my confusion with you all. Ultimately I got the associations to work as I wanted them to, so I just thought I’d share and hope this helps!</p><p>The most common example I found regarding when to use polymorphic associations is if I wanted my app to use tags and comments on several different models. I wouldn’t want to create a join-table for every model I’m putting a comment on (i.e. PhotoComment, VideoComment, PostComment, etc.); rather, I should just be able to make a single Comment model to host every instance of a comment association — no matter what class that comment is being pinned to.</p><p>Enter polymorphic associations. Polymorphic associations are a useful feature brought to us through Rails and ActiveRecord. They allow programmers to make a single model that can be used as a join-table hosting IDs from a variety of other models, instead of creating multiple unique join-table models.</p><p>Using the example above, let’s say I have a media hosting app with photos and videos that I want people to be able to add comments to. I’ll need a join table between an instance of User and an instance of a Photo or Video in order to create a comment. When I first arrived at this stage in my thinking, I said to myself: “If this is a join-table as I’ve come to know them, I’ll only have one column to determine the ID. So how will the app know if the ID belongs to a photo or video? Should I have two columns — one for photo_id and the other for film_id — and just leave one blank if I don’t need it?”</p><p>This is where I discovered the power of polymorphic associations. When creating the model for a polymorphic association, there needs to be a third column called ‘type’ that tells ActiveRecord on which table to collect the foreign ID. My model also needs a special word that I can use as an alias, allowing comments to be pinned on to either an instance of a photo or video. I’ve found the word ‘commentable’ to be most often used in this scenario, which makes sense: in the context of my app, I want photos and videos to be comment-able.</p><p>So when I create the Comment model, it’ll look like this:</p><pre>rails g model Comment commentable_type:string commentable_id:integer user_id: integer</pre><p>And when I make the associations, it’ll look like this…</p><p>The Comment model:</p><pre>class Comment &lt; ApplicationRecord<br>  belongs_to :commentable, polymorphic: true<br>  belongs_to: user<br>end</pre><p>**Notice that each comment belongs to a ‘commentable’, even though there is no Commentable class. I established earlier that ‘commentable’ is an alias Rails and ActiveRecord will use to determine the Photo or Video this comment goes to, depending on information we’ll pass in later.**</p><p>The User model:</p><pre>class User &lt; ApplicationRecord<br>  has_many :comments<br>end</pre><p>The Video model:</p><pre>class Video &lt; ApplicationRecord<br>  has_many :comments, as: :commentable<br>end</pre><p>**The word ‘as’ tells the application that ‘commentable’ is another word that can be used in lieu of “video”, or as we’ll in the next case, “photo”, to determine ownership. The video has many comments because it is ‘commentable’.</p><p>The Photo model:</p><pre>class Photo &lt; ApplicationRecord<br>  has_many :comments, as: :commentable<br>end</pre><p>So now I can call the method .comments on instances of users, photos, and videos and get an array of comments associated back with them. Cool, right??? A real life scenario would obviously be a little more complex, because the photos and videos would likely belong to users as well, but this gets the point across.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>After learning all this, I knew polymorphic associations were the answer to the problem I was trying to solve, but it still wasn’t clear to me about exactly how to go about it. My approach was a little different: rather than having a single user create one instance of something, like a comment, and assign that comment to either a photo or a video, what if I want one instance of something to be made by either a user or a group?</p><p>In the app I’m designing, users can operate individually as well as on behalf of a larger group. These are separate classes — a single member can join a collective group and access the powers of that group from their user account.</p><p>To simplify my example, I’ll just say there are only videos on our website. A user can publish a video as an individual, or, if the user is part of a group like a film studio, they can publish a video on behalf of the film studio’s collective account that they as an individual are apart of. Although the user as an individual is releasing the video, and would have access to ownership of that video by way of their membership within a film studio, it ultimately would belong to the film studio the person is in, not the user themself.</p><p>A contemporary example of where I imagine this could be already utilized is when Facebook makes a user an administrator of a Page. The user can make comments on behalf of all the admins of that page, having their personal name and profile hidden from the users interacting with that page, and the comment will still ultimately belong to the Page itself.</p><p>Hmmmmmmmm…..</p><p>It seems like I’m trying to make the polymorphic work in the reverse way. Instead of a user making a comment onto either a photo or a video, I want either an individual or a group to make a video, or in other words for the video to belong to either an individual or a group.</p><p>This was tricky to wrap my head around, but thinking in reverse here actually works. The word I changed that really helped me mentally imagine how I wanted this to function was the polymorphic alias. For example, what if “commentable” became “commenter”? Or, when speaking about films, using “releaser” instead of “releasable.” The alias refers to the one making the thing, not what the thing is being added to.</p><p>So instead of having a Comment model, I’ll create something more film appropriate:</p><pre>rails g model Release releaser_type:string _id:integer video_id: integer</pre><p>*The only thing bad about this example is the word “release!” Why do movies have to be “released?” They’re not like captive animals are something!* Anyways…</p><p>The Release model:</p><pre>class Release &lt; ApplicationRecord<br>  belongs_to :releaser, polymorphic: true<br>  has_one :video<br>end</pre><p>*Again, ‘polymorphic’ tells the application that this is an alias!*</p><p>The Video model:</p><pre>class Video &lt; ApplicationRecord<br>  belongs_to :release<br>end</pre><p>The User model:</p><pre>class User &lt; ApplicationRecord<br>  has_many :videos, as: :releaser<br>end</pre><p>The FilmStudio model:</p><pre>class FilmStudio &lt; ApplicationRecord<br>  has_many :videos, as: :releaser<br>  # a film studio would also have many users, of course...<br>  end</pre><p>So if I were to create a user, a filmstudio, and then movies put out by either of the two, I would do something like:</p><pre>spike = User.create(&quot;Spike Lee&quot;)<br>bfc  = FilmStudio.create(&quot;Brooklyn Filmmakers Collective&quot;)</pre><pre>dtrt = spike.release.create(&quot;Do The Right Thing&quot;)<br>summershorts = bfc.release.create(&quot;Trailers Of Our Favorite Summer Short Films&quot;)</pre><pre>dtrt.releaser will return the user instance Spike Lee<br>summershorts.releaser will return the filmstudio instance Brooklyn Filmmakers Collective</pre><p>By creating new instances of videos in this way, we’re automatically passing in the ‘releaser_type’ information to the Video initializer. This is how the Video instance knows which table to look for the Releaser on, even though they both have the ID of 1 right now.</p><p>And that’s the basics of polymorphic association! I hope that wasn’t too confusing! I’m sure there’s much more to learn, but I hope this was a good start for thinking about how to use them!</p><p>→ Just something to note, along the way I found others in similar situations that determined that inheritance was a better solution for them. After asking around I determined that inheritance wasn’t the right process for this particular problem, but just keep that in mind if you feel like polymorphic associations isn’t the right fit for you and you hadn’t considered inheritance yet! Maybe more on that later?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de2481264f85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[For Instance (and for partials)]]></title>
            <link>https://medium.com/@chrismetzgr/for-instance-and-for-partials-50a576106013?source=rss-69b144917d88------2</link>
            <guid isPermaLink="false">https://medium.com/p/50a576106013</guid>
            <category><![CDATA[sinatra]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <dc:creator><![CDATA[Chris Metzger]]></dc:creator>
            <pubDate>Wed, 27 Jun 2018 05:24:56 GMT</pubDate>
            <atom:updated>2018-06-27T05:24:56.953Z</atom:updated>
            <content:encoded><![CDATA[<p>We started learning Sinatra this week. Amidst all the magic that the gem has built into it, one thing that really amazed me was the ability to use instance variables to pass information from parameters delivered to the request via our submission fields, which can then be used inside our embedded Ruby (or ERB) files.</p><p>What exactly is going on here?</p><pre>get &#39;/books&#39; do    <br>  @books = Book.all    <br>  erb :&#39;index.html&#39;  <br>end</pre><p>I began to wonder: within a controller method like this one, is the instance variable an instance of the app itself? Are instance variables even tied to a class at all in this case?</p><p>I immediately remembered something fundamental — everything in Ruby is an object! It’s easy to get distracted by the name of the variable, in this case “books,” because in the past we have associated instance variables with a class by convention when working with classes and object relation mapping.</p><p>My initial contemplation was that, in this case with Sinatra, the name isn’t attached to the class it might appear to be referencing. Rather it is purely an instance, an acknowledgement that the information it is holding is dynamic and expected to be different the next time the request is made. Therefore it should not static, like a local variable we would use in the code we might want to use to complete the block.</p><p>But this turned out not to be true. Obviously local variables can change every time a method is called, as we’ve seen them do since the beginning. Duh!</p><p>For instance:</p><pre>post &#39;/books&#39; do <br>  book = Book.new(params)     <br>  book.save    <br>  redirect &quot;/books/#{book.id}&quot;<br>end</pre><p>So yes, some of what I had though is certainly true, but instance variables in Sinatra are really used to let one go outside the scope of the controller method and allow that information to be accessed in the ERB file. However, if the data we need passed into our ERB file is a hash, this isn’t the only way to do so.</p><p>The function ‘erb’ is also able to accept an argument of a key/value pair with the key being ‘:locals’ and the value being the key of the nested hash.</p><pre>post &#39;/new&#39; do    <br>  erb :&#39;book.html&#39; { :locals =&gt; params }<br>end</pre><p>Using an instance variable has become the standard since it’s the convention in rails. But there’s a thing called ‘partials’ we haven’t quite learned about in class yet where passing :locals can help be a little more precise.</p><p>As a quick side note, ‘partials’ allow you to call HTML code from one .erb view file into another by simply typing</p><pre>&lt;%= file.erb %&gt;</pre><p>For example, if I needed to use the same form to get a name on different pages of my site, I could create a new file called ‘name_form.erb’ and put in</p><pre>&lt;form action=&quot;/greet&quot; method=&quot;POST&quot;&gt;<br>  &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;</pre><pre>&lt;p&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt;&lt;/p&gt;</pre><pre>&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;<br>&lt;/form&gt;</pre><p>and then, in any other erb view files, I could simply write:</p><pre>&lt;%= name_form.erb %&gt;</pre><p>And using the :locals operation would allow us to change certain things about the partials such as input names or headers.</p><p>Sinatra is wild!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50a576106013" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RSpec (just a little bit)]]></title>
            <link>https://medium.com/@chrismetzgr/rspec-just-a-little-bit-87aad88a2787?source=rss-69b144917d88------2</link>
            <guid isPermaLink="false">https://medium.com/p/87aad88a2787</guid>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Chris Metzger]]></dc:creator>
            <pubDate>Wed, 20 Jun 2018 17:52:08 GMT</pubDate>
            <atom:updated>2018-06-20T17:52:08.524Z</atom:updated>
            <content:encoded><![CDATA[<p>When I began doing the pre-work for my bootcamp course at Flatiron School, I learned a little bit about RSpec through a page about it at the start of the Ruby curriculum. But I don’t think I understood the usefulness of of RSpec until the first week into the program when it became often recommended to me during my frustration with a problem that I check the spec file to see what the function is expected to do. Once I realized its value, I wish I would have utilized it earlier to save myself a lot of headache! Perhaps I put off familiarizing myself with RSpec because I was just becoming familiar with Ruby, and it seemed over my head then. Now that I have a better understanding of the Ruby language and the RSpec gem, I want to utilize RSpec testing and begin feeling comfortable writing my own tests.</p><p>When approaching a problem in the Flatiron curriculum, the spec files kind of supplement the instructions to make clear how the code should perform. When writing code independently, the practice of writing a spec file before writing the code itself is called test driven development, or TDD. Influential software engineer Kent Beck brought the concept of TDD to a wider audience in his 2000 book <em>Extreme Programming Explained</em>. Here were six points he made about the concept:</p><ol><li>Write the smallest possible test case that matches what we need to program.</li><li>Run the test and watch it fail. This gets you into thinking how to write only the code that makes it pass.</li></ol><p>3. Write some code with the goal of making the test pass.</p><p>4. Run your test suite. Repeat steps 3 and 4 until all tests pass.</p><p>5. Go back and refactor your new code, making it as simple and clear as possible while keeping the test suite green.</p><p>This is also simply known as the red-green-refactor cycle.</p><p>There are a bunch of different articles about how to use RSpec, and at the end of this post I’ll touch on some other ways engineers test code, but I just wanted to show that initially it can be really simple.</p><p>If you don’t have RSpec installed, first run $ gem install rspec. Then, in your project folder, create another folder called “spec” and make a spec file for the file named for the page of Ruby code you want to test. I made one for the “customer” model that I will make my Customer class in, so my spec file is called customer_spec.rb. We also need a spec_helper file to configure the test that you can pull off RSpecs <a href="https://github.com/rspec/rspec/wiki">github</a> page.</p><p>Require the file to the model in your spec page:</p><p>require_relative &#39;../models/customer.rb&#39;</p><p>and follow the format:</p><p>describe &quot;CLASS NAME HERE&quot; do</p><p>describe &quot;the_function_you_want_to_test_here&quot; do</p><p>to prepare the test.</p><p>I created a simple test that just checks to see if we created an instance of the Customer class correctly. An instance of the Customer class should be stored in a key and requires a first and last name to be initialized.</p><p>describe &quot;CLASS NAME HERE&quot; do</p><p>describe &quot;the_function_you_want_to_test_here&quot; do</p><p>let(:chris) {Customer.new(&quot;Chris&quot;, &quot;Metzger&quot;)}</p><p>it &#39;instantiates a new customer&#39; do<br>expect(chris).to be_a(Customer)<br>end<br>end<br>end</p><p>It’s helpful if we concisely and explicitly describe what we want the test to do. This helps us make sure we’re testing for only one specific thing.</p><p>The let(:variable) that you see above runs when the test is prompted. Other helper methods in Ruby let you define certain variable at other times during the testing method, depending on the complexity of the test.</p><p>After writing the test, write the code that you think will pass the test in the respective file model file.</p><p>So in customer.rb I wrote:</p><p>class Customer</p><p>def initialize(first_name, last_name)</p><p>end</p><p>end</p><p>Navigate to the project folder in terminal and run RSpec to see if the tests worked!</p><p>RSpec is one of two popular unit testing frameworks used by Rubyists. The other is called Minitest, which uses features built into Ruby like classes, modules, inheritance, and methods. Minitest is arguably tidier than RSpec, and functions more intuitively than a Domain Specific Language like RSpec. RSpec is in some ways more explicit, but Minitest has specific methods that work like Ruby thus making it feel more familiar.</p><p>Ruby actually has a built-in test library called Test::unit that is now considered defunct and isn’t updated. It’s based off of traditional methods used to test code in C++ and Java.</p><p>Although it seems like doing extra work, in the long run testing your code along the way can actually save time, and help you more easily identify where code is breaking if you are making any changes. The point of TDD is to break down writing code into step by step increments so that bugs can be sighted earlier and to reduce repetitive code editing. So start practicing writing your own RSpecs!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87aad88a2787" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>