Skip to content

improve code readability #3446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

cxljs
Copy link
Contributor

@cxljs cxljs commented Jul 25, 2025

  • replace two similar functions appendUniqueNode and appendIfNotExists with a generic function.

  • simplify the implementation of the get method in clusterNodes

  • minimize line breaks in function definitions.

  • keep the member name _generation of clusterNodes consistent with other types.

  • rename a data member _masterAddr to masterAddr.

- replace two similar functions `appendUniqueNode` and `appendIfNotExists` with a generic function.

- simplify the implementation of the `get` method in `clusterNodes`

- minimize line breaks in function definitions.

- keep the member name `_generation` of `clusterNodes` consistent with other types.

Signed-off-by: Xiaolong Chen <[email protected]>
@ndyakov
Copy link
Member

ndyakov commented Jul 25, 2025

Hey @cxljs, thanks for your contribution.
Do you have a specific reason to prefer less linebrakes. I do think, sometimes multiline function declaration is better for readibility?
Those function declarations and the generic function for append are the only one that I am not so happy about including, but I see the benefit of having that generic...

@cxljs
Copy link
Contributor Author

cxljs commented Jul 25, 2025

Hello @ndyakov , the reason for reducing line breaks is that there will be a comma after the last parameter, which often makes me think there are more parameters on the next line. e.g.:

func masterReplicaDialer(
	failover *sentinelFailover,
) func(ctx context.Context, network, addr string) (net.Conn, error) {

But this is just my personal opinion, if you think multiline function declaration is better for readibility, let's keep it as it is.

@ndyakov
Copy link
Member

ndyakov commented Jul 25, 2025

I do have a preference, but I am not the only person working on this :) @htemelski-redis , @ofekshenawa feel free to share your opinions.

@cxljs
Copy link
Contributor Author

cxljs commented Jul 26, 2025

Oh, I missed this question yesterday - why don't you like the change to generic functions? My thought was that it could reduce one similar function definition and make the code cleaner. What's your perspective? There might be something I haven't considered, and your viewpoint would be really helpful to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants