Tuesday, December 27, 2011

So I spent a couple of hours digging around in Visual BASIC code today. We're moving this code from one server to another. The .NET version changed. And the database delete functionality stopped working. Insert and update work fine. Only the delete part broke. It's frustrating.

The code uses something called a Business Facade with LINQ for database access. I personally find it very confusing. LINQ abstracts away the database access. In my mind, LINQ just adds another translation layer between me and the goal. My coworker probably feels the same way about Catalyst with DBIC. So honestly, what's the difference?

Abstraction vs. Simplicity

We use abstractions all of the time in real life. Calendars abstract the march of time so that we can see the interactions. We write checks instead of mailing cash. You look at a gas gauge instead of the fluid level right in the tank. Abstractions make our lives simpler. They stand in for messy details.

Catalyst does that. It hides the mundane intricacies of web connections. No matter how many web applications you write, parsing the URL happens the same way every time. There is only one right way of parsing CGI. And every application does it the same way. Why rewrite that code over and over and over? Catalyst does it once.

DBIC works in similar fashion for database queries...
  • Make the connection
  • Generate the SQL
  • Join related tables
  • And convert it all into Perl data structures
Abstractions help you write working code faster. My Catalyst applications are more documentation than code. And that's a good thing. So what happens when the abstraction breaks? This is the situation we find at work - the abstraction broke. My co-worker finally figured out that the web class calls into Business Facade which calls down into another class that executes a stored procedure that runs a DELETE statement. Yeah - all of that work for something as simple as deleting a record.

An abstraction should simplify details, not hide them. When the abstraction breaks, you can figure out what's happening.

Good Managers Delegate

Delegation happens every day. Your boss's boss asks your boss for something. Your boss then gives you responsibility for getting it done. You do a spectacular job, hand the result to your boss, who then gives it their boss. This occurs across your entire team. So when the manager delegates work to 8 people, that means he received the work for 8 people. What would you do if someone dropped the work of 8 people in your lap? One person doesn't accomplish the same as 8.

Delegation lies at the heart of automation. We delegate work to machines. Machines handle repetitive tasks with aplomb. Humans find them boring. Seriously, I would go bonkers typing in all of our data by hand. The computer doesn't blink an eye when it loads that same data. I delegated my work to the computer and accomplished more by doing so.

Web frameworks are about delegation - not abstraction. A good framework delegates the mundane, repetitive details using a library of proven code. Catalyst delegates the URL parsing to some block of code I have never seen - and don't need to. DBIC delegates table joins to some block of code I have never seen - and don't need to.

Catalyst and DBIC don't hide the details. They tie directly with the lower level details, if you need those capabilities. Both frameworks handle the details by default - helping you the programmer - like a good assistant. Does your framework help?

No comments:

Post a Comment