Programming Tip

This is probably so ludicrously obvious that it goes without saying but, in my experience, it really needs to be said:

When building your architecture, you should design it so that things you do every day are easy.

For example, if you have an often-used object, don’t split it into two halves and require that you join on them. There are lots of arguments for not having a 50-column table, and there was a clear distinction between the public side of a user and the private site of a user, but splitting one simple concept in half has caused lots and lots of pain. If it’s a core “thing” on your site, make it easy to manipulate. For example, the question, “How many users signed up today?” should not require joining two tables, nor should finding out whether a user on the site is active or not.

When complexity doesn’t come under the guise of optimization, it sometimes creeps in as permitting new capabilities. On another product we moved the “email” column out and created an Email object, allowing users to have multiple emails. In more than a year’s time, nothing has ever been done to actually assign additional emails. All it means is that instead of User.find_by_email(‘abc@example.com’), I need to do Email.find_by_email(‘abc@example.com).user.

And here’s what got me annoyed enough to start this post: you shouldn’t need lots of conditions to show your base case of things. Right now I’m working on a bit of code to pull back all the posts on the blogs. It seems I need to check a whole bunch of columns: WHERE post_status=’publish’ AND post_password IS NULL OR post_password = ” AND post_date < NOW()

Sorry, but that’s dumb. Sure, you can bundle it away and give a nice simple method that does all that stuff for you, but hiding insane designs behind simple methods doesn’t actually fix them. It all comes down to the premise I began with:

When building your architecture, you should design it so that things you do every day are easy.

Displaying all the posts on a blog is a thing you do every day. So is getting the number of members who signed up today. So is looking up a user by email. So don’t make them hard.

Leave a Reply

Your email address will not be published. Required fields are marked *