Aug 26

Sometimes More is Just Enough

In the quest for simplicity and maintainability, sometimes we need to add components.  It seems counter intuitive, perhaps, but sometimes it’s true.

As an example, I once came across a project which had multiple queries, each of which contained over 40 lines of SQL code.  I don’t know about you, but 40 lines of code for a single query smacks of being overly complex. The query was too long for the database to optimize and far too long for humans to maintain, let alone understand.

In this case, to “simplify”, the queries were perfect candidates for database views and stored procedures.  Thus, by adding components to the architecture, we’ve actually made it simpler and easier to maintain.

Aug 26

Why my code is broken….. (break my code redux)

Yesterday, I posted an article entitled Break my code, please, wherein I posted a very fragile piece of code, with the challenge to find ways in which to break it.

What follows is a discussion of the code and why it is bad/fragile/easily broken…..

Read the rest of this entry »

Aug 25

Rails Project Setup Script

I got tired of typing the same commands all the time and/or looking up urls for plugins.  Hence this script….  Yes, I know it’s been done before, but this does what I want (for now; I’m sure I’ll edit it).

It does the following:

  • Creates rails instance (optionally setting the database, etc.)
  • Installs rspec & rspec-rails
  • Installs acts_as_statemachine
  • Installs restful_authentication
  • Modifies routes.rb
  • Adds an observer
  • Adds email settings

You can see the script below the cut or download it here:start-rails

(Edit: Removed an un-escaped pair of parens)

Read the rest of this entry »

Aug 25

Testing Scribefire

I’m testing scribefire to see how well it works…. Nothing to see here, move along.

Aug 25

Ruby Corner Feed

I’m not sure why, but the Ruby Corner is always picking up on my next-to-last post.  Weird.  I wonder if it’s something I’m not doing properly or what……

Aug 25

Break my code, please

There’s a number of things we can should take into account when writing code — boundary cases, etc., that can make or break a programme.  Yes, testing is important, but I think that developing good defensive programming practices is even more important.  That said; I present the following, fragile, code.  Just about every line has a case where it can fail.  Can you break my code?  I’ll post some test cases which cause it to fail later.

And for those looking for the next installment of O_RLY?, it’s coming soon; I’ve been embroiled in a hideous move.

Read the rest of this entry »

Aug 22

Ruby’s ObjectSpace: Subclasses

One of the (imho) lesser used pieces of the Ruby language is ObjectSpace.  In this article I’ll show one of the things you can do with it — get all the subclasses of a class.
Read the rest of this entry »

Aug 20

Oooh Shiny! Magpies don’t know what’s just enough!

I’ve done it.  I’ve been guilty of ooh shiny development.  You know, those projects where you use the latest and greatest library, tool, or infrastructure not because it’s the best thing to do but because it’s the cool thing to do. Read the rest of this entry »

Aug 19

rspec, restful_authentication, and login_required

This is partly for myself, and partly for anyone after me…..

I have a controller generated via rspec_scaffold — yes, I know, it might not be what all the cool kids are doing, but it works.  I also have restful_authentication set up to use rspec.  So, when I go to add before_filter :login_required, autotest frowns at me.  After much trial and error, and googling (with false hits and things that didn’t work), I finally achieved a smiley face with the following added to my controller’s spec:

Aug 19

autotest reminder (or why did it go boom?)

autotest / zentest are really useful tools.  However, it’s important to remember to run migrations for the test database — otherwise your tests will fail (miserably!)

I’ve found the following to be helpful for using autotest:

Older posts «

» Newer posts