-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
spec: add __FILE__ and __LINE__ macro #12876
Comments
Go doesn't have anything like this before, so I'd hesitate Also FILE and LINE look quite ugly in Go. The reference you cited is a few years old, and I'm wondering |
I can see the use for access to what are constants known to the compiler, and it's not entirely unprecedented in Go: The predeclared constant iota exposes such a mechanism (it counts semicolons inside a const declaration, not unlike But I think introducing more such predeclared constants is not the right path. For one, We do have other means to handle such things in a more Go-like way. I can think of 2:
Such a mechanism would be easily extensible. It would mean that we extend the language by this additional builtin.
Something to think about. |
I (now) agree that It's hard for me to picture how these would be used. Not many people write out So I would like to see a real example of how these would be used before we even consider adding them. |
@ianlancetaylor logrus have multiple logging code path and unstable internal API. Hardcoded stack depth are prone to bitrot. I agree compiler magics are hard to use, but they are hard to break too. |
Without going through the long issue, could you please give |
It occurs to me that you can actually write these yourself very easily as functions.
Now for I'm going to close this. |
Here is an implementation of it. Go master (1.7): For gccgo (6.1): |
The current
Caller()
method is more flexible, but it encourage hardcoded stack depth constant (see https://golang.org/src/log/log.go#173 ). This is easy to bitrot.Constant (or marco) like
__FILE__
push the responsibility to the caller. Maybe a little bit hard to use, but it is simpler to maintain.Reference: https://groups.google.com/d/msg/golang-nuts/3_UFKPKIzRU/HKCC8KqOhQYJ
The text was updated successfully, but these errors were encountered: