From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, Dan Ports <drkp(at)csail(dot)mit(dot)edu>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Coding style point: "const" in function parameter declarations |
Date: | 2011-06-22 16:41:10 |
Message-ID: | 2487.1308760870@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
> On Tue, Jun 21, 2011 at 5:51 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Declarations like "const structtype *param" are fine, because those
>> create a real, enforced contract on what the function can do to data
>> that is visible to its caller. But I don't see any value at all in
>> const-ifying the parameter itself.
> What about making a separate typedef for that (like ConstRelation)?
Well, any change along this line would require pretty widespread
changes, as you'd have to const-ify from the bottom up, or else hold
your nose and cast-away-const in assorted calls (which I think is so
evil you might as well not have the const in the first place).
If we were thinking of moving in that direction, I would argue that
we should get rid of typedef'd pointers altogether, ie, change
"Relation" to be a typedef for the struct and write "Relation *rel"
not "Relation rel". Then, attaching a const to the front is easy,
natural, and does what the naive reader would expect. But this would
be a sufficiently sweeping change that I'm not sure the benefits
would be worth the cost.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2011-06-22 16:51:18 | Re: [v9.2] DROP Reworks Part.0 - 'missing_ok' support of get_object_address |
Previous Message | Kevin Grittner | 2011-06-22 16:26:42 | Re: Repeated PredicateLockRelation calls during seqscan |