Steven Brooks' Blog

Student @Flatiron School

Day 5, Making My Params First

Although I have has multiple breakthroughs as far as my knowledge has been concerned over the last few days, I am still very stuck. The good news is, I am now beginning to think differently about my forms. Previously, I was worrying about the form first whereas now I am more conceded about creating the params that I want to be given from the form and then making the form first those params that I want. Here are the current params I would like:

My params

On the above code, I have a routine, which has a name. That routine has this thing called arbitrary which means nothing. But that routine has many lifts, each with an exercise_id and many infos(or sets) which have weight and repetitions.

These are the params I constructed in IRB.

The issue I am now having is that when I choose more than one exercise in my short form:

My form

The params are only showing :lift once. My guess is that it is only picking up the last exercise_id because it is overwriting each lift and just leaving the last one. After about two hours so far today going down a rabbit hole I have decided to post my first question on Stack Overflow. So if anyone can help you can see my first questions here.

Day 4…How Nested Can Your Form Be?

So yesterday I hit a little bit of a wall. And the good news it I’m not too worried about it.

Right now I have four objects being either created or associated with in my single form. The reason I’m being persistent about having all of this happen in one form is because if I was a user this is the way I would want to implement my workouts. I would want either create the workout beforehand and after my workout but in either scenario be able to implement all the exercises, sets, reps, and weight used. If this was not the case and I had multiple forms it would be easy peasy but that’s not what I want to do.

Today I’ll be working with Joe, one of the TA’s here at Flatiron to try to get my form working this way. If that gets done before the weekend, I would like to attempt to make this form using accepted_attributes_for. The reason I did not do that was because a confidant of mine suggested I do otherwise as actually locating all of the nested attributes is challenging, at least for someone with less than 8 weeks of programming under his belt. Also this weekend I am also going to be looking in AJAX because apparently that would solve my issues too.

Day 3, Four Models in One Form Are Driving Me Nuts

Grrrr. Tough night last night. The good news is that I’m only going to have one form for this app and that’s awesome. The bad news it that I am using four freaking models in my single form. But the good news on that is if I can get this I will be able to crush any form in rails, which is literally one of the top three most important things about rails that I can think of.

One of the things I learned is that in the create method in the controller, nothing in the joins table is happening until I save the information that is in the tables that the joins table belongs to.

Quick post, spent a lot of time just trying to wrap my head around how I get multiple models in one form. I realize though I can accept_nested_attributes for the sets within the lifts.

Day 2, Switching to Form Tag From Form For

So last night I was able to get about an hour of work in. I feel like that a sustainable pace considering I do not want to have energy taken away from my Library group project.

Anyway I feel very strong with form now. Yesterday, I was doing some work with my form with one of our TA’s, Jeff, who recommended I back down from form_for and move to form_tag. That worked wonders as there is far less rails magic involved in form_tag, and I also am literally only going to have one form for the user to input data for multiple objects.

Form_tag was much easier for me for many reasons. First, I was able to create to params hash the exact way I wanted to. This made it very easy for me to locate the the proper information in the controller and add that information into different instance variable. That process was repetitive, which I enjoyed because I feel I made large strides yesterday as far as the M and C of the MVC model goes.

I also was able to add sets to lifts(which is a joins table between routine and exercises). Now each lift has many sets which include repetitions and weights.

Staring My Own App

For me, today is the day I have become a programmer. Actually, it was pretty exciting and I even got a little emotional about it. Yesterday(Sunday), I began creating my own application, and very much enjoyed making it on my own, solving some bugs on my own (or at least the ones I was able to understand). It was very exiting for someone who has only been programming for 7 weeks. I have come very far and would like to challenge myself in creating my own app.

My friends are very into fitness as well as I am. We compete in Crossfit events and I wanted to create an app where myself and my friends can input the data from each of their workouts, on top of just having a log, and being able to see their and their friends’ progress visually with visual representations to track progress.

I would like to have a post each day, or at least try to have a post each day, or now that I am thinking about it I should make a post with each new thing I learn while building. Actually I think I’ll do the latter.

I first built three models, a routine model, and exercise model, and a lift model which is a joins between routine and exercise. The first issue I came into was the form in which I am attempting to allow the user to create a workout along with exercises for that specific routine. One of the first issue I found is that each time a user makes a routine, the corresponding exercises are being saved into the database as new exercises. So if I have a “squat” in one workout and create a “squat” in another, there becomes two instances of “squat” in the database. I decided to push that back because my form is already a mess.

In watching Nested Models on Railscasts, the author talks about nesting models within the form. In my routine form, I wrote “accepted_nested_attributes_for :exercises”. Now while this will allow each exercises to be nested within a routine, and with the knowledge I have in 7 weeks, I cannot get access to each exercise in the instance of the routine.

I realized my form is messed up. I need to do something like “f.label ‘routine[][exercise[name]]” or something in the form and then in the controller loop through that array of exercises and << or shovel them into that instance of a routine such as “@routine.exercises << whatever_the_params_are”.

For me thats a big breakthrough to be able to get this on my own. It’s exciting. Being able to get the data in a way you want it to is beyond important in Rails and I feel I am on my way!

All in the Family

After a fantastic weekend at the beach I was talking to my younger brother David over a nice Paleo dinner where we absolutely crushed The Stable. David is a CS major and on the side develops iPhone applications. He has made a few apps with his most popular being “Never Have I Ever” and is currently creating a location based app this summer.

David code 1 David code 1

I was explaining to him why I believe native was garbage and so we were talking about some of the things he enjoyed and didn’t enjoy as far as iPhone development. We talked for a while and I remember he said a few interesting things about Objective C and specifically native applications in general. Because I paid for dinner he was kind enough to answer a few questions:

Steven: What are some of the difficulties in using objective C?

David: A major complaint that a lot of programmers have relating to Objective-C is that a Mac is required in order to actually write and compile your Objective-C code. It is unfortunate that Apple does not allow the development of Objective-C on a Windows based platform. This denial of Windows based developers means that if someone wants to develop for the iPhone/iPad/Mac, you must first pay Apple to get a Mac and then pay Apple $99 yearly to be part of their developer program. In terms of actual code writing, I do wish that it was easier to test your app on multiple devices. In order to test a singular app on multiple iPhones, you have to collect the device id and create a Provisioning Profile, which is basically a certificate that allows the app to run, and distribute that profile to every device you want to use. This makes it a big challenge if I want to, for example, show my brothers my latest app and let them fool around with it and provide feedback.

Steven: What do you think could be easier in developing with objective C?

David: One thing that I would like to be easier about Objective-C is how it uses Frameworks. Frameworks in Objective-C are like libraries in C or like packages in Java that you must import in order to use their information. It is annoying to have to figure out what Framework you need to include in order to use a certain piece of code. It would be a lot easier if all the Frameworks that have been created and are available to you to use and just automatically imported by the compiler when needed. All the Frameworks we use are already included in iOS or OS X, so why can’t the device choose the needed Frameworks instead of me telling it to?

Steven: Do you feel objective C will be around in three years?

David: Yes I believe that Objective-C will still be around and heavily used in three years time. We are currently in an evolving technological world which has transitioned to computers the size of rooms to handheld computers and smartphones. I must point out that, Objective-C has not created solely for the iPhone. Objective-C was created by Apple for the Mac and Mac OS X. Once the iPhone came around, it was then transformed to work with iOS as well. Therefore, in addition to the ever growing mobile market, the fact that Objective-C is used to build applications for the Mac means that it will endure through the years.

Steven: Why did you choose to learn objective C over web application languages?

David: When I was a Sophomore in high school, I taught myself C++ and a little bit of Java. I had no previous knowledge or involvement with HTML or web development and decided to focus on software engineering. Then, the invention of the iPhone came around and I was hooked. I saw it as this awesome new product that everyone would be talking about and so turned my attention to mobile development. It is very interesting to point out that, I am a rising Junior at Loyola University Maryland, aiming for a BS of Computer Science and a minor in Mathematics, and yet, I have never once touched HTML. In fact, HTML is not even in the CS curriculum because our faculty believe that it is such a basic and easy language that they do not even bother teaching it to us. Instead, we are to learn it ourselves outside of the classroom if desired.

Pretty interesting stuff. I definitely learned quite a bit from talking to him. We are both programmers and learning completely different things.

I was telling him as much as I could about Active Record because I am just obsessed with the type of magic it provides to me and I asked him to show me his code for importing data into his database, saving it, and displaying it. This is what I got in return:

David code 1

David code 2

David code 3

David code 4

David code 5

So somewhere in here he is getting a users location and storing it into a SQL database, then saving it, then making it available. Apparently in Objective C you have to make methods on methods on methods for a lot of things that with Active Record you can simply run a migrate. I also realize that the way I presented this code makes it look like databasing in Objective C is the worst thing in the world. There is a good amount of code here for actually finding the location of the users, but it is still a lot.

Thanks David for letting me interview you.

David code 1

Beast mode.

Sinatra

The sinatra-examples folder structure at first glance appears to be very large but fortunately very organized. On the first screen there are five folders as well as a three additional files. These additional files are :

.rvmrc – This is a small file which appears to list the ruby version in which the program runs on.

README.md – This file appears to give a brief outline of the five folders as well as a setup guide to install the files and run them on a local computer.

classic.rb – This file appears to show a brief example of what a sinatra app looks like. By requiring ‘sinatra’ at the top, this could mean that sinatra gives a large framework for a program and customization can occur.

The first of the five large folders is:

Assetpack

assetpack – This large folders contains four additional folders as well a seven files. The first additional folder is:

.sass-cache – Google claims this folder is used for making compiling faster. It appears as if sinatra creates this folder automatically. Within this folder are two additional folders which each hold contents that are very similar to images.

app – This folder holds css files in their own folder, images in their own folder, and js in their own folder which also holds query files.

lib – This library folder is very large. It holds a sinatra folder. That sinatra folder holds as asset pack folder. That asset pack folder looks like it holds files all containing the sinatra Module and many different sub-modules.

views – The views folder here holds a file index.erb. This would be the erg template for the index page of the app.

The assetpack folder also contains a few other files also including a Gemfile which requires additional gems to power the application.

Middleware

middleware – the middleware folder is the second folder on the top level. This folder contains two sub-folders:

basic_auth – this folder holds an app.rb files, which appears th eve the basic authentication file for the application. It also holders the config.ru file which appears to run the authentication file above.

examples – the example folder is filled with a few files. Most of them appear to be in some form of Rack in which they are sending information to the server and receiving back status, headers, and responses. There is also a no_chrone_middleware files which is interesting to me. The content of the file appear to redirect the user to Internet Explorers default download page. Does this file send users without Chrome to IE? The config.ru rile which was also listed in the basic_auth file also runs the application, but my question is which application is it running?

Modular

modular – this is the third folder on the top level of the application. This folder only contains two files. It contains a config.ru files which runs the application in the modular folder and a modular.rb file which inputs a sinatra base modular into the application.

Multiple-app

multiple-app – this is the fourth top level folder which holds a websites folder and a config.ru files. The config.ru file here runs the application but I am unsure as to which part of the application gets ran from this specific file. The website folder contains four files; blog, init, search, and site. The blog file appears to put a sinatra modular into the blog class which I am guessing powers the blog portion of the site. The init file requires other parts of the site I am assuming at the beginning. The search file is similar to the blog file in which a modular is being passed into the search class. The site file is also similar to the blog file in which a sinatra modular is being passed into the site class. In all three instances, the same modular is being passed into the blog, search, and site .rb files.

View

view – the view folder is the fifth top level folder which contains a view folder as well as an app.rb file and a config.ru files.

views – the views folder has a admin folder as well as a few additional erg and haml files. The erg files I am assuming are template files for the index, layout, and my_partial. The admin folder appears to hold an erb file that is the outline of the administration section or page of the application.

After doing this assignment I can better see how to structure the files of an application. I am sure as I get more involved with Sinatra I will see repeat structures as well as files in specific folders.

Baseball Is a Game of Pixels

When I started coming up with ideas for this post I began by thinking about my specific issues in the code I have written to date (12 days) and the concepts that would help with those issues. One of the issues I had was keeping track of all my methods/variables early on and trying to find where each method/variable was coming from and what information it was giving. I then wanted to see if I could come up with plugins for Sublime 2 that would paint a background color pasted behind each variable/method as well as where else it would be in the code, and that background color would stay there as long as you wanted. This is different than Sublime circling the words or phrases you click on. Eventually I ran this by a classmate who tore down the idea so I will not be writing about that.

Over Chipotle on Tuesday I was speaking to two classmates about some of the things I did as an athlete and baseball player and was telling them that it was amazing how many similarities there were between being a baseball player and a programmer. I’d like to introduce you to some of them:

It’s Not Boring

Baseball, like programming, seems to be doing the same thing over and over again, which is why people perceive it to be boring, but that’s really just to the untrained eye. In baseball, you play the game with the same rules each day and as a hitter you hit against a pitcher every day. But every day is a new game and again a new pitcher or set of pitchers. The same macro level things occur daily in games but the fine elements of the game change every day.

Programming is very similar where for the most part you are coding into a computer every day, but you are not writing the same code each and every day. Each day brings new tasks, errors, and goals.

Be Comfortable With Discomfort

Being the batter in the 9th inning of the ACC Baseball Championship Game with the bases loaded where your team is down by one run and the opponent has their best pitcher throwing against you in front of thousands of people is not comfortable. Period. Writing dozens of lines of code only to find out none of it works when you have a deadline in five minutes and you have no idea what the error message in Terminal is telling you is not comfortable.

Discomfort is part of the game in baseball and programming. As a baseball player I was at my best when I accepted these situations as part of my role and became comfortable with discomfort. The same goes for good programmers, they must be comfortable with discomfort and realize that creating code that doesn’t work as well as not knowing how to do certain things is part of the role.

Breaking Things Down

As I have learned first hand in my first twelve days as a programmer, programs have many many parts. The same goes for a swing in baseball. In a swing, there are many, many, many, many smaller parts that create the whole swing just as there are many, many, many, many smaller parts that create an entire program.

In both scenarios, the key is to break down the whole into smaller and more manageable parts so when something goes wrong, it is easier to pinpoint error. In baseball if a player happens to be lunging forward before he swings rather than trying to say the entire swing is a mess he may pick a smaller part in his swing. Looking at something like film could help the player pinpoint the smaller issue. Typically, if a player is lunging in the batters box then their is an issue with his head (interestingly enough).

This scenario arrises in code as well. If a programmer is trying to run code and an error pops up it would not be wise to suggest the entire program is wrong and throw it away. Looking at the error messages that come up will allow the programmer to pinpoint the issue down to a smaller aspect rather than the entire code.

Practice & Adapting

If you don’t use it you lose it. Yes, you do. Everybody wants to hit home runs, but you won’t even be put into the starting lineup unless you practice your craft and are always improving. If you are not always trying to make yourself better, you are getting worse and there really isn’t anything in between.

As programmers, the more code we write, the more familiar we become with things such as syntax, and the better we become at coding. You also won’t be able to make Facebook if you don’t know the basics and whatever else goes into making Facebook. Its just like the more batting practice a baseball player takes the better he becomes (in theory).

Both professionals also require adaptation. Ever since technology began to play in integral role in baseball players have had to adapt more frequently and in shorter times. The information the teams can get and store on individual players is astonishing. Every at bat I had starting in college was tracked to the “T”. Every opponent knew about each of those at bats and would pitch me a certain according to my perceived weaknesses. As a player I needed to adapt to those changes and work on my weak points. Once I got better at those first weak points others would arise and would begin the cycle again. If I was unable to adapt quickly, I would have been no good.

While improving on weak points in programming is important, it is also equally important to be able to move with the times. I say this as far an new languages, technologies, updates, etc. I am currently running Ruby 1.9.3 but I am willing to bet that soon I will need to use a newer version and quickly learn the differences in the newest version and be able to implement them. And after that I’m sure a newer version of something will have come out by then and I will have to repeat the cycle.

Playing On a Team

This was the most surprising of the bunch for me. My younger brother is a Computer Science Major in Loyola in Baltimore and from what I could gather from him, being a programmer meant there would be little interaction with others. Once I began as a student as The Flatiron School I quickly realized that this would not be the case, rather it would be the opposite. Being able to program as a member of a team was kinda the icing on the cake for me as far as becoming a developer.

Like in sports, working well with a team takes a certain skill set. So far, it has been much easier to work with a team of developers (my classmates) that it was to play with baseball players. In the environment I am currently in, all of us are trying to learn a new skill together, so it makes more sense as of right now that the members of the team are easier to work with.

There are some others things such as preparation and mentality that are very similar between the two. But there are definitely some surprising similarities if you ask me. Who would have thought these two people were so similar?

class zuckerberg class player

Also I wrote this post last night and after proofreading this I realized that my sentences are wayyyyyyy too long. Kinda like my methods.

Testing Ruby

I was quickly drawn to “Testing Ruby” by Emily Price because as a rookie programmer I have come to realize that things such as planning and testing are very important.

Ruby Testing

She writes that testing does many things for a programmer including:

  1. Ensuring the code is correct
  2. Promoting good practice
  3. Giving reference to how to code actually works.

In the first two weeks at Flatiron School, testing out my code before moving on has become very important. If I can know for certain that a method works (by testing), I never have to worry about that method later on in my program. It seems like such a simple idea but it was only something I found important after writing dozens of lines of code and realizing one of the first few lines did not work.

One pointer that Price writes about that I learned was to:

  1. Write your test first

This is something that I can see would be very useful. At this point in my programming career I am just learning how to do that so this slideshow comes at a good time for me.

Some of the things I thought of during my first two weeks as a programmer that she brought up were:

  1. Get instant notification when you have an issue
  2. Write as little code as possible to test

As my skills as a programmer grow, I would like to be able to create some sort of a process in which I develop certain ways to test my code to find errors as soon as I can.

Price also has a Git Introduction slideshow on speakerdeck.

Pretty Juiced About the Work I Did Last Night

This morning will be the seventh day of The Flatiron School. Yesterday (the sixth day) was by far the most challenging day for me. Yesterday we were introduced to many new things in the ruby language and it became a lot to comprehend all at once. As yesterday was seemingly overwhelming, it became very clear to me that no matter what the issue, the process becomes very important.

We were given a homework assignment to create a basketball game with the following guidelines:

homework guidelines

For my seventh day, this assignment also felt overwhelming. Luckily for me (some would say), I have an hour long bus commute going home so it was a great opportunity to do some reading on hashes (which is how we were supposed to create this data).

While this feels like a lot of information for me (or at least it did), remembering the process became key (play on word). I chose to begin by planning out everything and talking myself through what these hashes would visually look like. Eventually I was able to visualize these hashes as simple numbered lists:

numbered list

Eventually, my code ended up looking something like this (which I’m very proud of):

my code

I am very happy with what I did on this homework assignment as I successfully took a large project and was able to plan out my execution well and break it down into smaller parts.

Later on in the assignment I was asked to make calls to the hash $basketball_game which maybe I’ll talk about in another post.