28 August 2012

Roundtable Discussion: Identifier Naming Conventions

Our second Roundtable discussion 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.

2 comments:

  1. Hi Steven,

    I completely missed this but just had a quick read through the discussion.

    I'm curious if you've reconsidered retraining your finger tips yet... Any changes coming to you best practice recommendations or to your Naming Conventions and Coding Standards document?

    Regards,
    Dan

    ReplyDelete
  2. Haven't made any decisions on this yet.

    I think John's ideas make a lot of sense, but going from there to changing deep habits....tough!

    ReplyDelete