Avoid Chained Calls Directly in Function Calls
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
I would like to suggest an improvement regarding the current usage of chained calls within TiDB. Currently, we have instances where chained calls are directly used within function calls. This practice causes inconvenience, especially when debugging, as it forces us to step into each of these chained calls, making the process cumbersome.
To enhance our debugging experience and code maintainability, I propose that we avoid using chained calls directly within function calls. Instead, we should break them down into intermediate variables or steps before passing them to the function. This approach would not only simplify debugging but also improve code readability.
Here is an example to illustrate the suggested change:
```
// the candidate predicate should be a constant and compare predicate
match := validCompareConstantPredicate(selection.SCtx().GetExprCtx().GetEvalCtx(), candidatePredicate)
if match {
result = append(result, candidatePredicate)
}
```
Proposed Change:
```
// the candidate predicate should be a constant and compare predicate
ctx := selection.SCtx().GetExprCtx().GetEvalCtx()
match := validCompareConstantPredicate(ctx, candidatePredicate)
if match {
result = append(result, candidatePredicate)
}
```
By adopting this approach, we can set breakpoints at each intermediate step and inspect the values more easily without stepping into each chained call unintentionally.
I believe this improvement will significantly streamline our debugging process and enhance overall code quality. Your consideration and feedback on this suggestion would be greatly appreciated.
Contributor guide
Assessment
This issue has not been assessed yet.