{"id":1166,"date":"2013-09-30T21:37:42","date_gmt":"2013-10-01T04:37:42","guid":{"rendered":"http:\/\/zackmdavis.net\/blog\/?p=1166"},"modified":"2013-10-06T22:08:34","modified_gmt":"2013-10-07T05:08:34","slug":"app-academy-diary-week-three","status":"publish","type":"post","link":"http:\/\/zackmdavis.net\/blog\/2013\/09\/app-academy-diary-week-three\/","title":{"rendered":"App Academy Diary, Week Three"},"content":{"rendered":"<p><span id=\"monday\"><em>Monday 30 September 2013&mdash;<\/em><\/span> Today's assessment was implementing <a href=\"http:\/\/en.wikipedia.org\/wiki\/Crazy_Eights\">Crazy Eights<\/a> in accordance with the given RSpec tests. In the afternoon, I worked with <a href=\"http:\/\/quan.io\/\"><em>Dan Quan<\/em><\/a> on exercises from the <a href=\"http:\/\/sqlzoo.net\/wiki\/Main_Page\">SQL Zoo<\/a>, which varied wildly in difficulty.<\/p>\n<p><span id=\"tuesday\"><em>Tuesday 1 October 2013&mdash;<\/em><\/span> Today I worked with <em>A. J. Gregory<\/em> <a href=\"http:\/\/zackmdavis.net\/blog\/2013\/09\/app-academy-diary-week-two\/#saturday\">again<\/a>, this time on a cute Ruby program for interacting with a database. A few remarks follow. The first remark: I much prefer the <code>%Q<\/code> syntax for multiline strings over heredocs. The second remark: it turns out that using string interpolation to compose database queries is very bad, because it leaves you vulnerable to SQL-injection attacks. The third, and final, remark: you shouldn't name any of your Ruby classes &quot;Data,&quot; because apparently this name is already used by a regrettably exposed implementation detail of the interpreter itself.<\/p>\n<p><!--more--><\/p>\n<p><span id=\"saturday\"><em>Saturday 5 October 2013&mdash;<\/em><\/span> Dear reader, suppose <a href=\"http:\/\/zackmdavis.net\/blog\/2013\/09\/app-academy-diary-week-two\/#sunday\">again<\/a> that you're building the great American dog-sharing site. One problem that you face is that the the most convenient way of storing data in the database isn't exactly the same as the most convenient way to manipulate data in your program. It would be nice to have some standard tool for translating the rows in your database table to occurrence of a particular class in your favorite programming language and back again, without having to futz with the syntax of the systematic questioning lexicon every time you add a new feature ... some sort of\u2014<a href=\"http:\/\/en.wikipedia.org\/wiki\/Object-relational_mapping\"><em>occurrence&ndash;row matching<\/em><\/a> ...<\/p>\n<p>The Ruby on Rails framework (does anyone else think <em>Ruby on Rails<\/em> sounds like the title of an action movie about a woman named Ruby who has to fight spies on a train?\u2014no?) includes a library called ActiveRecord for this purpose. Suppose your database has a <code>users<\/code> table for storing all the user data, and a <code>dogs<\/code> table for storing all the data about dogs. And suppose we want to say that each dog is owned by a particular user. We can do that by including an <code>owner_id<\/code> column in the <code>dogs<\/code> table; for each row in the <code>dogs<\/code> table, this column will store a number referring to a row in the <code>users<\/code> table, thus indicating the user that owns that dog. Columns like this that refer to another table in the database are called <em>foreign keys<\/em>, and we also want to tell the database to <em>index<\/em> them so that we can search them in logarithmic rather than linear time in the number of rows. Then, when we write the classes to represent users and dogs in our application code (these are called <em>models<\/em>), Rails gives us nice shortcuts to make it easy to retrieve (respectively store) their information from (respectively in) the database. In the <code>User<\/code> class, we say that a user &quot;<code>has_many :dogs, :class_name =&gt; &quot;Dog&quot;, :foreign_key =&gt; :owner_id, :primary_key =&gt; :id<\/code>&quot;, and we put a similar <code>belongs_to<\/code> statement in the <code>Dog<\/code> class (the <code>belongs_to<\/code> corresponding to a <code>has_many<\/code> always goes in the class whose database table contains the foreign key), and then everything is great forever.<\/p>\n<p>On Wednesday I worked with <em>Mainor Claros<\/em> on a simple URL shortener, and on Thursday I worked with <em>Scott Silver<\/em> on models for a simple polling application. Yesterday the original plan was to have a solo day during which each of us would implement our own simplified version of ActiveRecord (... SedentaryRecord?), but at some point it was decided that the office was needed to host hiring day for the cohort before ours, so there was no class yesterday and we'll do SedentaryRecord on Monday of next week. I told myself I would get something educational done just the same (App Academy is providing value added in the form of guidance, connections, and a working environment, but if you're a long-time reader of <em>An Algorithmic Lucidity<\/em>, then you know that I know that the ultimate responsibility for internalizing knowledge must rest on individuals, not institutions), but I'm sorry to report that some of the more frivolous distractions of the internet (as well as a science-fiction novel that I purchased Thursday night on a whim at the bookstore inside the library in the city, which I had not set foot in since I think the March of 'aught-ten) proved too tempting that day. But fear not, dear reader!\u2014for today and tomorrow are an entirely different story, in which your faithful correspondent will no doubt make tremendous progress in his quest for true knowledge of the nature of web development, as well as related matters of concern, like who would win in a fight between the <a href=\"http:\/\/www.mysql.com\/about\/legal\/logos.html\">MySQL dolphin<\/a>, the <a href=\"http:\/\/wiki.postgresql.org\/wiki\/Logo\">Postgres elephant<\/a> (PostgreSQLephant?), and the bird that the <a href=\"http:\/\/en.wikipedia.org\/wiki\/File:SQLite370.svg\">SQLite feather<\/a> was taken from.<\/p>\n<p><span id=\"sunday\"><em>Sunday 6 October 2013&mdash;<\/em><\/span> Yesterday and today I looked at the instructions for the project scheduled for tomorrow which I've been calling <em>SedentaryRecord<\/em> and started working on a Python version (including <a href=\"http:\/\/docs.python.org\/3\/library\/unittest.html\">tests<\/a>), which I've been calling <em>SerpentineRecord<\/em>. Why? Because ... because I can. And because even though this is a Ruby\/Rails course, I've been toying with the idea of preferentially shooting for Python\/Django jobs when this is over. My thought is that Ruby and Python are filling the same niche in programming-language space, so that in the long term, it's only worth specializing in one of them: <em>really<\/em> mastering a tool (not just the basic syntax, which is easy, but the technical minutia and ecosystem and everything) is costly, so you want to allocate your finite amount of effort into mastering an orthogonal set of tools, rather than many tools that do mostly the same things. So if I <em>will<\/em> ultimately have to choose, I'm inclined to go with my first love, Python, even if that's only an arbitrary artifact of what I happened to learn first. Is that wrong? Is it petty of me to care about the merely cosmetic issue of syntactic whitespace versus <a href=\"http:\/\/zackmdavis.net\/blog\/2013\/08\/doend-macros-for-emacs\/\">that execrable word <em>end<\/em><\/a>, even while Ruby's blocks are suffused with grace and power whereas Python's lambda statement is deliberately crippled precisely because of whitespace considerations?<\/p>\n<p>I don't know. But in any case, my money is on the dolphin.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monday 30 September 2013&mdash; Today's assessment was implementing Crazy Eights in accordance with the given RSpec tests. In the afternoon, I worked with Dan Quan on exercises from the SQL Zoo, which varied wildly in difficulty. Tuesday 1 October 2013&mdash; &hellip; <a href=\"http:\/\/zackmdavis.net\/blog\/2013\/09\/app-academy-diary-week-three\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[64],"_links":{"self":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts\/1166"}],"collection":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/comments?post=1166"}],"version-history":[{"count":6,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":1173,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts\/1166\/revisions\/1173"}],"wp:attachment":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/media?parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/categories?post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/tags?post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}