- Recent
- Popular
- Tags (0)
- Subscribers (1)
- The curious case of beauty in Ruby (or Rails vs Merb part 2)December 26 2008
-
I’m sure you’ve all heard the Rails 3 announcement. When I first found out my initial reaction was “fuck me“. But shortly after I was filled with a feeling of dread and general unease. And I didn’t know why ….
Firstly, a bit of history.
I first tried programming on a Commodore Vic 20, and then after that a C64. C64 BASIC was very simple - if you wanted to do anything beyond PRINT statements you needed to POKE values into registers and control the hardware directly. Great for learning how things actually worked. And, to be fair, I was shit at it.
But I do remember reading an article on a system called “Smalltalk” and its “Object Oriented Programming”. Suddenly, programming made sense. It read a bit like English. You sent messages to the thing that knows how to answer your question. It was like talking to people. You ask Dave a football question. You ask George a music question. Cos Dave knows crap all about music and George knows nothing about football.
But, in those days, Smalltalk cost a fortune; there was no way a child like me could get hold of a Smalltalk environment. So instead, I got hold of Turbo Pascal 6 With Obj
- Writing tests for your controllers improves the design of your modelsDecember 20 2008
-
I’ve recently been updating some old code - partly written by someone else, partly written by myself. At the time, I thought I had written this code really well; looking back on it now, it looks awful. Fair enough, I’ve learnt a lot - I want to look back on old code and shudder. But also, there is very poor test coverage on this app and the tests that there are are quite unwieldy due to an over-reliance on fixtures.
So I’ve been reworking them all using RSpec, my fork of RSpec-Rails and my Object Factory (which means I can avoid fixtures).
Most of the work involves writing a spec that mimics the current behaviour (by inspecting the code and trying to match all paths through it), then refactoring the code, using the spec to prove that I haven’t broken it.
But some points have some really horrible code (and lots of it) within the controllers. As you probably know, Skinny Controllers is the Rails way - your application logic belongs in your models (as they are your application) - the controller should just find or create the relevant model, ask it to do something and then render the results.
Because of this, I opted to just rewrite the actions in question.
To do this I started by writin
- Think VisibilityDecember 20 2008
-
The irrepresible Dominic Hodgson is organising his very own conference in March 2009.
It’s all about SEO, marketing and those dirty things us coders try not to get involved with
Of course, I will be there. So why not give Think Visibility a go? You may just learn something.
- Coping with the VAT ChangeNovember 25 2008
-
There seems to be a lot of wailing and gnashing of teeth about the upcoming VAT change. Especially as it is only a 13 month change and the rate will revert to 17.5% in 2010.
However, it ought to be really simple (although I realise that this may be a bit late for some computer systems).
Never hard-code the VAT rate
Have a Tax class that the rest of the system can ask when it needs the tax rate. That way, you’ve only got one place to make the change.
Store the rate against your invoice lines
Add a field to your invoice lines that stores the rate applicable for that line. Populate this when the line is created. That way, an invoice at tax point 30th November 2008 will have lines with a 17.5% stored against them, those created on the 1st December 2008 will have a 15% stored against them. This keeps your most vital financial documents accurate over time.
Calculate the VAT as late as possible
When calculating the VAT on an invoice do not do this:
value_excluding_vat = 0 vat = 0 value_including_vat = 0 for each line in my invoice value_excluding_vat += line.value vat += line.value * line.tax_rate value_including_vat += line.value + (line.value * line.tax_rate)The problem here is that you are calculating the VAT on a per line basis and then summing the values. This will lead to rounding errors - where your line values are a penny out from your totals.
Instead you need to place
- Acceptance Testing in Ruby, Rails, RSpec and CucumberNovember 21 2008
-
I’ve written up a new post at the Brightbox blog detailing how we are using RSpec and Cucumber to build acceptance tests for the next generation Brightbox systems.
