An example of complicated code

I’m in the middle of a contact management app as a project for learning how to develop in rails.  I plan to launch it soon, but lately have been lacking the motivation to tackle new feature ideas.

Fast-forward to today and I’m going over some code and just seeing how my thought patterns were towards finding solutions a few weeks ago.  Wow.

Overcomplicate much, Steve?

So here’s a “bit” of code that I used to keep track of a task when it was rescheduled.  Basically you click on a little calendar icon, you can reschedule a task to another day.

I have headers that organize the tasks so that you can see what’s due today, tomorrow, etc.

I wanted to be able to remove a task from one header, and replace it in another.  Oh!  What if it was the last task in that header?  You have to condition for that too!  Wait; how would I do that?  This is how I used to do it.

It works.  It’s ugly.

This is how I refactored it today.  *facepalm*  76 to around 8 lines of code.  Seriously?!

Yea, there’s some neat little UI stuff taken out like the slideUp of the header element.  I decided, however, that that’s really not that important and was seriously making my code look like crap.

What if I decided later to change the structure of the view?  I’m screwed!  I relied so heavily on CSS selectors to pick the right header to remove.

Leave a Comment