The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Naming Cursors

I'm always surprised how often cursors (PL/SQL term, basically views built into a program) are given the oh-so-meaningful names c1, c2, c3, etc...Uh guys, if you don't want the person taking over your code to curse your mother for having borne you, it would go a long, long way to give these things meaningfull names.

And, while I'm in my ranting block, ditch the abbreviations. Modern programming languages are no longer limited to 8 characters (my apologies if you are working with SAS), and the Eybishter has given us cut and paste. The few extra keystrokes will be very appreciated by those of us who follow.
Steve Hirsch Send private email
Thursday, December 08, 2005
My own preference has generally been to name cursors after the table or give some indication of what the cursor is about. And from what I can tell, a lot more people have wanted to hit me for using long_freaking_variable_or_parameter_names than for cryptically specifying lfvopns.

However, I would start to worry about more than names if I had a lot of cursors to manage in the same scope. Sure, nest one or two levels, but juggling cursors is a bit like juggling butcher knives--ugly when you get past your limit.

And might I put in a quick plug for Steven Feuerstein's _PL/SQL Best Practices_? I don't follow every last one, but I'm the better for having considered them.
George Jansen Send private email
Thursday, December 08, 2005
I'm not a God of SQL by any means, and my experience is probably only relevant to my litlle baby-steps corner of the language:

Surely the OP misses the point... cursor names don't matter, variable names do:

I find I'm only using one cursor at a time & it's boilerplate code. The cursor is declared just before it is used, destroyed immediately after, and referenced only at the start (init) and end (get next item) of the loop. So the cursor itself isn't at high risk of bugginess.

The important identifiers are actually the variables that the cursor loads up. The variables themselves _must_ be well-named because they can be referenced anywhere within the loop. That's where I write the bugs, anyways.

Friday, December 09, 2005
George said:
Surely the OP misses the point... cursor names don't matter, variable names do:

I think that the OP is hitting the point - cursors are a form of variable and should be given meaningful names just the same as any other variable should.
Jonathan Leffler Send private email
Saturday, December 10, 2005
The reason for giving cursors meaningful names is not to help with the debugging, per se, but to create some clarity in the text of the code. It's not a question of whether a short name would work, it's that it really helps the next person coming along to know what things are being operated on. My personal preference is to give the cursor a plural name; i.e.,

CURSOR studies IS
FROM ....;

and then give the row variable the form "next_xxx" where xxx is the singular name:

FOR next_study IN studies LOOP

Goes a long way, trust me.
Steve Hirsch Send private email
Sunday, December 11, 2005
And of course to make the cursor really readable, often it is best to make it implicit and not have a name at all.
Scot Send private email
Monday, December 12, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz