Exceptional Rails Handling

When I am writing a Rails application it starts out simple with a few if @something.save lines that are pretty self explanatory. Then the application grows and starts to become hairy. Take my contrived example with a grain of salt as I can’t show you production code that I am using. # app/controllers/widgets_controller.rb class WidgetsController < ApplicationController # # Other methods go here # def something # Maybe we handle the update in a special way widget = Widget.find(params[:id]) widget.some_method(params[:widget]) # for the sake of simplicity let's change the owner foobar = widget.foobar foobar.owner = current_user respond_to do |format| if widget.save if foobar.save format.html { redirect_to widgets_path, :notice => 'Huzzah!' } else widget.some_special_rollback format.html { redirect_to widgets_path, :notice => "You're a moron" } end else format.html { redirect_to widgets_path, :notice => "Not even close"} end end end end What did we learn here? Terribly contrived examples can prove anything, No! Though I liked how easy it was to come up with it but that is not why I wrote the code above. I have seen applications get to that point and when I see it now I start to shake my fist violently at the computer and wonder just what in the world were they thinking. ...

March 25, 2012

Effective Programming

I’ve been programming for the last 6 years and I have a bunch of programming languages under my belt. But just because I know other languages doesn’t make me a desireable programmer. Any decent programmer can pick up a new language within a few weeks and pick up the new programming paradigms after. What makes me desireable is how effective I am when I program. You need to be effective else you risk being left behind ...

January 14, 2012