20 ms·
Major standard library changes in Go 1.20
- candiddevmike 4y agoJust when you think you have The Best Way of handling errors in Go figured out, they add yet another paradigm. Is a shared err type package on the way out? I use it to bubble up HTTP status codes consistently, is there a better way? Should you always use sentinel errors?
- metadat 4y agoThe only constant is change. Especially with Go, apparently. It's hard to evaluate the comparison of Golang of today to the one I originally discovered 11 years ago in 2012. Then, it was a breath of fresh air. Nowadays.. I find myself sighing. It works but the joy has faded. Bit rot is life.
- mixedCase 4y agoThe joys and woes of reinventing computer programming right where it was left off in the early 70s.
- kubb 4y agoI think I can sympathise, it's hard to keep up with all the development in PL, so it's easy to convince yourself that all those new inventions are stupid anyway and you don't need them, you'll do it your way. And then, slowly over a couple of decades, other people will be making it their life's work to add in the things that you thought were stupid because inevitably the need for them surfaces.
- groestl 4y agoOr you've seen an approach fail spectacularly in a programming language you're familiar with, which causes you to throw out the baby with the bath water.
- metadat 4y agoAny specific examples you can share?
- groestl 4y agoA bit tongue in cheek, but I'm just referring to Rob Pike et al., exceptions, and C++. And I must clarify that by "fail spectacularly" I mean solely from the POV of the aspiring language designer, not necessarily from other language users. People enjoy C++ exceptions now, it seems, in combination with RAII, but back then it was probably a different story.
- wrycoder 4y agoImplementors gotta implement, no?
- zdragnar 4y agoHow many languages go through the first 11 years of life without significant changes? There are lisps, which have no syntax to change, and I guess elixir, which is itself just a syntax for a very mature runtime (BEAM). Hell, even C underwent pretty major changes from 72 onwards, because every compiler supported entirely different features. Things like void functions and returning structs or unions. Granted, this predated internet distribution of software, so changes overall were perhaps slower within a single implementation, but there were still radical developments happening on a frequent basis.
- kaba0 4y ago> How many languages go through the first 11 years of life without significant changes Only if a language with basically zero new concepts could have just learned from the litany of other managed languages’ mistakes..
- philosopher1234 4y agoCan you give an example of a feature where the designers of go failed to consider other languages mistakes? Every discussion of there’s I’ve read has been thoughtful, open, and well cited.
- lakomen 4y agoYeah I'm not using generics and they're a big turn off. If Rust wasn't so ugly and the JVM so Swiss-cheesy and stuck in paradigms, I would switch. So I keep writing my old ways code in Go and act like the new features don't exist. Big sigh
- earthboundkid 4y agoIt’s the same paradigm. You still have to do if err != nil. Multierrors have been in the community forever. It’s just been added to the standard library is all.
- deleted 4y ago[deleted]
- Groxx 4y agoWell. Kinda. Except that now if someone does `errors.Join` and they pass it to existing code that was using `errors.Unwrap` to inspect an error chain... ... they now get a not-unwrap-able error. Which they can still `As` to inspect... ...but since it's a tree, they can't recursively-`As` to find all instances of a type of error in a chain, like they could before (if you find something in one branch, you can only traverse that branch, because As doesn't maintain iteration-state). It's not an unambiguous win, sadly. New code interacting with old code might misbehave.
- earthboundkid 4y agoWhy would the other code be manually unwrapping and then doing an As test instead of using errors.As? That's extremely Hyram's Law behavior. :-) I agree though that if you have an error log reporting system it should be updated to understand the new multierrors. OTOH, if it's not, it will just see the multierrors as a single node and work fine otherwise.
- Groxx 4y agoAnything trying to display the whole chain is one example, like some every logging library or custom output in existence. For behavior: sometimes wrapping order matters, and As is convoluted to use to determine that, to say the least. Manually unwrapping is easy, and reasonably safe and easy - the standard library does it! But...
- andrewstuart2 4y agoSentinel errors are only one way, and definitely not the best way imo. `errors.As` gets you the ability to recursively and multierror-safely check to see if somewhere in the stack, an error of a certain type is found, and access its extra data, to determine e.g. which status code is most appropriate based on any extra data in that type. I think shared types from a package make a ton of sense and are really practical for writing flexible and maintainable code.
- tptacek 4y agoThis is the same way of handling errors Go has always had. The point of Go errors is that they're just values; you program them like you would anything else. People have had multi-error packages for years, and Go encouraged it. Now there's a standard one.
- threeseed 4y ago[flagged]
- badrequest 4y agoEvery time this completely tired and worn out take is regurgitated on this website, it reminds me that people write big fat try/catch blocks because they never expect things like file reads to fail.
- Groxx 4y agoThough at least Java people doing that get a stack trace, so they can find out which attempt failed. In random Go code you're fairly likely to get "error: file not found" and literally no other info.
- Joker_vD 4y agoWell, the Go's FileNotFound errors returned from the standard library do have the file name in the message string. Java's FileNotFoundException exceptions, on the other hand, don't; and the stacktrace is usually useless because it doesn't record the values of the local variable anyhow.
- Groxx 4y agoyeah, the inconsistency there in both standard libraries is... strange to say the least. more info is more gooder IMO, the runtime cost is SO much lower than the troubleshooting cost.
- 4y ago
- gregwebs 4y agoI wrote a package to attach codes to errors via wrapping rather than a shared error type: https://github.com/gregwebs/errcode https://github.com/gregwebs/errcode
- revskill 4y agoNo, Go programmers are get paid to get if err != nil done correctly.
- politician 4y ago[flagged]
- logicallee 4y agoFor your information, I understand what is meant by stochastic parrot, but after interacting with ChatGPT quite a bit it is clear to me it is doing real thinking. One way you can verify this is to ask for its opinion about novel things, for example you can invent something new and ask its ideas about it. It will give genuine feedback that shows understanding and does not show parroting behavior. Soon you will be able to ask it to build you the damn thing as well, and that should put an end to the idea that it is just parroting. It's not quite there so sometimes it does indeed seem to just parrot. But it has real thoughts as well.
- endigma 4y ago[flagged]
- politician 4y agoNo, “it” doesn’t have real thoughts. ChatGPT is an amazing language model, but it’s a serious error to claim that the model is sentient. Each of the so-called interactions with the model are concatenated together for the next set of responses. It’s a clever illusion that you’re chatting with anything. You can imagine it being reloaded into RAM from scratch between each interaction. They don’t need to keep the model resident, and, in fact, you’re probably being load balanced between servers during a session.
- Waterluvian 4y agoAre you sure you’re not describing how humans think? How can we tell? I also have this urge to say it isn’t thinking. But when I challenge myself to describe specifically what the difference is, I can’t. Especially when I’m mindful of what it could absolutely be programmed to do if the creators willed it, such as feeding conversations back into the model’s growth.
- nraynaud 4y agoI think arenas could solve a weird need I sometimes have, the ability to say: “from now one this object should have no references” as a debugging tool.
- nemo1618 4y agoYou might be able to use https://pkg.go.dev/runtime#SetFinalizer https://pkg.go.dev/runtime#SetFinalizer for that. Another option is https://pkg.go.dev/lukechampine.com/freeze https://pkg.go.dev/lukechampine.com/freeze -- not exactly what you want, but if the object is mutated after freezing, it will panic.
- bbkane 4y agoVery useful! I'll be playing with the error tree additions and studying the HTTP interface extension to see if I can replicate the pattern for https://github.com/bbkane/warg https://github.com/bbkane/warg values. Id like to be able to have value-specific output for different types of --help , even ones not in warg
- astrange 4y agoAdding manual arena memory management seems like a weird choice for a supposedly memory-safe and GC'd language where this is supposed to be an implementation issue. I mean, you should hear the screams from Rust/Go people about how bad C is, and now you're just going to do it?
- slimsag 4y ago> now you're just going to do it? "you can’t import it by default", "you probably shouldn’t be using it at all", "experimental arena package", and 'you must opt-in to even be able to use it via an GOEXPERIMENT environment variable' As for screams from Rust/Go people about how bad C is, it said: > This is highly efficient, but also highly dangerous. What if the programmer makes a mistake [...] > > To mitigate the risk of these kinds of bugs, the arena package will deliberately cause a panic if can detect someone reusing memory after it has been freed. and goes on to explain that each arena has its own unique/distinct address space, so that if a pointer to an object still exists and is dereference it will get a memory access fault, causing the Go program to terminate, with an error message specifying that arena as the cause of the problem. Sounds like a pretty reasonable/cautious experiment to me.
- lnxg33k1 4y agoYeah I think a language is safe or unsafe according to the ecosystem they live in. A project a developer works on is hardly 100% self-developed and depends on library and third party code, so I understand you have experiments you need to enable, but once it starts spreading in libraries, I think the whole safety guarantee just goes out of the window? As a rust student myself, even the unsafe{} block is stupid
- kaba0 4y agoRust’s unsafe is still much safer than your average C code. The borrow checker checks inside unsafe blocks as well, you can just circumvent it through pointers. But the great thing with unsafe blocks is that you get to create a safe API abstraction on top. You manually verify closely the unsafe parts, and if you got that short part right you can use the safe wrapper wherever you want safely.
- malkia 4y agoWonder if this is to optimize protobufs (C++ versions uses (or can use) arenas too)
- p-e-w 4y ago[flagged]
- acrispino 4y agoFrantic is one the last words I would use to describe the process of adding generics to Go.
- impulser_ 4y agoThe whole purpose of Go is to make building concurrent and scalable programs simple. Which is does achieve. Someone that knows basic Go can build a server that would be just as performant as one in Rust with no optimizing, no external dependencies, fewer lines of code, and in minutes not hours or weeks. Yes, obviously a server in Rust will be faster once you optimize it, but the point is that you don't really have to do optimizations with Go to get fast concurrent code. You pretty much get fast programs by default. This is why it is so popular.
- sieabahlpark 4y ago[dead]
- threeseed 4y ago[flagged]
- jitl 4y agoI think Rust at least twice as complex Go, and an order of magnitude is not unreasonable estimate. For example, there’s only `string` in Go. How many string types are there in Rust? Even a beginner must understand &str vs String. The concept of lifetimes I find easy, but that isn’t the case for everyone - and the ramifications of the borrow checker are often a “brick wall” for me. Anyone who’s written Typescript or Python can pick up Go and write average quality Go code in a few days after going through the tour (https://go.dev/tour/list https://go.dev/tour/list). 10 years ago, I did the tour and the next day wrote an animated GIF for the terminal. Everything I needed was in the standard library (yes, including GIF parsing), although I eventually used a package for color quantization. If there’s a learning resource like the Go tour for Rust that can get me from zero to writing an animated gif player in a couple of days, I’d love to hear about it! So far I haven’t been able to make my way through the Rust book at an exciting pace.
- 7to2 4y agoHow substantial is Go's standard library compared to Python's? I know Go has support for what I would consider to be the bare minimum for what modern standard libraries must provide (http, crypto, time), but what about support of smtp, data serialization formats, etc? I want an alternative to Python that can provide the same awesome batteries-included experience. I am also considering Nim but I want a language with a strong industry backing.
- heretoo 4y agoYou could consider Clojure. It is backed by the java ecosystem, which is substantial. Not quite the same as python's "batteries included" approach.
- mzi 4y agoJava has substantial industry backing, but you cannot argue that it has a battery-included standard library. But to answer the question: yes, Go has support for SMTP in net/smtp and a lot of different serialization formats in encoding/ You can browse it all here: https://pkg.go.dev/std https://pkg.go.dev/std
- zmmmmm 4y agoGroovy would be the most "batteries included" JVM language I think ... latest version even bundled YAML support in the standard library. Of course, it has all the downsides of a "kitchen sink" approach to language design.
- mseepgood 4y agoYou can browse the standard library here: https://pkg.go.dev/std https://pkg.go.dev/std > what about support of smtp Yes, https://pkg.go.dev/net/smtp https://pkg.go.dev/net/smtp > data serialization formats What you can find in the "encoding/*" subpackages: JSON, XML, Gob, CSV, ...
- thefounder 4y agoGo is a good alternative. It has support for smtp and data serialization formats. I highly recommend it. Using a single compiled binary for deployment will be a nice addition too. If you have patience to try it for 2-3 months you may fall in love with it.
- Traubenfuchs 4y ago[flagged]
- thiht 4y agoThis is the worst kind of comments on HN. Snarkiness without argumentation, condescension and depreciation of some good and interesting work. Just don't post anything instead. If you're salty or don't like Go, do yourself (and the community) a favor and don't click on submissions related to Go.
- doctor_eval 4y agoAll languages borrow ideas from one another, and that’s good for all of us. I was once a Z80 developer, then a C developer, then Java and now Go. I don’t look at C and say “autoincrement! Those scallywags just copied the idea from LDIR!” (Admittedly this is partly because it’s not true)
- wiseowise 4y ago[flagged]
- philosopher1234 4y agoI thought it was funny
- cbsjjxhcc 4y ago"major standard library changes" is not something you want to here as a consumer of said library.
- earthboundkid 4y agoAgreed, but these are all backwards compatible.
- hknmtt 4y ago[flagged]
- doctor_eval 4y ago> even talking about interfaces like "magic methods" No, this was referring to a mechanism used in the stdlib to see if an object passed in as one interface type, could be coerced to another interface type in order to perform some operation more efficiently. I’m a Go developer, and I didn’t know this happened, it’s basically not visible from the API function signatures, you have to look at the implementation. I love working in Go but this did raise my eyebrows and the functionality definitely deserves being called “magic”, and not in the good way.
- hknmtt 4y agothere is nothing wrong with asking if provided object is more capable than it seems so we can perform more efficient logic on it. that has nothing to do with magic methods, numbers... no magic whatsoever. "magic" in code refers to usually hidden and/or fixed behavior. this is not even in the same ballpark.
- doctor_eval 4y ago> there is nothing wrong with asking if provided object is more capable than it seems so we can perform more efficient logic on it. There certainly is something wrong if you can’t see this in the API declaration. Some Go stdlib calls declare that they accept one interface, but then test the passed in object against another, unrelated interface, which provides additional functionality. Because the second interface is undeclared and hard coded, the functionality is hidden from the user, who has to somehow know about the inner workings of the API in order to benefit from it. > "magic" in code refers to usually hidden and/or fixed behavior. Which is exactly what is happening in this case.
- mjburgess 4y agoThe next phase of language design is making it possible to write "data-oriented" programs which largely live within the cache of the CPU. Ie., the next frontier is moving from RAM to cache, since CPUs are not going to get faster than programs are "already slow". If you rewrite some OOP/Pointer-Machine-Model/RAM-Thrashing programs for modern CPUs, you can get 100-1000x speed-up. The evolution in language design seems, then, to be about exposing more of the hardware to enable developers to target it effectively.
- zelphirkalt 4y agoI don't think the next step is to expose more complexity of underlying hardware to the developer. If at all, then the next step is to have compilers deal with that. Let them rewrite the program.
- dgb23 4y agoYou make a good, general point. But I found that a data oriented approach has benefits outside of performance and resource usage, because it nudges you towards: - normalized, small/tight data structures - data structures that are closely related in computational terms - smaller interfaces and functions that tend to be more re-usable and general - fewer if/else branches and more existence based branching via loops - fewer "business level" generics, macros and similar abstractions, because you can dispatch easily via tagging to concrete types - less code that "digs"/"drills" into data and more code that composes data - generally a simpler (less coupled) end result This all comes with a cost of having to do upfront design and exploration in order to decompose and lay out your data. And while it reduces the mental overhead of understanding the individual pieces of your program on a day by day basis, it might increase learning curve of seeing the big picture, especially at the beginning. So it is a tradeoff. But I think it would be too dismissive to say that the programmer is doing compiler work here. It is design work, and it is unlearning some of the notions of how to structure programs that carried on since the 90's. Some of which are performance related and some of which are about sensible code structure.
- KapKap55 4y agoThe 100x plus speedup is no exaggeration either, I've noticed some incredulity from others at the numbers. For a very simple comparison, I recently was testing a (poorly) custom built data-oriented Entity-Component-System for usage in games with a more typical "componentized" object approach. No multithreading or anything complicated. On my system, the typical approach could generate about 1000 new objects and attach a single component in about 1 millisecond. The data-oriented approach could generate about 100,000 new "objects" and attach a single component in about 0.5 milliseconds. Same thing in the end, but one is roughly 200x faster in the same time frame. It's pretty stunning when you see stuff like this in benchmarks.
- dawkins 4y agoSo happy that they added the ability to extend response deadlines with http.ResponseController.
- rsc 4y agoThe arena goexperiment contains code used inside Google in very limited use cases that we will maintain, but the discussion on https://go.dev/issue/51317 https://go.dev/issue/51317 identified serious problems with the very idea of adding arenas to the standard library. In particular the concept tends to infect many other APIs in the name of efficiency, a bit like sync.Pool except more publicly visible. It is unclear when, if ever, we will pick up the idea and try to push it forward into a public API, but it's not going to happen any time soon, and we don't want users to start depending on it: it's a true experiment and may be changed or deleted without warning. The arena text in the release notes made them seem more official and supported than they really are. We've deleted that mention from the release notes to try to set expectations better. Posting here to leave a note for people who are curious where they went.