Tuesday, August 28, 2012

PL/SQL Challenge Update: Roundtable discussion on naming conventions

The second Roundtable discussion at the PL/SQL Challenge focuses on an issue that every developer grapples with: how to name our identifiers. That is, what are our naming conventions?

There have been many approaches to creating names, including CamelCase and Hungarian notation.

A longtime PL/SQL Challenge player, John Hall, offers a very different approach:

Identifiers can be considered a form of documentation, which raises the question, "What should an identifier's name document?"I propose this core principle: "Identifier names are based solely on the problem domain concept." No prefixes for scope. No suffixes for type.

In other words, while I would usually write a block of code like this:

DECLARE
   TYPE employees_t IS TABLE OF employees%ROWTYPE;
   l_employees   employees_t;
BEGIN
   SELECT *
     BULK COLLECT INTO l_employees
     FROM employees;
END;

John would, instead, do the following:

DECLARE
   TYPE employee_table IS TABLE OF employees%ROWTYPE;

   all_employees   employee_table;
BEGIN
   SELECT *
     BULK COLLECT INTO all_employees
     FROM employees;
END;

He's already got me thinking differently about how to write my code, though I am not yet ready to force my fingertips into drastically different patterns of typing.

I encourage you to visit the Roundtable, check out the discussion, and add your own thoughts.

No comments: