13 Jun 2016 Making of
Let's get started, using a pencil.
Trace it using a fineliner.
Getting rid of those pencil strokes.
Dream of the kind of worldBono, U2
you wanna live in.
Dream it out loud,
at high volume
Let's get started, using a pencil.
Trace it using a fineliner.
Getting rid of those pencil strokes.
Yep, we own a family car, a people mover for 8.
Backside of our house in 82 Sunshine Ave, Karori, Wellington, New Zealand.
I think it’s good practice to list up all the things you achieved in a year. It’s not really about telling others and brag about it. No, it’s more about telling yourself and calm down (impostor syndrome anyone?).
So let’s talk about 2014. We (my wife, our five boys and me) were living in Hamburg, Germany they whole year and I was working as a freelancing software developer most of the time. Besides that…
Ruby on Rails comes with its own set of assumptions and conventions (which is why it is called opinionated). We are not only aware of these, but we follow them in our everyday work. Recommended reading The Rails 3 Way, Obie Fernandez.
There are a couple of good styleguides around on GitHub and others. We know them, we use them and we highly recommend them. Even to the point to force ourselves by setting up these guides in our editors. For example Styleguide for Ruby.
We visit conferences and read books to know how the good guys write code. We listen to people telling us about not the better ways, but the best ways to achieve our goals. Every day.
It’s our codebase. We love it and we don’t want anyone destroying it. This is why we read any commit coming in. I mean literally, every commit.
If the issue to tackle is complicated, or we just want to talk to someone while writing code, we simple ask anyone to join us in doing the work. Call it 4-eye-principle, Wackeldackel or Rubberduck, it’s on our toolbelt, ready to be used when needed.
Technical debt is everywhere. Our means to tackle this pile of guilt is our refactoring board, which grows and shrinks, visible for each and everyone. No process needed. There is always time to change existing and running code. No broken windows allowed.
We have a number of ways to push our code to the repository. Sending pull requests is one of them. We ask others to take a look (or even ask ourselves one day later), before we let it go into the wild. Simple and effective, if needed.
There’s a plethora of chances to talk about our codebase. Stand-ups, coffee-times, ad-hoc discussions, lunchtime, and so on. Non-coders disrespectfully shake their heads on us talking so much about our work. We always talk about major code changes long before we implement them.
In order to avoid conflicts we tell others what we are working on. No surprises, and no major merge conflicts. And even if we are working in the same code area, we are able to handle any conflict showing up.
By working together every day, we know each others leanings, our strengths and weaknesses. So we know when we have to support each other on tackling complex problems and writing code. Even when someone tries something new and experiments around, we trust what they are doing, because we know they are doing right.
Whenever we write code, we take a look around, identifying and marking code smells. We utilize TODO, FIXME and QUESTION a lot, and find the time to decover these spots and remove them.
Even with all conventions, the codebase grows to a point where it is no longer maintainable. We sport modules, mixins, concerns, gems, plugins, packages. We know when to use inheritance and STI or composition. We do this to remain focused on our given business case.
A lot. All kinds of tests. Sometimes first and sometimes after we write the actual code. No bug without adding a test. No refactoring without a test. To write a test it to write code. We utilize test coverage, but 100% is not our goal. That’d be insane. There’s a kind of test for each usecase. We use the one most appropriate.
While writing tests is important, having a fast test suite is equally important. Slow tests won’t be run, it’s simple as that. That’s why we observe the trend on Jenkins (or Travis CI).
Every code change might have an impact. This is why we do log-jammin’. We do it regularly and a lot. Logjam is a great tool for that.
We not only keep our tools up-to-date, we keep the tiny bits of libraries and packages up-to-date as well. We not only update gems mentioned in the check-gem-versions build, we check for rarely used or development-only gems as well.
Monkey-patching is easy. And dangerous. This is why we have a natural tendency to return our code changes back to the original developers, in order to improve their code and let ours grow smoothly and independently. We pullup a lot.
Rails provides good means to organize the code. But that’s not sufficient. There are authorizers, utilities, external APIs, decorators and so on. And there’s a neat little place for all of them.
Back in Brighton, England for the dConstruct conference, after 2008 and 2010. If it wouldn’t be for the conference, visiting Brighton is worth all the time. Easy to get there (choose Gatwick Airport as your destination, and take the First Capital Connect train for 30 minutes), grab a bed in any hotel close to the beach and make your way around. It’s marvelous!
But the dConstruct conference is worth attending, too, and your time and money couldn’t be spent any more unrepentantly. I got repeatedly asked what the conference is all about, and to be honest, it’s not easy to answer. From what Clearleft and others state on its website itself, it is a collection (a smörgåsbord) “of clever clogs gathered together to twist our perceptions of technology and culture”. Yeah, that fits. It’s about technology for sure (lots of web developers and designers around), and it’s about culture as well, regarding all the Internet, but even more than that. It’s about how we see the world, what drives our motivation and inspiration. And anytime I get back home, I’m more focused and inspired than before. It’s about that, finding your place in the world around you.
It’s good to be back.
All I've got is a red guitar,taken from “All along the watchtower” by Bob Dylan
three chords, and the truth.
All I've got is a red guitar,
the rest is up to you.
Validate your fixtures.
As mentioned in our Ploppcasts session about Testing (German only, sorry) I'm using both fixtures and factories when testing my Rails applications. One of the drawbacks from using fixtures is that these don't have to be valid in terms of ActiveModel validations. In order to make sure my fixtures are in fact valid I introduced a fixtures test, which is simply a unit test to automatically verify the fixtures' validity:
So, taken these fixtures:
the test will indicate one failure, because the fixture user_without_email is invalid. The fixture invalid_user won't be marked as failure, because its name is starting with invalid_ telling the test that it should expect an invalid fixture, and return a failure otherwise. By this, we can keep having even invalid fixtures without failing tests.
Roughly a year ago a very good friend of mine, Benjamin Rabe, was organising an event for iPhone fingerpainters from all over the world. He invited them to come over to our shared office space and have a couple of drinks. I can't remember who came up with the idea, but we finally bought a bunch of paint tubes and asked the painters to try and somehow return to real painting, with real paint and a real canvas. And since all of them should do it together, the canvas simply had to be one of our office walls.
Over the next couple of hours, these guys really went into something, and so the painting on our wall grew and grew.
And it grew even further.
We really had good fun watching the work in progress. Everybody, even guests without prior painting experience, was giving it a try. Everybody was invited to fill the wall up and paint what they were feeling like.
Everybody was in a flow. Even when waiting outside, it was a nice and warm night, the people couldn't stop painting, this time using crayons, and they went on painting little pictures on the street.
After having painted for almost 5 hours, everybody was happy with the result and proud of being part of this happening. The final picture is about 5 meters wide and almost 3 meters high, and it does not fit in full size on the following image.
But feel invited to come over and take a look yourself! The painting is still there and will be around until we leave the office to the next residents. When coming back to the office the next morning, we were glad it haven't rained yet and the chalk paintings outside were still visible.
When taking a closer look at the big painting inside, I noticed a number of nifty details.
It was just a wonderful evening. Thanks to everyone who was taking part in this, and even more thanks to the guy who created this living and one-of-a-kind experience, Benjamin Rabe!
Adding a to_s method to a Ruby class helps with debugging.
I more and more tend to add to a Ruby class I want to test is a to_s method returning some sort of information about the underlying object.
So whenever I have to dig a little deeper and have to debug code that uses an instance of that class or I simply want to write some details to the logfile, I can use the returned string and thereby make sure all relevant information is printed.
Returning only a hard-coded string or name doesn't make any sense at all though. So, let's assume we have some sort of business object, for example a job doing some kind of work in the background. It has a certain state which we want to know about:
If you put this into an application which keeps the waiting user up-to-date with the current state of processing (as simulated below with a Ruby irb console), the user knows exactly what's going on.
There are more methods a Ruby class should have. Make sure to take a look at Robert Klemme's "The Complete Class" article. I don't think a class should contain all of the methods described there, but it's a good starting point.
Older Posts are to be found in the archives...