Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Anyone with enough experience in C derived languages large scale preprocessor spaghetti, welcomes _buildtag.extension alternative.

This is actually one of the few things I fully agree with Go designers.



Is the file foo_bar.go (no build tag line) compiled or not?

If your Go version doesn't know of such a build tag as "bar", then foo_bar.go is unconditionally compiled. If Go in a later version adds "bar" as a known build tag, then foo_bar.go becomes conditionally compiled. Better hope you know this is how things work (reality: lots of Go devs don't).

Build tag lines don't have this problem. They always specify compilation conditions, even if the build tag is not already known to the compiler. They also apply to the whole file, the same as _tag in the name; there's no preprocessor spaghetti possible.


I guarantee you it is even worse with preprocessor spaghetti, than build tools.


I think we're talking past each other.

Build constraints with "//go:build" already exist, I'm not making them up or proposing something new: https://pkg.go.dev/go/build#hdr-Build_Constraints

This has nothing to do with preprocessor spaghetti, which is impossible in Go. Either a file is included or it is excluded. Neither with file naming nor "//go:build" can you cause only portions of a file to be compiled.

Really, the _tag.go mechanism is just a very simple kind of build constraint, equivalent to "//go:build tag". The problem is that it relies on a magic list of known build tags, and the contents of that list change over time. Apart from _test.go, which is a little too convenient to give up in my opinion, the rest of the tags could be pushed into build constraints, or at the very least, the list of known build tags could be frozen in its current state.


Build contraints are the version of Go's preprocessor spaghetti, when those conditions get so complex, that one needs pen and paper to understand what is actually included.


Well, then it ought to go the other way. If you create foo_bar.go and bar is not a known build tag, you should get a compiler error.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: