5 ms·
Seems pretty complicated compared to Rust's `include_bytes!("path/to/file")`. Sounds like it might have a compile time advantage though, seeing as it produces a
by nicoburns 6y ago
Seems pretty complicated compared to Rust's `include_bytes!("path/to/file")`. Sounds like it might have a compile time advantage though, seeing as it produces a seperate package.
- opqpo 6y agoEverything in Golang seems pretty complicated and nonintuitive compared to any other modern language. But "it's all well thought out"!
- jimktrains2 6y agoEvery nil panic and manual type assertion holds a potentially very nice language back. They just seem like relics we should abandon.
- opqpo 6y agoAccessing nil pointers is well thought out. Not enforcing error checking is well thought out. Reflection and code generators instead of generics and traits is well thought out. Lack of conditional compilation is well thought out. No compilation with unused variables instead of warnings is well thought out. Doing your own sort, map, all essential array operations from scratch everytime is well thought out. Spamming err != nil instead of some operator like `?` is well thought out. iota instead of type-safe Enums is well thought out. No file-scope variables is well thought out. go mod is well thought out compared to npm and cargo.
- leetrout 6y agoGo doesn’t have to be bad for all those things you like in Scala/Rust/etc to be true. It’s a simple language with simple, explicit, verbose, tedious, pedantic patterns. The communication resulting from those patterns is where the value lies for a lot of developers and teams.
- opqpo 6y agoMediocrity, ugliness and verbosity is more well thought out than engineering.
- leetrout 6y agoSure - I know you disagree - I was just pointing out a Ferrari and a school bus can both exist and be good for different purposes.
- opqpo 6y agodisagreeing is a pretty strong word. Nobody can disagree these days. I was flagged and labeled as a troll within a couple of minutes once I criticized a programming language. 30 years from now, people will remember this pathetic mob tyranny era when one couldn't even offend a programming language feelings!
- hu3 6y agoIf you allow me an advice, I'd rather not waste precious time with trolls. That user has multiple flagged messages in this month alone.
- jimktrains2 6y agoBefore using it I thought the if err != Nil would be annoying, but it actually isn't. I think a sum type would be better, but the pattern is common and honestly not very different from a match on a sum type. In general I agree that it does lead to code that's more familiar even if it was written by someone else. Having only used it a few months now, I can definitely see where the value in go lies.
- Thaxll 6y agoIt seems much more powerful than the Rust version. The Rust version basicaly embed the file into a byte array that's it or I'm missing something?
- nightfly 6y agoIf you need more check out the rust-embed crate.
- euank 6y agoThis proposal is more powerful than that one rust macro, but rust's abilities around embedding files are much more powerful than go's approach. This proposal allows "go build" to embed things in a very specific way, but it's not meant to be extensible. Rust's 'include_bytes!' macro on the other hand is a macro in the stdlib that can be emulated in an external library. I'm fairly sure every feature of go's embed proposal could be implemented via a rust macro outside the stdlib. For a specific example, I had a project where I wanted to serve the project's source code as a tarball (to comply with the AGPL license of the project). I was able to write a rust macro that made this as easy as effectively "SOURCE_TARBALL = include_repo!()" [0] to embed the output of 'git archive' in my binary. Of course, there's a very conscious tradeoff being made here. In rust, "cargo build" allows arbitrary execution of code for any dependency (trivially via build.rs), while in go, "go build" is meant to be a safe operation with minimal extensibility, side effects, or slowdowns. [0]: https://github.com/euank/include-repo https://github.com/euank/include-repo
- zenhack 6y ago> Of course, there's a very conscious tradeoff being made here. In rust, "cargo build" allows arbitrary execution of code for any dependency (trivially via build.rs), while in go, "go build" is meant to be a safe operation with minimal extensibility, side effects, or slowdowns. I've been working off and on on a language that tries to get the best of both worlds to some extent. The whole language is built around making sandboxing code natural and composable. Like Rust, it has a macro system, so lots of compile time logic is possible without adding complexity to the build system, but macros don't have access to anything but the AST you give them, so they are safe to execute. There's a built in embed keyword that works like Rust's include_bytes, which runs before macro expansion, which you can use to feed the contents external files to macros for processing. At some point I'll probably add a variant that lets you pass whole directory trees.
- leetrout 6y agoAlso note in this proposal: > The path separator is a forward slash, even on Windows systems. Which is much more ergonomic for developers than rusts treatment of os specific paths.
- Arnavion 6y agoForward slashes work on Windows systems for most [1] paths. You can write `include_bytes!("foo/bar.txt")` in Rust and be very confident it'll compile correctly for most of your users. [1]: "Most" because they don't work for namespaced paths, by design. But note that the number of times you'll encounter those is limited, the Rust standard library doesn't handle them correctly in general, and a lot of other non-Rust software breaks when given them.
- leetrout 6y agoOh, TIL! Well that is good to know- so it is only that windows backslashes fail on linux.
- josefx 6y agoWindows path handling is a horrid mess. It basically takes your input and tries to turn it into a valid NT file path, that also includes handling special device names like COM1. At some point this was limited to 256 chars, so you had to input a valid NT path yourself if you wanted it longer, however I think Microsoft removed that limit a few years ago.
- justasitsounds 6y agoI know it's been mentioned before, but I really feel there is a need to codify an 'internet lore law' about how many comments can appear on a Go themed HN post before someone brings up how superior Rust is Something like: Pikes law of unfavourable comparison OR HN Golang oxidation rate
- dodobirdlord 6y agoOxidation Factor: Inversely proportional to the amount of time before a comment brings up the superiority of Rust. Go has a pretty high oxidation factor.
- justasitsounds 6y agoOxidation (noun): the act or process of shoehorning Rust into a comment thread
- papaf 6y agoI suspect that, programming in Rust is so onerous, that Rust programmers must take lots of breaks and troll Go threads so they feel less bad about themselves. Or maybe they're just waiting for something to compile?
- no_wizard 6y agoTo be fair, I remember thinking the same thing when Go was new. HN was pretty dominated by everyone apparently switching to Go (if you were to believe the general attitude anyway) and how Go was the clear path in the future Not that it is or isn’t and clearly Go does things really well in some problem spaces but yeah, this seems to be a common theme for all young languages I do think some members of the Rust community Take it waaay too personally, which I never saw in general when Go was the hip thing. That I agree can be very obnoxious
- pantulis 6y agoSame with Nodejs, and same with Ruby when the Rails craze. That's us devs.