On 29/01/2024 19:07, Robert Haas wrote:
On Mon, Jan 29, 2024 at 10:03 AM Jelte Fennema-Nio <postg...@jeltef.nl> wrote:
I feel like this is the type of change where there's not much
discussion to be had. And the only way to resolve it is to use some
voting to gauge community opinion.
So my suggestion is for people to respond with -1, -0.5, +-0, +0.5, or
+1 to indicate support against/for the change.
I'll start: +1
-1. I occasionally run into situations where I'm like "ah, it would be
nicer to declare this in the middle of the block". But for every 1
time that happens, there are probably 10 times where it's helpful to
me to be able to look at the top of the block and see all of the
variable declarations in one place. Plus, a lot of times, this urge to
declare mid-block is a sign that I've made that block too big and
complex and I need to refactor and simplify.
-0.5 from me, for exactly those reasons Robert said. I wouldn't mind
removing the compiler flag as long as we mostly keep the current style
of declarations at top, with exceptions when it really makes sense. But
in practice it would open the floodgates and make things worse overall.
You can also add curly braces to introduce a block like this:
do_stuff();
{
int i = 123;
do_more_stuff(i);
...
}
I know many people dislike that too, though. I think it's usually better
than declaring a variable in the middle of a block, because it also
makes you think how long the variable needs to be in scope.
The main argument I see for changing anything is that we do a lot of
things on this project that many people consider old-fashioned, and it
may discourage some younger developers from getting involved in the
project. I doubt that this is anywhere close to the biggest problem we
have in that area, but if we do end up changing it I'll console myself
with the thought that maybe we're usefully modernizing something.
People writing extensions or hacking on their own forks of PostgreSQL
are free to do whatever they like. And I don't mind reviewing patches
that don't follow the usual guidelines to the letter, stylistic things
like this are easy to fix before committing. I don't feel like we're
forcing these rules upon others.
--
Heikki Linnakangas
Neon (https://neon.tech)