8 weeks tuition, 2 weeks coding, 3 awesome apps; the Makers graduate!

Q. What could you build in a 2-week project after only 8 weeks of web-development tuition?

A. “CrowdDJ”, Story Tree and Audiogasm.

These are the three apps, each created in under 2 weeks, by our student teams at Makers Academy.

The idea behind CrowdDJ, which is not yet live outside of Makers Academy, is to enable a user to create a playlist for a party or event, by searching for artists and selecting tracks, then share the playlist on Facebook.  During the event, the playlist can be played on CrowdDJ (which uses Rdio) and friends can add new tracks and vote existing tracks up in real time.

Story Tree is a social story telling app which enables a user to begin a story, share it on Facebook and invite friends to propose additions to the story, vote up the latest proposed additions and eventually branch off to create a new story.

Audiogasm aims to transform choosing live music from a text-based experience to an audio-based experience.  Users can enter a location, a date and a genre and Audiogasm will instantly* start playing tracks by artists of the given genre, who are playing live on the given date in the given location.  If you like what you hear, you can click a button to buy tickets!

*performance may vary; it’s only v0.1…

So, will we see our newly graduated makers again, now that they’ve built these awesome products?

Actually, yes, they were all back at Makers Academy today!  I guess you can’t help it once you’ve been bitten by the bug…


How do you become a web developer in 10 weeks?

It’s the challenge the students at Makers Academy have taken on and I was delighted to join as an instructor with the second (March) cohort; alongside Leo Allen and Makers Academy co-founder Evgeny Shadchnev.

This week (week 5) we have been joined by the third (April) cohort and our new instructor Enrique Comba.

The schedule of weeks for the cohorts of Makers Academy currently looks like this:

Feb    1  2  3  4  5  6  7  8  9  10
March              1  2  3  4  5  6  7  8  9  10
April                          1  2  3  4  5  6  7  8  9  10

As you can see, February’s weeks 9 & 10 coincide with March’s 5 & 6; while March’s 9 & 10 will coincide with April’s 5 & 6 and so on.

We don’t just want to teach the students at Makers Academy how to code; we want to give them an authentic experience of professional development, including teamwork and deadlines.

Enrique had the inspired idea to combine the students in respective weeks 5 & 6 and 9 & 10 and split them into mixed teams.

Each team (there happens to be 3) has a team leader and will have 2 weeks to develop a complete product, which we, the instructors, will judge.  Prizes will be awarded for the strength of the product idea; design; execution; code quality; application of TDD and so on.  It’s The Apprentice meets the Silicon Roundabout!

Combining students from 2 cohorts creates a great dynamic as students on the earlier cohort naturally start to teach students on the later cohort and this helps them to validate their own learning and realize how far they have come.  Conversely, students on the later cohort get to see where they will be in four weeks time.

Working on team projects has massively increased communication and collaboration in the Makers environment and having something concrete to deliver has given everyone a shared focus for their individual purpose and motivation.

On Tuesday, The teams presented their ideas in the Makers board room.  These are highly entrepreneurial people and pitched 3 new startups, all born in just a couple of days.

I can’t wait to see the final products and picking a winner is going to be tough…

Rails Made My Day

Rails made my day yesterday when I delved into the truly awesome power of declarative associations.

I’ll use a pretty common scenario as an example, which, in the old days, would have taken me weeks to untangle:

We have three models, Person, Company and Address.

There are a number of key relationships that need to be modelled (ahem) and these are summarized as follows:

  • a person can have zero or more addresses
  • a company can have one or more addresses
  • an address can belong to one or more people and/or companies.
  • a person should have at most one address considered as the ‘main’ address
  • a company must have exactly one address considered as the ‘main’ address

There are also some basic UI requirements which need to be provided:

  • When creating or updating a person, the user should be able to edit the main address in the same form, or leave it blank
  • When creating or updating a company, the user should be able to edit the main address in the same form

The first observation I would make is that, although an address can, technically, belong to multiple models, it is counter-productive to try to model this in the schema.  Instead, we should treat an address as a disposable collection of text attributes, representing a physical address, which may happen to be duplicated multiple times in our schema (I feel better already).

I tend to think in third normal form (nod to the relational database die-hards.  It’s an old habit and Rails is beginning to cure me…), so my initial thoughts were as follows:

Person Company Address Model UML

You might choose a slightly different schema, with addressType in Address, but for me the addressType is contextual to the Person or Company, not the address itself.  Minor semantics.

This would map into rails as follows:

 class Person < ActiveRecord::Base
   has_many :person_addresses
   has_many :addresses, :through => :person_addresses
 class PersonAddress < ActiveRecord::Base
   belongs_to :person
   belongs_to :address
 class Company < ActiveRecord::Base
   has_many :company_addresses
   has_many :addresses, :through => :company_addresses
 class CompanyAddress < ActiveRecord::Base
   belongs_to :company
   belongs_to :address
 class Address < ActiveRecord::Base

I hope you’re still with me, because this is where it gets exciting(!)

The next job is to build the logic that manages creation of the main address (and the link object, e.g. PersonAddress) for new records, with an address_type of ‘Main’.  Then that all needs to be validated.  After we’ve muddled through and tested it all, we need to think about the UI logic and how to submit a main address to the controller using the same form as the person or company.  There there’s updates and deletes to get stuck into.

I feel nauseous.   Not least, because I’m going to have to do this all over again with telephone numbers…


After much more reading into associations in Rails, I decided to test the mettle.  Could Rails actually provide a declarative solution to this whole thorny problem?

Oh boy.  And then some.

Please see the models below to whet your appetite.  When I found this worked, it blew me away.

class Address < ActiveRecord::Base
  attr_accessible ...etc, :address_type

  belongs_to :addressable, :polymorphic => true

class Person < ActiveRecord::Base
   attr_accessible ...etc, :main_address_attributes

   has_many :addresses, :as => :addressable, :dependent => :destroy

   has_one :main_address, :class_name => "Address",
     :as => :addressable,
     :conditions => { :address_type => "Main"}

   accepts_nested_attributes_for :main_address,
     :allow_destroy => :true,
     :reject_if => proc {|attrs|
       attrs[:address_line_1].empty? || attrs[:postcode].empty?

class Company < ActiveRecord::Base
   attr_accessible ...etc, :main_address_attributes

   has_many :addresses, :as => :addressable, :dependent => :destroy

   has_one :main_address, :class_name => "Address",
     :as => :addressable,
     :conditions => { :address_type => "Main"}

   accepts_nested_attributes_for :main_address,
     :allow_destroy => :true

I won’t go into the details of poymorphic associations (or how to create the migrations and multi-model views to enable the main address to be entered alongside the owning model); it’s already well documented on Rails Guides and Getting Started with Rails.

However, some explanation is necessary:

  • The :polymorphic option allows the Address class to be associated to any other class via a proxy called :addressable, without having to know which other classes it is associated to (good encapsulation). Rails handles this with some additional columns on the address table.
  • Person and Company each have an additional association via a proxy, called :main_address in each case. The :conditions not only declare constraints on this association, but also act as build logic (see below)
  • accepts_nested_attributes_for tells Rails that the main address attributes can be passed to the Person model along with the person attributes (this enables :main_address to be built automatically from a form containing fields for both Person and Address models). Note the addition of :main_address_attributes in attr_accessible

These declarations are all that is required to do all of the work!

Now we can write statements like this:

@person.main_address || @person.build_main_address
@person.main_address.address_line_1 = '742 Evergreen Terrace'
# etc...

which builds the main address (already populated with the attribute address_type = "Main") and associates it with the person model, if the main address does not already exist. The main address also appears in the @person.addresses collection.

It all works perfectly in the UI also and the :reject_if option ensures that the address doesn’t get created if the address attributes sent along with the person attributes do not have an address_line_1 and postcode. Notice there is no :reject_if option on the Company model because the main address is not optional, according to our specification.


Hi Ho, Hi Ho…

…it’s home for work I know.

Oh dear. Bear with me, there is a theme to this.

I cut my teeth on VB6 and VB.Net, so I grew up with Visual Studio.  Coding outside of an IDE (integrated development environment) was relatively unknown to me.  I did occasionally edit batch files in a text editor; but almost everything else was done in the IDE.  You might  say I was institutionalized in the IDE paradigm; and I thought Visual Studio was pretty swell.

However, when I moved into Java, and began using IDEs like Netbeans and IntelliJ IDEA, I had a bit of a surprise.  I could not believe the vast amounts of additional functionality these IDEs provided over Visual Studio, despite being a fraction of the price (and in the case of Netbeans, free!).  In fact, when I went back to managing a C# team, I bought everyone licences for ReSharper (by JetBrains, who make IDEA) to add the functionality into Visual Studio that I’d become so used to having when coding in Java!  But that’s a different story.

So, when I started with Ruby, I wanted an IDE.  I’ve never been one for command-line programming or writing code in a text editor.  I know some developers prefer it and think it’s more hardcode; they’re probably right; but I prefer the path of least resistance.

I want an IDE that provides dropdowns and dialogues for running command-line tools, with auto-completes so I don’t have to remember everything.  I want an integrated console, log window, database view and integrated source control.  I want to be able to debug my code line-by-line; and not always because there’s a bug; sometimes I just want to step through each line as it runs so I can understand how it works.  I want intelligent shortcuts so that I can bounce between files and go straight to class and method definitions.

A good IDE is like having an expert developer with you at all times, quietly and unobtrusively whispering advice in your ear, highlighting mistakes and reformatting code.  An expert developer who is also an exceptional manservant; ready at your side with your car keys, the very moment you realize you need to drive somewhere.

And when you are learning a language or a framework from scratch, having your own personal expert/manservant is invaluable.

So, which IDE to pick?

I’ve always coded in dark text on a white background.  It’s what I’m used to.  I can’t get on with coloured text on a black background, which seems popular in the Ruby community.  I’ve tried it, it just makes me grumpy.  So one of my first criteria was an IDE that had a built-in (preferably default) theme with dark text on a white background.

The first one I found that met that criteria was RubyMine.  By happy coincidence,  RubyMine is also by JetBrains, so I was confident that it would be a solid product and similar to IDEA, which I’d used extensively.  I was not disappointed.

I have been using RubyMine for just over a month.  I can’t speak for it being the best Ruby IDE; it’s the only one I’ve tried; but it certainly provides everything I wanted and much more.  It isn’t open source, or free, but I’ve made back the £51 licence fee in time saved several times over already it feels.

Oh, and the theme?  If I haven’t made you too sleepy, you hopefully spotted it.

Ruby on Rails chose me

I have been a C# developer and a Java developer and I have run both C# and Java teams.  When I was recruiting, particularly in the Java domain, I would find myself wading through mind-boggling arrays of acronyms and frameworks listed on candidates’ CVs.  It was often difficult to gauge if some or all of a candidate’s technologies were relevant to our own particular platform (or indeed whether the candidate was actually proficient in any of them).  Variety is often the spice of life, but sometimes it is counter-productive.

I am hopeless at making decisions, so the thought of choosing a web technology stack to learn from scratch was daunting.  Plus, I was not looking for even more terms to litter my own CV.  There were many options (and attractions); PHP-based (Drupal), Java-based (Groovy), .Net-based (ASP.NET MVC, Azure) and more.  As I investigated each one, I found myself tumbling down yet another rabbit hole; lost in myriad browser tabs.

Then I investigated Ruby.  As a C# and Java developer, I found the expressive power of Ruby fascinating and the structure of the language very refreshing; but that wasn’t the killer feature.  There are many Ruby resources out there, sure; but if you are doing web development on Ruby, then you use Rails.  End of.  That’s what clinched it.  I didn’t even have to make a decision.

The next daunting challenge was to get Ruby on Rails running on my machine.  I’m not particularly hardcore; I’ve never been one for building from source; I like to press a button and have everything done for me.  I was expecting hours of configuration hell, forum trawling and text file hacking before the ubiquitous “Hello World” would, at last, proudly appear in my browser.

Not so.  I downloaded and installed the kit from http://railsinstaller.org/ and that was it.  There is very accessible documentation at http://guides.rubyonrails.org making it particularly easy to get started.

I love it when things just work.  And Rails just works.  In every sense.  It is concise, logical, intuitive and well conceived.  Convention over configuration is a new concept to me and the more I see it the more it feels right.  I think I may become a bit of a fan.

In the next post, I’ll discuss how I chose an IDE.