Re: Minor code de-duplication in fe-connect.c - Mailing list pgsql-hackers

From Daniel Gustafsson
Subject Re: Minor code de-duplication in fe-connect.c
Date
Msg-id BF683DB4-96FB-48CE-AA58-EC76CDE03445@yesql.se
Whole thread Raw
In response to Minor code de-duplication in fe-connect.c  (Gurjeet Singh <gurjeet@singh.im>)
Responses Re: Minor code de-duplication in fe-connect.c
List pgsql-hackers
> On 21 Apr 2023, at 07:29, Gurjeet Singh <gurjeet@singh.im> wrote:
>
> Commit [1] implements Fisher-Yates shuffling algorithm to shuffle
> connection addresses, in two places.
>
> The attached patch moves the duplicated code to a function, and calls
> it in those 2 places.

The reason I left it like this when reviewing and committing is that I think it
makes for more readable code.  The amount of lines saved is pretty small, and
"shuffle" isn't an exact term so by reading the code it isn't immediate clear
what such a function would do.  By having the shuffle algorithm where it's used
it's clear what the code does and what the outcome is.  If others disagree I
can go ahead and refactor of course, but I personally would not deem it a net
win in code quality.

--
Daniel Gustafsson




pgsql-hackers by date:

Previous
From: Anton Voloshin
Date:
Subject: Re: duplicate function declaration in multirangetypes_selfuncs.c
Next
From: Robert Haas
Date:
Subject: Re: Non-superuser subscription owners