> On Aug 21, 2025, at 09:10, Peter Smith <smithpb2...@gmail.com> wrote: > > I feel that having redundant assignments can be misleading because > someone reading the code might think the initial value matters or has > some significance, when it does not. > > ~~~ > > Here's another example, in the same function: > ---------- > PublicationRelInfo *newpubrel; > Oid newrelid; > Bitmapset *newcolumns = NULL; > ---------- > > None of those initial values above is needed because these variables > are all immediately/unconditionally reassigned. So, why is 'newpubrel' > not assigned up-front, but 'newcolumns' is assigned? IMO this implies > that the 'newcolumns' initial value has some meaning (which it > doesn't), so it just introduces unnecessary doubts for the reader... >
For “newcolumns”, the initialization can be removed, because it’s immediately and explicitly assigned: newcolumns = pub_collist_validate(newpubrel->relation, newpubrel->columns); However, for “isnull”, it doesn’t get explicitly assigned, it depends on the subsequent function to set a value to it. If the subsequent function gets a bug with not assigning it, it would lead to unpredictable results. With an explicit assignment, even if there is a bug of not assigning “isnull" in the subsequent function, the bug will lead to a consistent result. So, I think it’s a good practice to always initiate a value before passing its pointer to a function. -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/