3 ms·
Not that it matters but the go binary should be smaller if you use 'println()' instead of importing fmt.
by BenTheElder 11y ago
Not that it matters but the go binary should be smaller if you use 'println()' instead of importing fmt.
- e12e 11y agoOk. That code is from the go-lang homepage (except for changing the text, so the two programs are mostly identical), so I'm guessing (hoping) it should be considered (more) idiomatic? Would using naked println be similar to using putc in C? Anyway, just tested, and stripped a version without fmt is 414k.
- BenTheElder 11y agoI thought println was like puts in C but it appears to be capable of printing multiple types and support a variable number of arguments(?). It has zero dependencies (in theory) and is just a little bootstrapping/diagnostic tool and might even eventually be removed [0]. Importing fmt seems to import the package which adds a lot of bloat to hello world. But realistically anything more complex than hello world is going to be at least a few MB in go, and eventually you might have to use fmt.Println() and most production code probably does. Edit: and yes fmt.Println() is idiomatic. I was just mentioning that it is possible for helloworld to be a bit smaller in go than other go programs. [0] http://golang.org/src/builtin/builtin.go?s=10600:10626#L240 http://golang.org/src/builtin/builtin.go?s=10600:10626#L240
- e12e 11y agoDoing basic imports is a valuable addition to hello world, as it demonstrates the tool-chain is working :-) I just found out that my rustc-arguments probably were wrong (for most uses, anyway). Or rather, they link dynamically to the rust standard library -- which while "equal" to C, won't hold most of the time. All (non-embedded) systems will have libc for the foreseeable future -- assuming that they have rust libstd is probably not a good assumption to make. I found this out after I upgraded to rust-1.0, and the lib/libstd-<hash?>.so files changed names. So while: rustc -O -C prefer-dynamic -o hello hello.rs works, that produces a really dynamically linked little binary. One probably wants: rustc -O -o hello hello.rs This statically compiles in the rust std lib, and leaves a binary that's ~332k after stripping. (Btw, -O is equivalent to -C opt-level=2)