- 필수 기능
- 시작하기
- 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:
:=
to define a new variable within the function body. This shadows the original 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.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")
}