- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: go-best-practices/modify-parameter
Language: Go
Severity: Info
Category: Best Practices
Assigning new values to function parameters exhibits several bad coding practices and should be avoided for several reasons:
param
parameter within the function body by assigning a new value 41
to it. This is considered a bad practice because it can lead to confusion and make the code harder to understand. Modifying a function parameter in this manner breaks the expected behavior and can cause unexpected side effects. It is generally best to treat function parameters as read-only values and avoid reassigning them.:=
to define a new variable param
within the function body. This shadows the original param
parameter, making it inaccessible within the function. Shadowing variables can cause confusion and make the code harder to reason about. It is better to use distinct variable names to maintain clarity and avoid any unintended side effects.a
using both the increment (++
) and decrement (--
) operators, but it is unclear what a
refers to. This inconsistency can cause confusion and make the code more error-prone. It is important to use clear and consistent variable naming conventions to improve code readability and maintainability.To write more maintainable and understandable code, it is advisable to adhere to the following practices:
By following these best practices, the code becomes more readable and easier to manage and avoids introducing unnecessary complexity and confusion.
func myfunction1(param int) {
param, b := 1, 2
param = 41
param := 51
param++
param--
}
func myfunction42(param int) {
param, b = 1, 2
}
func (r *Type) myfunction2(param int) {
param, b := 1, 2
param = 41
param := 51
param++
param--
}
func foobar(_ int) {
_ := plop()
}
func (r *Type) myfunction1(ctx context.Context) {
span, ctx := tracer.StartSpanFromContext(ctx, "myfunction")
}
func myfunction2(ctx context.Context) {
span, ctx := tracer.StartSpanFromContext(ctx, "myfunction")
}