-
Notifications
You must be signed in to change notification settings - Fork 113
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
Refactor utility functions related to pointers #1710
base: main
Are you sure you want to change the base?
Conversation
@@ -85,7 +85,7 @@ func (f *admissionControllerFeature) ID() feature.IDType { | |||
return feature.AdmissionControllerIDType | |||
} | |||
func shouldEnablesidecarInjection(sidecarInjectionConf *v2alpha1.AgentSidecarInjectionConfig) bool { | |||
if sidecarInjectionConf != nil && sidecarInjectionConf.Enabled != nil && apiutils.BoolValue(sidecarInjectionConf.Enabled) { | |||
if sidecarInjectionConf != nil && sidecarInjectionConf.Enabled != nil && apiutils.NewDeref(sidecarInjectionConf.Enabled, false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Code Quality Violation
Condition could be directly returned (...read more)
In Go, it is considered unnecessary and less readable to write a conditional statement that returns true
or false
explicitly based on a condition. Instead, it is recommended to directly return the condition itself. Here's why:
- Code simplicity and readability: Writing
return condition
directly conveys the intent of the code more clearly and reduces unnecessary verbosity. It is easier for other developers to understand your code at a glance without having to analyze additional conditional statements. - Avoidance of redundancy: Explicitly returning
true
orfalse
based on a condition introduces redundancy in the code. Since the condition itself already evaluates to a boolean value (true
orfalse
), there is no need to include additionalreturn true
orreturn false
statements. - Maintainability and refactoring: The direct
return condition
approach is more maintainable and flexible for future code changes. If the condition or the desired return value changes, it is easier to modify a single line rather than multiple lines of code. This minimizes the chances of introducing errors or inconsistencies during refactoring.
Therefore, it is recommended to simply use return condition
instead of if condition { return true } return false
. By doing so, you improve code readability, reduce redundancy, and ensure better maintainability of your Go code.
} | ||
|
||
// SingleStepInstrumentation requires APM Enabled | ||
if apmConf.SingleStepInstrumentation != nil && apiutils.BoolValue(apmConf.SingleStepInstrumentation.Enabled) { | ||
if apmConf.SingleStepInstrumentation != nil && apiutils.NewDeref(apmConf.SingleStepInstrumentation.Enabled, false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Code Quality Violation
Condition could be directly returned (...read more)
In Go, it is considered unnecessary and less readable to write a conditional statement that returns true
or false
explicitly based on a condition. Instead, it is recommended to directly return the condition itself. Here's why:
- Code simplicity and readability: Writing
return condition
directly conveys the intent of the code more clearly and reduces unnecessary verbosity. It is easier for other developers to understand your code at a glance without having to analyze additional conditional statements. - Avoidance of redundancy: Explicitly returning
true
orfalse
based on a condition introduces redundancy in the code. Since the condition itself already evaluates to a boolean value (true
orfalse
), there is no need to include additionalreturn true
orreturn false
statements. - Maintainability and refactoring: The direct
return condition
approach is more maintainable and flexible for future code changes. If the condition or the desired return value changes, it is easier to modify a single line rather than multiple lines of code. This minimizes the chances of introducing errors or inconsistencies during refactoring.
Therefore, it is recommended to simply use return condition
instead of if condition { return true } return false
. By doing so, you improve code readability, reduce redundancy, and ensure better maintainability of your Go code.
What does this PR do?
Most of the pointer-related utility functions have been deprecated due to the introduction of generics. In this PR, I've refactored the code and removed most of them.
Motivation
Cleaning up the codebase.
Additional Notes
N/A
Minimum Agent Versions
N/A
Describe your test plan
N/A
Checklist
bug
,enhancement
,refactoring
,documentation
,tooling
, and/ordependencies
qa/skip-qa
label