learning to code

There was a point in firehose project where I would have a daily goal. That daily goal would be: 6 lessons per day no errors = success. And you know what it’s a lousy goal. Because when you code you will run into problems all the time. Goals like this make you feel lousy because, one, you didn’t get to reach your goal and, two, you are stuck. But it’s lousy for another reason and that is getting everything right isn’t really the point.

Knowing what you are doing wrong is just as important as knowing what you are doing right.

This realisation is the point when I decided to focus on what I was doing wrong instead of what I was doing right. These days my goal is no longer how many things I do correctly or how many lessons I get through, but how many errors I get. It sounds weird but yes I actually have set myself a goal for failure. If I hit 10 errors in a day I’m smashing it! Forget 6 lessons a day 6 errors a day I’m on track.

I now have a spreadsheet literally named ‘100 errors’. I’m not sure when I will reach it but I’m sure it won’t be long. Ha! I have 3 columns. The error message, what the problem was and the solution.

The first week of writing errors down has been more encouraging than ever. Rail’s errors feel less scary. I read through them through carefully. I’m getting better at solving problems on my own. The ruby errors for challenges are more frequent than rails errors but that’s getting better too.

Focusing on the errors can give you a better understanding about rails. If you are just starting out on rails you will at some point probably get an error similar to this one.

When you are starting out instead of the words ‘Precompiling assets failed’ you are probably seeing this ‘ERROR!! ERROR!! ERROR!! ERROR!!!’ Because what the hell are assets?

An asset is a file that is to be included in your Rails application (JavaScript, CSS, Image, etc). The asset pipeline is the framework that concatenates and minifies or compresses these JavaScript and CSS assets. And this is done by the sprockets-rails gem. Ah sprockets! so that’s what that is for!

The assets pipeline does. Three main things and a few others read here (http://guides.rubyonrails.org/asset_pipeline.html)

1. Concatenates Reduces the number of browser requests CSS and JavaScript files

2. Compresses CSS and JavaScript files: gets ride of code comments, white space and helps you zip versions.

3. Precompile ahead of time not with each request.

The precompiling is important! Precompiling is doing all this concatenation and compressing before production. Precompiling takes time. It can even take up to 1–5 mins. In your development environment this is done on the fly. But in Production it does not compile assets. It expects that to have already been done in development. This makes everything a lot faster!

Imagine doing this in production stage. There are not many people that would stick around 5 mins waiting for a site to load.

Rails automatically precompiles your assets ready for production. How does it do this. Well that’s what that sprockets gem is for. It compiles and servers the assets for you. Thanks sprockets!