- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: go-best-practices/invalid-seek-value
Language: Go
Severity: Info
Category: Best Practices
In Go, it is recommended to pass the arguments to a function in the correct order, according to the function signature. This helps improve code readability, maintainability, and reduces the chances of errors.
The reason why we should avoid myValue.Seek(io.SeekStart, 0)
and use myValue.Seek(0, io.SeekStart)
instead is to follow the convention of passing the offset (or other numerical parameter) before the whence parameter.
The Seek
function in Go’s io
package takes two parameters: offset
and whence
. The offset
parameter represents the distance from the reference point, and the whence
parameter represents the reference point itself.
By following the convention of passing the offset before the whence parameter, the code becomes more consistent with Go’s standard library and promotes uniformity across different codebases.
This convention aligns with how other functions in the standard library, as well as commonly used idioms in Go, work. For instance, in the Seek
function’s counterpart, the Read
function, the offset is passed before the buffer parameter: Read(buffer []byte, offset int64)
By using myValue.Seek(0, io.SeekStart)
and myValue.Seek(10, myio.SeekCurrent)
, it better conveys the intention of the code and makes it easier for developers to understand the purpose of each parameter.
To summarize, it is good coding practice to pass function arguments in the correct order, according to the function signature and established conventions. In this case, it means passing the offset before the whence parameter, as in myValue.Seek(0, io.SeekStart)
and myValue.Seek(10, myio.SeekCurrent)
.
func main () {
myValue.Seek(io.SeekStart, 0)
myValue.Seek(myio.SeekCurrent, 10)
}
func main () {
myValue.Seek(0, io.SeekStart)
myValue.Seek(10, myio.SeekCurrent)
}