by isaiahg · 5y ago · 0 comments
However I think the coolest part of the language is the part no one talks about. The inclusion of comments as a major part of a program.
// +linux
for managing files for specific platforms is just wonderful.
//go:embed
for embedding files and directories into your program
// #include <stdlib.h> import "C"
is probably the coolest and easiest ways to use C libraries I've seen. You can write C code directly into your go files and even set complier and linker flags.
//go:generate
can allow you to automate your build process from within your codebase.
Also Go: because we shoved them all into comments instead!
This seems like an extremely weird choice.
No doubt sophisticated IDEs highlight them somehow, but more naive editor extensions e.g. Emacs 'go-mode', do not. No color-coding.
Disagree. It's more like the opposite is mostly true:
By convention comments are not meant to be ignored, but the truth is they mostly are, by the average programmer. And most programmers are average, by definition of the word 'average' and by the bell curve law. Yes, with exceptions.
Even if comments are not ignored in normal work, just wait for the next crunch to hit (which is mostly the default state or mode in many companies, anyway), and then see the fun. Every dev scrambling to hack the code any which way to meet the deadline / target / ship date, and now maintaining comments is a goal that flies out of the window. Been there, seen that, plenty, though also worked in places where that was not the case. Those are few in number, though.
There can be other issues too, with compiler directives as comments. What if the directive-as-comment is itself now commented out, maybe as part of commenting out a larger surrounding block of code?
Now you (and the compiler writer) have two problems :)
// +linux
Dunno -- help, anyone? //go:embed
https://golang.org/pkg/embed/ // #include <stdlib.h> import "C"
https://golang.org/cmd/cgo/ // go:generate
https://golang.org/cmd/go/#hdr-Generate_Go_files_by_processi...https://golang.org/cmd/go/#hdr-Build_constraints
EDIT: Those are in the process of being replaced with //go:build directives. See https://github.com/golang/go/issues/41184.
> is probably the coolest and easiest ways to use C libraries I've seen.
You should see Zig's interoperability.