08 February 2016

Week 03

Boom! Week 03 done! This is flying!!!! Fully immersed into Week 04 today, tackling SQL databases, but enough of that! This is a Week 03 recap!

The week started off with a lecture about the web. Http, Post & Get methods, Server & Client models etc etc. It then went on to building a short & sweet web app using Sinatra (a Ruby web framework) that hosted a picture of a cat online.. Sounds easy right?

From there it got difficult. We were introduced into a new type of testing framework called Capybara which you can use to test that your web app shows what you want the user to see! This therefore helps to give you a really good starting block to start developing your code.

Example of said framework testing the functionality of my Battle web app.

Capybara works hand in hand with RSpec so the syntax wasn't too difficult to get a grasp of... 'feature' blocks are like 'describe' blocks & 'scenario' blocks are like 'it' blocks!

From there the week focussed on building a rudimentary pokemon-esque game that allowed two players to take turns attacking each other, again this was using Sinatra, the app was then executed from the command line & played in the web browser.

Just a few snippets of how it looked, its basic as hell. But I wasn't gonna sit there creating CSS for it. Some people did, but thats not really what I enjoy, I prefer working with logic of the code. Which looked like this...

This is my controller which does the rooting of the game. Here instances of Player & Game are created which links back to my Ruby class files I have created in lib...

These lib files do all the heavy lifting of the logic and are where most of the games functionality is carried out. (Not very SRP friendly at the moment but I have a huge list of refactoring to do at the end of the course!)

These are then required in the controller which sort of initialize the game. The pages (what the user sees) are then rendered using .erb files which stands for embedded ruby! They tend to have a mix of Ruby code & HTML which looks like this!

This relates to that first page of the web app up top!

The weekend challenge was a long similar lines, we had to create an interactive game of rock/paper/scissors which I managed to do! Again I didn't use any CSS as I didn't feel I had to/didn't want to....

But I got it all working and it plays the game! Again I have to refactor out some stuff to follow SRP and the seperation of concerns & I could extend the game to play with rock/paper/scissors/lizard/spock. The code review I did with my pair-partner today really helped me go over the weekend challenge and I feel like I have a good understanding of building small web apps so far!

So thats it for last week, tuesday tomorrow and it is more about databases & implimenting them with web apps so I don't have to use EVIL EVIL global variables (which you should never use in a tech test, we just did it this time as we hadn't been taught about databases yet!)