Note to Self: Intro to Backend
So, the most difficult part of Phase 3 is keeping track of what’s what and their relationship with each other. Obviously, this is nothing thorough or detailed about any of the subjects but I think it’s important to strengthen my grasp of the basic concepts since there was a lot of information in Phase 3. Here, I’m going to concern myself with mostly Ruby, SQL, Active Record, and Sinatra.
What is Ruby?
Ruby is an Object Oriented Programming (OOP) language, and bears some similarities with JavaScript. In Ruby, everything is object and is based off the real world. Objects have properties (as stored data in instance variables) and actions (in methods that define behavior).
Another type of programming is Procedural Programming (PP) where you build programs by sequential order. There are some advantages of OOP over PP, namely that in OOP, data security is prioritized, having its choice of public, protected, and public methods. OOP allows for inheritance, meaning different entities can have shared traits or behaviors inherited from a parent super class. Inheritance is useful because one can reuse code while no known feature exists is PP.
Something specific about inheritance is the :: operator or module namespacing which is a means to specify which methods are intended as class methods or instance methods. While inheritance < syntax implies state is a type of class, like this:
class Daisy<FlowerIf :: syntax is used, Daisy::Flower gives the Daisy class access to all constants and instance methods without stating Daisy is a type of flower.
What is SQL?
SQL stands for Structured Query Language. It’s a language specifically used to communicate with databases and is used by many kinds of database systems like SQLite (which we are using for our Phase 3 project). SQLite itself is a relational database that stores data in a structure of tables and rows like in a spreadsheet. A few important things to note are that different databases have different datatypes available. SQLite uses five: null, text, integer, real, and blob. Another thing is that the database store representations of Ruby objects, not the Ruby objects themselves but only raw data describing the given Ruby objects.
What is Active Record?
Active Record is an ORM integrated as a Ruby gem to link Ruby to the database. ORM means Objective-Relational Mapping and is a technique or design pattern of accessing relational database using an object-oriented programming language like Ruby. We use ORM because it cuts out repetitive code and implements conventional patterns that are organized.
Get Daisy Yi’s stories in your inbox
Join Medium for free to get updates from this writer.
Active Record takes care of queries written in Ruby into commands that the database understands so that programmers don’t have to manually make changes to the database. It connects to the database, creates tables, finds and saves data.
What is Sinatra?
Sinatra is a small web framework that provides Domain Specific Language (DSL) implemented by Ruby. It’s Rack-based, lightweight, and flexible for building simple, dynamic Ruby applications. A web framework provides structure and libraries to create applications, and it handles request routing, provides a mechanism for apps to respond to different URLs with the appropriate response, and renders templates.
In the App class, we inherit routing DSL from Sinatra::Base.
We can easily send responses in more than one format, such as html or JSON for a frontend app like React using .to_json. Another benefit of Sinatra is the ability to define dynamic routes, using the params hash which gives us information from the URL.
class ApplicationController < Sinatra::Base
set :default_content_type, 'application/json'
get "/creators/:id" do
creator = Creator.find(params[:id])
creator.to_json
end
endWhat is Rake?
It’s a task management tool in Ruby to help automate certain tasks like executing SQL, migration, seeding, using console, and more that can all be executed from the command line.
Sources:
Difference Between Procedural and Object Oriented Programming
A Quick Analysis of How Sinatra Work





