Matthew Lang avatar

Matthew Lang

Web developer with a preference for Ruby on Rails

What is The Rails Way?

It's a question I've been asking myself as I switch between different Rails applications for different clients. In my early days of working with Rails, I had a preferred selection of gems that I liked to use and that I stuck with for many Rails applications. After a few upgrade issues on a couple of applications I started to pay more attention to how I build applications with Rails. I questioned the gems that I was using and my testing practices. As I've gained more experience I've started to see that working closely to the Rails framework when building applications has some benefits that I previously overlooked.

What you're about to read isn't a silver bullet approach to building Rails applications. This is simply a guide to what I've find works for me.

Application Architecture

In the past most applications I worked on followed the old favourite of "fat model, skinny controller". Most applications tightly followed the MVC pattern and very few classes or objects were located outside of these three folders of the application. It does work, otherwise Rails wouldn't be as popular as it is, but following the MVC pattern did present one problem. Models became huge wells of code as they tried to contain the bulk of the application's code. Now I try to follow some best practices when coding but I don't strictly adhere to them, but you have to admit that a model with a 1000+ lines of code could probably be trimmed down a bit.

Since reading and watching a number of different ways in organising your Rails application, I've started to see the argument for extracting business logic into individual classes. You might be thinking of service objects or Hexagonal Rails when I say this. It's the same idea. I've started to keep classes that contain business logic in the app folder, alongside the rest of the application's objects. The reason for this is that I see the business logic as being part of the application, not a seperate layer or component of the application. I'm using Rails for my application, so I want to keep the business logic close to the rest of the application.

Gem Dependencies

Gems sure are handy. Just add to the Gemfile, install and your application has access to new functionality when it needs it. While adding gems is the easy way to add functionality to your application, you then have a dependency on that gem to stay maintained.

Before you even begin adding the gem to your Gemfile, ask yourself if it is truly necessary for your application?

In the past I would happily add a gem that I thought I needed, but now I take a different stance on it. If a gem provides just a small bit of functionality to the application, I take the time to spike a similar or better solution for the application on my own. The reason for this is that sometimes a gem won't do everything you need it too. If it can provide everything you need then great, but if it only provide most of your needs, could you add the complete functionality that you need by yourself?

Building this functionality on your own isn't always the best way to go, but if your application has specific requirements, then I say it's definitely worth looking at. Rolling your own solution to your application's requirements means that your solution could be a better fit for your application than anything else that's out there. It also means that with your own solution, you are responsible for keeping it maintained. Lastly, it keeps your Gemfile lean and the dependencies for your Rails application lean. I don't suggest you do this for everything, just the gems that you might question over their suitability for your application.

Testing

In the past I was a keen advocate of Cucumber and RSpec. That has changed over the last year. I'm finding that the testing tools that Rails provides are more than adequate for new Rails projects and sometimes better suited for smaller Rails projects.

Out of the box Rails provides Minitest through Ruby to write your tests and fixtures to organise the data you want to test against. Minitest is flexible in that you can write tests or specs depending on your preference, so I don't have any issues there. Minitest in a new Rails application is straightforward and it doesn't require any changes to your application's setup to get it working. Why even bother changing?

The real benefit I've seen though is in doing testing the Rails way is by using fixtures. They do require some initial effort to put together, but they're always there for subsequent tests runs and soon you'll start re-using fixtures for different tests and rarely have to touch them.

Rails is a database backed web application framework. Now I've seen the arguments for isolating the database from your tests, but for a framework that persists its data to the database, I think it's overkill to start stubbing out calls to the database and canning data using factories. This is why I like using fixtures. It's real data you're working with. A complete working set of test data.

Finally, an argument against using fixtures in the past was that tests took too long to run. I have to say that this is not a concern now. I have worked on a number of Rails projects using Minitest and fixtures and while their test and assertion counts run into the hundreds, I've yet to see a test suite take longer than 30 seconds. And even if your test suite is on the large side, it shouldn't be a major concern as you should have your tests automated to run as you edit your code by using something like Guard or Spork.

So What is The Rails Way?

Since I've made a few changes in how I build Rails applications, I'm definitely a more productive developer and I'm able to build new features with minimal fuss. The Rails way for me is working with the tools that Rails provides and building an application as close to the application's own models, controllers and views as you can. Simple patterns and designs are available to reduce complexity but aren't always necessary. I don't suggest you immediately think about re-writing your whole application to fit around these three suggestions, but bear them in mind for any future Rails projects that you have.

Clarity Through Blogging

Perfect time to be reading this again.

Even if nobody reads them, you should write them. It's become pretty clear to me that blogging is a source of both innovation and clarity. I have many of my best ideas and insights while blogging. Struggling to express things that you're thinking or feeling helps you understand them better.

You Should Write Blogs by Steve Yegge

A Big Problem for Google

Marco Arment on what could be Google's biggest challenge yet.

Shallow social-shareable listicles and clickbait headlines have always been plentiful on the web, but it does seem clear that they’re getting much worse and more dominant recently.

Google is making the problem worse, but they’re not the root problem. In fact, the real problem is a pretty big problem for Google, too:

Everyone’s spending increasingly more consumption time dicking around in apps and snacking on bite-sized social content instead of browsing websites and searching Google.

Google and blogs: "Shit" by Marco Arment

Does this explain why Google are going to show tweets in their search results?

If the postman wasn’t singing so bloody loud, he might have realised that he was delivering mail to the wrong door.

Short Term Contractor, Long Term Freelancer

Even before I started freelancing, I always got confused by the almost interchangeable career titles of freelancers and the jobs that were available to them. Contractor, consultant and freelancer. Are they specific to the type of work freelancers do?

When I started freelancing, I decided to market myself as a "Freelance Web Developer". I had thought about the different titles I could use but I paid more attention to the technology field rather than the type of work I would be doing. I stuck with the title of freelancer as I simply thought it best described who I was. This was almost right, I wanted to freelance but what I wanted to start work on was contract work.

Starting Out As A Contractor

To begin with I was keen to look for roles where I could gain a bit more experience working as part of a remote development team. I wanted to work in remote teams to see how they continue to progress with projects. In the past I worked in teams that shared the same physical space and therefore communication with other team members was easy. How does this affect remote teams?

I also wanted to gain more experience in my preferred choice of technology stack. I had a number of roles working with Ruby on Rails, but I was definitely far from being an expert on the framework. A few gigs working in different teams would quickly identify areas where I might be short on knowledge. Thankfully this wasn't a problem.

Armed with these two goals, I found out that contracting would be the best work for me. As a contractor I can market myself as a development resource to clients. They might be looking for that extra programmer needed to finish a project or they might need a developer with experience in a technology stack that they are lacking in. Whatever the reason, my primary role as a freelancer so far is as a contractor.

Long Term Focus As A Freelancer

I don't want to be a contractor forever though. In time I would like to gradually move across to being more than just another "butt in a seat".

Contracting is good because it means the decisions are largely removed from your hands. Your clients decide the work for you and you as the contractor fulfil your client's needs. While this type of work does pay the bills and keeps my career going, I don't believe that this should be my long term goal.

Doing the work is one thing, but advising the client in the way in which they can best achieve their aims is the work of the consultant. While I could market myself exclusively as a contractor, I would in fact like to be more than just another programmer in the team. I would like to be more of mix between contractor and consultant.

What's The Next Step?

This is where I believe the term freelancer applies to the type of business I want to have. I love programming, and being able to work with a client's team and help fill a gap is where I'm comfortable and productive. It shouldn't be my only selling point though. To do this, I'm going to need a web site that focuses on business and freelancing and nothing more. It's going to need material such as test cases and examples of work that back up my abilities as both a contractor and a consultant. I'll see what I can come up with.

Good Weekend For Golf

It was a good weekend for the members of Elderslie's Junior Newton Shield squad. Coaching on the Saturday with the club pro followed by an opportunity to play on the course for all levels of members in the junior section on the Sunday. All those involved with this in the club should be commended. It's great to see kids of all ages being encouraged to play and compete.

Photo of the junior squad practicing their short game

Getting Noticed

I've always been the quiet type, often electing for the quiet corner of the room rather than being the speaker on the platform. Paul Dessert's guide to getting noticed as an introvert though has me thinking I need to shake up this behaviour if I'm to push my career forward as a freelancer.

Here's his take on going to meetups:

Seriously, do it. I know what you're thinking, "screw that, why do I want to talk with a bunch of random strangers? Most people that go to those are greasy salespeople". Guess what, you're right. Most of them are filled with people handing out business cards. Ignore them. Find people that are interesting. They don't have to work in the same industry as you, in fact, I'd suggest seeking out people in industries other than your own. You spend most of your time at work or school associating with like minded people, step out of that bubble and understand the needs and pains of others.

Want to know the secret to a good conversation? Shut the fuck up. Plays right into our wheelhouse, right! People LOVE to talk about themselves. Let them. Just listen and learn. You'll make new friends and gain a potentially valuable contact you can lean on in the future.

The introverts guide to getting noticed by Paul Dessert

Junior squad out with @ElderslieGcPro working on their short game. Good turn out as well. #growingthegame

Sell to Yourself First

The thing is, that even with all the successful projects behind us, we’re typically bad at selling ourselves to ourselves. Like my friend above, who for years had been the lead developer at an agency yet he underestimated the actual value he brought to the table.

Your First Sale is to Yourself by Curtis McHale

Centireading

I can't say that I've read a book over 100 times, perhaps the closest to that count is A Christmas Carol which I've read over 20 times.

Centireading reveals a pleasure peculiar to text lurking underneath story and language and even understanding. Part of the attraction of centireading is that it provides the physical activity of reading without the mental acuity usually required.

Centireading force: why reading a book 100 times is a great idea by The Guardian (Stephen Marche)

Doing a number of spikes with the Ionic framework this morning. Like what I’ve seen so far just by getting up and running.

Kids & Technology

Last weekend our son came home with the school quarterly bulletin. As always we familiarised ourselves with everything that was coming up in the next few months, asked him what events he would like to go to and made sure there was nothing else that needed our attention. One last thing caught me wife's eye though as she read through the bulletin. The school are looking for volunteers to help re-vamp their school website.

The next day I phoned the school to let them know I would be willing to help out. I got a call back a few minutes later with a date and time to speak to the assistant head teacher at the school who will be handling the website. All good so far.

The school's website is okay as an information portal but it definitely falls short in terms of how it looks. Well, when the site says that the school kids contribute to the look and content of the site, you're not exactly going to be expecting something that wins web design awards. Looking at other web sites in the area, and it's clear that the school web site isn't a primary concern for some schools. There is more an emphasis on getting the school children involved and that's not a bad thing.

Today's school children though are far different in terms of technology exposure than school children have been in the past. In the last ten years, mobile technology has become so engrained in day to day life that homes often have two or more mobile devices with kids often having their own tablet or even smartphone.

It got me wondering about the approach to take in getting the school children involved in the new school website. Is it better for them to know how to edit and update web pages by hand or will the kids be more interested in maintaining the school website through something like Wordpress?

I might be jumping the gun here a bit, but I've been keeping a list of questions like this to ask at my meeting with the school this week.

The main good thing to come out of this though is the chance to do something for an organisation in my local community. Yes, I'll be doing the work for the school for free but with our oldest already a pupil there and our youngest due to start there in a few years, the chance to contribute something to their school can't be a bad thing.

Back on Twitter

I'm back on Twitter.

After weighing up the options, I'm probably better being an active member of at least one social network rather than none at all. Working for yourself is great, but the lack of office banter can make for very quiet days.

Fancy following me? I'm @matthewlang.

Never thought I would be proficient with Vim on a day to day basis. It’s taken a number of attempts but I finally got there.

3 Reasons for Sharing Content

I've been keeping this site going for a few years now, and while my main form of sharing content is through the RSS feed for this site, I do also share content through Buffer. It's ability to schedule posts for the networks I'm on is what made me sign up. I also use a separate domain for all my shortened links for each post and it starts to look a little more branded.

Why do we share our content in this way though? I can't speak for the mass collective of netizens, but here's why I share links through Buffer.

1. To Be Seen

People share their content in this way as a marketing tool, they want to be seen. And so do I. Being self-employed means that I need to keep my name out there.

While my recently published content doesn't strongly tie in with my freelance career, I do like to think that what I publish is valuable to others and may lead to new clients and contacts.

2. To Suit The Reader

Not everyone uses RSS to subscribe to content. For many, social networks are their first point of call when it comes to finding new content. This is the main reason why I share my content in this way. RSS is often seen as a more techie solution for subscribing to content which is why some people prefer to get their news from their preferred social network.

3. To Pay It Forward

Some things are just too good to keep to yourself and that's why I'm starting to share more links on Buffer. For the content that I find valuable and worth reading, I'm going to start sharing on Buffer. They might not make my blog in the form of a link post, but sharing these links in other places means that the original authors of the content get noticed.

That's the main reasons why I share the content that I do. Largely it's about having an active presence on the Internet and letting potential new clients and contacts know that, "I'm here!".

This is a personal site though and unsuitable for the kind of content that would get me noticed by new clients. For that I need a separate site with more focused content on Rails, Ruby and other web development topics. This is in the pipeline and I'm hoping to have something up and running by the summer.

Store Bought Bike or Online Bought Bike?

For the last month I've been pouring over mountain bike websites and magazines in the hope that I can pick up a decent bike at a reasonable price.

In the distant past this was a no-brainer. I would head to my local bike shop and ask about some recommendations. The advice was always balanced towards the models they had in the store or could order in. To be fair most local bike shops carry a fair range of mountain bikes, and if these were the only ones on offer then you can always find something that will suit your needs. Things are changing though with the introduction of Internet based bike companies. These small companies offer better specced bikes for less than the majority of bikes that are available in your local bike shop. They do this by selling directly to the customer, cutting out both the distributor and the local bike shop.

On-one have been a favourite of mine for a while. Their initial line of singlespeed steel hardtails were sold direct to customers from their website. Within a few months they were a success. Today they now carry a bigger range of bikes and frames for all different types of riders.

Bird are another mountain bike company that have recently surfaced using the same business model. With just one hardtail frame and full-suspension frame in their product line, they offer a number of build options for each frame according to the customer's budget.

Both of these companies aim to do one thing. Save money on the amount you pay for the bike by selling to you directly.

The business model is great for customers. They end up saving money on a similarly built bike offered in their local bike shop or they can get more bang for their buck by spending the same amount at the online retailer than they would at their local bike shop. Ask most people where they would probably buy their bike and I'm willing to bet that most would pick the online retailer. This is bad news for local bike shops though. Bikes are big ticket items, and if the trend towards buying from online retailers gains momentum, it would

I'm still on the fence about it. The Bird Zero is great value for money in terms of its specification. The other bike I'm considering, a Whyte 901, is distributed through bike stores and while it carries a higher price tag than the Bird Zero, it's not too far off my budget for a new bike. Both bikes match my preferred riding style, so there's no problem there. At this price level, £200 more for a bike isn't going to break the bank, but it does mean that I'm supporting a local bike shop. On the other hand, buying from an online retailer means saving a bit more money. I am swaying towards buying a store bought bike, but the decision isn't final yet.

Hosted Service or Custom Solution?

In the early days of the Internet, hosting your own website was reserved for those in the know, but over time it's become easy for anyone to build and host a website. With it though, comes that initial question. Do you use a hosted service or roll your own solution?

Over the years I tried lots of different hosted services. When I first started blogging a few years ago, I jumped from Tumblr to Posterous to Github Pages and then finally settled on Octopress. In recent weeks I've once again been assessing if Octopress is sufficient for my needs. It's got me thinking about the decision to use a hosted service like Wordpress or to use my own version of Octopress that has served me well over the last year.

The Hosted Service

The benefits of using a hosted service are immediately clear. Sign up and your done. As soon as that form is submitted you're ready to go. It's hard not to argue with this instant benefit. For most people this is the only way. Maybe they're not willing to delve into servers and software or perhaps it's a time issue.

For a smaller group of people though, they have the knowledge to roll their own solution, so what makes them chose a service?

I choose services based on a number of factors but mostly it's the benefit I can get from being able to use them on a day to day basis.

Services like Todoist and Trello take the pain out of my task and project management by allowing me to move between devices without having to synchronise data between them. There's a number of other minor benefits but the big benefits is accessibility.

I don't run my own servers as I know it would take up too much of my time to learn how to configure these correctly and ensure they are secure and running smoothly so I look towards services like Cloud 66 and Heroku to ensure my clients sites run without any major impact.

These are just a couple of examples of how hosted services are beneficial but there are drawbacks.

One of the big issues I have with hosted services is my ability to get my data in and out of that service. It's probably the one single feature of any hosted service that ultimately makea me sign up or not. As a hosted service I respect that my data must be located elsewhere for that service to be effective, but I must be able to import my data and extract it in a simple way. This is still a issue with some services, but it is getting better. Sadly though, the services themselves decide on the format of the data and with so many out there, getting them to all agree on the one format is never going to happen.

The Custom Solution

The benefit of a custom solution is just that. It's your own solution.

Hosted services offer a product or service pre-boxed and used by hundreds of people, but they can only be made to fit your needs to a certain point. What usually happens then is you have a service that fits your needs most of the time, just not all of the time.

This is where custom solutions excel. They are solutions tailored specificically to your own requirements. The drawback though is that such solutions need maintanance, and in my experience, a little more effort to ensure they run smoothly.

So what about my blog then? Well as nice as a hosted service would be, I do prefer to have that element of control over how it looks and what it does. Yes, I might have to jump through a few more hoops to publish content, but it gives me more control in that process. I think I'll be staying with the custom solution for the moment.