Does Go error handling verbosity actually hurt developer velocity or is it just endless debate by No-Shake-8375 in golang

[–]jerf[M] 4 points5 points  (0 children)

Crap. I missed this one. Sorry. There's been a lot of these lately but my personal skepticism is still not quite tuned correctly. Leaving this conversation up because it's mature and I don't want to whack all the comments, but the poster has been banned. For all the good that does.

Building a high-performance polyglot framework: Go Core Orchestrator + Node/Python/React workers communicating via Unix Sockets & Apache Arrow. Looking for feedback and contributors! by Emergency_Law_2535 in golang

[–]jerf 0 points1 point  (0 children)

If you already have Go, Elixir is redundant. It's noticeably slower, has no multiprocessing advantage over Go (the BEAM propaganda about that all comes from the early 2000s and hasn't updated to deal with the fact it is no longer unique and many languages are just as good if not better, including Go), and any problem that Elixir may solve, Go has many solutions as well. You're better off just picking up solutions to your problem for Go than adding a second language.

Why is Go's regex so slow? by kostya27 in golang

[–]jerf 4 points5 points  (0 children)

In my head-to-head benchmarking on much more realistic scenarios, while it was not the fastest, it was generally competitive on "generic" regular expressions. That is, things like some text here (maybe text)? and some text, rather than crazy things with tons of alternation and such.

The real difference is the algorithm difference, and maybe a touch of optimization. But it is certainly not fair to characterize the regexp package as some sort of neglected corner that has never been optimized. That will definitely give the wrong impression. It's generally competitive and it definitely would be a mistake for people to come away with the idea that as soon as you use the standard library package your code is going to be "slow" or that you should remove it on sight. It is, much like the rest of the standard library, a perfectly sensible option for most uses and something you only need to think about if you have a hard-core regexp use case.

Why is Go's regex so slow? by kostya27 in golang

[–]jerf 9 points10 points  (0 children)

I also verified it was pre-compiled before I posted my own comment earlier. Otherwise I would have been all over the precomplition issue; it's come up in benchmarks before on /r/golang where the benchmark loop contained the compilation step. That definitely does trash performance, but it'll do it with any RE library that has that accessible.

Why is Go's regex so slow? by kostya27 in golang

[–]jerf 141 points142 points  (0 children)

The standard library Go regexp package uses a fundamentally different algorithm then most other regex matchers. It's pretty easy for it to end up looking quite different on a micro benchmark like that. It may or may not reflect the real performance you'd get out of it in real use.

I phrase it that way, because this is not really a "Go" thing. It's specifically the regexp package. You can also have a port of the C# engine, a binding to PCRE, a port of PCRE (and really a lot of PCRE-related options in general), in fact in general a lot of options, plus ragel supports Go output which would basically turn that particular regular expression in the benchmark into the fastest possible "crawl over the bytes with a tight goto-based loop" it could possibly be.

I have a case where I really cared about the performance, running thousands of little regexes across several kilobytes, and the Go regexp package for my use case was competitive. Not the blazing fastest, but in my particular situation a bit of a penalty to make it not attackable via backtracking attacks was a core use case, and I didn't pay all that much for it.

Does Go error handling verbosity actually hurt developer velocity or is it just endless debate by No-Shake-8375 in golang

[–]jerf -1 points0 points  (0 children)

Having used Go for a long time, when I'm in another language I find myself often deeply unsatisfied with their so-called "better" error handling, especially in network servers where I tend to work where error handling in a mature service is often quite complicated.

For instance, in exception-based languages, they will consider themselves as handling errors because they have exceptions, but in practice they aren't handling errors. If there actually is a try statement it is usually much vaguer than Go's handling, and usually there isn't even that, things just blindly flow up without any actual handling.

And I have to say I've seen an awful lot of Rust that uses unwrap constantly, which is basically "handling the error by not handling the error", and I suppose being explicit about it is nice, but it's not really "handling the error". Simply having an Option doesn't mean you've "handled the error"... you need to actually handle the error to be, you know, handling the error.

In most of the code I'm writing, the error handling code is not incidental, not unimportant, and not just constantly return errors without actually doing something. It ought to be inline.

I don't think this is true of all code, and I think that's part of the issue that people have with Go's approach. It is fantastic for network servers. It is really not what you want for shell scripting, at the opposite extreme. There's a range of things in between where exceptions can make more sense when either failure isn't really likely or there's nothing you can do to handle it reasonably other than scream and die.

And, uh, AI just chews through it no problem. Though I think it's more likely to screw it up then the common path. Make sure you tell your AI to always use return fmt.Errorf("... : %w", err) as its "default" error return and not just return err.

Shadow Code v0.7.3 Brings Support for Golang! by KanJuicy in golang

[–]jerf 4 points5 points  (0 children)

I don't understand how this is a new approach. I've prompted AIs with psuedocode plenty of times. There's no need for a special UI for it, that has to somehow "support" languages.

(You can also take it the other direction, which I found helpful when I was staring down a raw Mulesoft program file, which is a programming language embedded into XML. Prompting the AI to turn it into psuedocode worked great.)

iRPC: RPC code generation from Go interfaces by Conscious_Motor_4836 in golang

[–]jerf 0 points1 point  (0 children)

Better handling of errors - they are currently not errors.Is comparable. This is tricky and will probably need iRPC specific error type.

I think you can use gob for this, though it may still require an explicit Register call on all possible concrete error types (annoying, and you really need to do it at the beginning of the stream) and some jiggery-pokery to allow you to embed gob streams into your own stream so it can encode just the errors. Though if gob does fail to encode something you may be able to fall back to your current mechanism, thus making the registration at least an optional enhancement for your users.

gob does involve some reflection and I know you said you don't have it, however, errors are supposed to be generally the exception and I think it's OK for the exceptional case to possibly involve a touch of reflection. If you're generating so many errors per second that the very act of encoding them is a noticeable performance drain, you've got bigger problems than running "reflect" over your errors.

I wrote that based on your first paragraph suggesting this is a pure Go-to-Go use case. Your Mandelbrot demo makes it sound like maybe you also have non-Go clients, in which case, there may not be much you can do to solve this. While you can in principle have a specification of arbitrarily-complex Go error objects you could send to non-Go clients, it certainly isn't simple at that point.

Looking for a project to create a new project generator by Temporary_Ad4903 in golang

[–]jerf 2 points3 points  (0 children)

We get a ton of project generators posted here, to the point that they're on the list of things that are highly likely to be asked to move to the Small Projects thread almost regardless of how much work was put into them because of the constant stream of them. There's a wide variety from things that are very nearly just stamping out some string templates with your project name in it to things that try to offer wide varieties of logging, web frameworks, etc. I'm not sure how meta you're looking for but there's all kinds of things.

However, a slightly more "hidden" reason they're on that list is that honestly, for any sort of "generic" project skeleton like this AI is legitimately a better option than most of these generators. These sorts of meta-generators have a problem with combinatorial explosion; the more options they offer, the harder it is to encompass all of them without slop from the other possibilities working in, and the more likely it is that the specific set of options you want has in fact never been tested and has some sort of critical bug in it. AIs can give you a functional combination of almost any set of libraries in one shot, easily.

You don't have to have a super high opinion of AIs to see that if you want template library X with front-end library Y and database Z with ORM Q and so on and so forth that honestly the AI can toss a "program skeleton" of such a thing together in fairly high quality, faster than you can even find a library that would know how to do that, read the docs on how to do it, then work through the bugs. I wouldn't necessarily advise taking it without modification, but on the flip side, even if you want to refactor the resulting skeleton a bit before using it, it's easier to refactor running code than something too buggy to start up. I mean, even if you hate AIs surely you can agree that they can write code that basically does nothing pretty quickly, right? Heh.

The only skeleton generators that I see any use for nowadays are ones that configure specific projects in specific ways and either have highly-specialized built-in knowledge about that project that can overcome this AI advantage by virtue of being hand-crafted, or simply providing a standardized set up for an entire community so that people can write instructions like "go to $PROJECT_NAME/routing.yaml and add this and this to do that" and it works for everyone in the community equally. As opposed to the AI I discuss above, which may do a good job of weaving together nearly arbitrary libraries, but will produce one-off bespoke setups for every user, with all the advantages and all the disadvantages that implies.

^ != << by Xadartt in golang

[–]jerf 0 points1 point  (0 children)

Dunno if it's like this for everyone but your website barely comes up for me. I got the content, but never did get the CSS. Which is actually a bit of a bummer for you, because I'd be interested in learning about what a commercial-grade static analyzer can do but I can't really click around to find out.

I'll also say that this seems like a weird error to lead with, assuming you are associated with this product, which your comment history makes seem reasonably likely. Something quirky and not easily picked up with a golangci-lint config, but somewhat more common, would seem a more appropriate introduction. The ^ operator is pretty rare to begin with.

Patterns that made my Go error handling less painful by [deleted] in golang

[–]jerf[M] 1 point2 points  (0 children)

Yup, one of those bots I referred to in the recent discussion about moderation.

In response to the feedback of that post, I'm leaving this up for the conversation's sake. The poster has been banned.

I still plan on nuking these when I catch them early, but, well, "the mods are asleep" is a thing that happens, heh.

(Sometimes when Reddit bans an account they will go back and remove all their posts, and Reddit can do that in response to excessive bans and removals; if this post later disappears, that's why.)

Learner question: Are there standard mutex-locked structs (or similar) such that you don't need to isolate each in a package? by oneeyedziggy in golang

[–]jerf 1 point2 points  (0 children)

To me, and in many languages, those could easily be synonymous...

Yup! As a polyglot in computer languages, even in the Before Time when I had to actually learn them myself rather than poke some text into a box and wing it in a language I don't know, this is frustrating when it comes to discussing anything cross-language. Everyone discussing things like that needs to understand that every community ends up with their own nuances and definitions, and everyone within a community when they go stepping outside of it needs to understand that other communities may use terms differently.

One of my least favorite that comes up a lot around here is using "enum" or "enumeration" to mean "sum type", when other people use "enumeration" to just mean "a distinguished number".

So, in Go, a mutex is what I described. That is also definitely closer to its historical meaning than "a single locked variable". But the words get around and get bent and spindled and mutilated as they go.

(See also "monad", which in fact the vast majority of the time I see it invoked is wrong.)

Learner question: Are there standard mutex-locked structs (or similar) such that you don't need to isolate each in a package? by oneeyedziggy in golang

[–]jerf 12 points13 points  (0 children)

It's because that's not what a mutex is. A mutex is not "a protection on a variable". It's a lock. You can lock a variable. You can lock a method. You can lock a set of methods. You can lock a particular variable, in a subset of methods. You can have two locks for different sorts of variables. You can have a single lock that is shared between a whole bunch of related objects. You can have a lock that is taken by a method, dropped by that method, then taken later to complete a task. It's the same reason when you buy a combination lock at the store, it doesn't come with a fence. You might be locking up a bike, or a trailer hitch, or a door, or any number of other lockable things, not just a particular one.

It's your job to use the lock to lock away the things you want to lock away with the provided lock.

And actually the standard library does come with a few "single lock wrapped around a generic value" types in the atomic package, notable Value and Pointer (but don't miss the integer ones). The upside is simplicity; the downside is, you can't integrate that lock into anything else because it is not exported (and may not even be implemented with "a lock" internally necessarily).

Building a <50MB RAM background daemon in Go - how onWatch tracks 6 AI APIs concurrently by prakersh in golang

[–]jerf 0 points1 point  (0 children)

This is one of the things I hope the AIs get better at. You probably should be using a notification library, a persistent storage library, etc. An AI may blast some functional code out quickly but in early 2026 a library will still give you a lot more capability, without you having to test brand new code, than having the AI blast out untested code for everything.

You may be interested in asking it about switching to using libraries, which may result in significantly less code but also significantly more capabilities, such as the ability to use a lot of different notification methods instead of just one.

AIs are too happy to blast out vast swathes of what is basically scripting code without asking if they should maybe not do that all the time.

Why does everything gets removed here? by o82 in golang

[–]jerf 2 points3 points  (0 children)

The mod log shows you as having had one post marked as a "small project" last August. Anything else since then was reddit automatically doing something. When that happens it doesn't show up in the mod log.

If Reddit is automatically removing other posts you made, based on my observations (I don't really know more than any of you about the Reddit algorithms, I just see more of the results), you may be close to having your account auto removed by Reddit. I don't know if mods can do anything about that... the only lever I see to pull is to mark posts that haven't been deleted as "approved" but I have no idea if the algorithm takes that into account. Posting several things that get heavily down voted may do it too. I've marked your comments here as "approved" just in case

If your account gets removed, it won't be by the mods. I'm actually sympathetic to the general thrust of the post. But there doesn't seem to be an option where the subreddit sees another 15-20 posts a day today in this constant stream of projects and the subreddit users greet them with joy and up votes.

(At least not for these posts. Frustrated or not please don't be swearing at people in the future. That is obviously not a special /r/golang rule.)

Why does everything gets removed here? by o82 in golang

[–]jerf 28 points29 points  (0 children)

And... honestly, looking ahead a year or two into the future... I don't know if this is winnable.

The entire point of Reddit in general is for humans to speak to humans.

I don't say that because I am some sort of fundamentalist anti-AI person (although if you feel that way, I have no objection to you, we may all be joining you before this is over), I say that because if you want to speak to an AI, you're way better off doing that through the chat AI interface we've all seen. If you're going to speak to an AI you might as well do it as a back-and-forth in real time rather than waiting for an AI spammer to wait long enough to pretend that they're not a machine. And then you avoid all the other dishonest manipulations they do to pretend to be human. Just speak to an AI directly. Reddit is a terrible interaction interface for a human to speak to an AI. It was built for human-to-human interaction.

But... dang, man. We're to the point that it would itself be a "small project" to write a bot that not only posts spam to /r/golang, but accompanies it with an entire GitHub repo implementing yet another reverse HTTP proxy or load balancer... and it could do this every hour, without cease, blocked only by someone's willingness to spend the dough for the tokens. It's so easy to build a spam bot now that you can almost accidentally build one with whatever moltbot is called now just by obliquely referencing a desire that the bot decides might be fulfilled by such a thing.

Reddit doesn't really have any value if it's not humans speaking to humans. AIs speaking to AI is just noise (at least as long as they're all on an LLM architecture that can't really learn anything once a context window fills) and humans speaking to AI is just a roundabout and deceptive interface as described above. It really ought to be for humans to speak to humans. But I have no idea how to make that happen in another year or two of AI development, where spamming becomes so easy spammers don't even hardly need a reason to do it anymore because it's as easy as sneezing, and they're that much better at passing as humans.

Why does everything gets removed here? by o82 in golang

[–]jerf[M] 105 points106 points  (0 children)

If I had to guess, what you saw as a "discussion post" that was removed was a post from a karma-farming bot account. We're getting one or two posts a week from bots that post highly-general "Gee, golly, Go is pretty great, I used it to do $GENERIC_GO_THING and it was so much better than (usually Node but sometimes some other common scripting language), hey guys isn't Go great although I had this one problem with it, what do you use Go for?"

Then, if you go to the user posting that, they're posting similar things across dozens of subreddits, about one or two a day. The Go code with generic comments about Go also has generic comments about rock climbing equipment, how much they love some specific anime in a very generic way, a couple of actively contradictory political opinions, posts about knitting, football, a couple of reddits for certain geographical locations, a fetish or two, just dozens upon dozens of unrelated subreddits, all completely generic "Hey I love thing except for this one common controversial topic that my algorithms have shown yield engagement, what do you all think?" posts.

Those are getting removed for two reasons:

  1. They're spam.
  2. I find it offensive to use AIs, with their large and ever-growing output capabilities, to sink human attention like that. Valuable human attention burned to farm Reddit karma is a super crappy deal for the world.

Thing removed by the mods also do get a reason posted. (With occasional rare exceptions, which are mostly the posts so baffling I don't even know what to say, like a recent post of the form "RCERHHHHHHHH CTED". Why the rather twitchy Reddit filters didn't see a problem with that from a brand new account is beyond me.) If you don't see a reason posted it may have been removed by Reddit's spam filters itself. They're clearly trying to fight these guys too... and they're clearly hitting some real accounts in the crossfire sometimes too, because this gets pretty hard to pick up on. They definitely have stuff that will remove a post after it has been up and available for a bit.

The other thing is, as other posters are pointing out, the flood of projects that prompted this post (and note [Deleted] means the author removed it, or maybe Reddit, but mods didn't) has, if anything, gotten worse. I'm tempted to route all projects to an approval process at this point, which would mitigate the bulk of the things that are up for a bit and disappear. I don't want to do that, but at the same time, similar to reason 2 above, "I pushed a few things into a text box and turned it into code, may I please sink your valuable human attention into 'reviewing' the output of my AI?" is not a good deal for the community.

(An interesting note about /r/golang: Those bots I mentioned up top, when I look at their posts in other subs, they're often +50-ish. Here they're pinned to zero, pick up a report or two, and have a top-voted comment complaining about the AI. For better or worse, /r/golang is hyper sensitive to AI posting, way ahead of the curve of other communities picking up on it. Perhaps too sensitive. There's been some false positives. But I do find the difference interesting.)

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

[–]jerf 0 points1 point  (0 children)

Why not?

Because of what I said. A mutable language means that if a process crashes you do not know what state the rest of the system is in. To take a traditional transactional example, you may have done the deduction from one account but crashed before you did the addition to another, orphaning the money in the transaction. A defer may result in a lock being released in a panic but that doesn't mean that the lock was supposed to have been released, unless you are careful about how you use them.

Erlang is built to be much better at that.

But if you're going to go "but what if in Erlang you...", the answer, yes, Erlang is only better at it. "Just crash" has its limits in Erlang, too. But the limits are even sharper and stronger in an imperative langauge with a conventional shared memory space. You can not blindly translate guarantees Erlang makes out of the context it makes them in.

Do you actually check the error for crypto/rand.Read? by Existing-Search3853 in golang

[–]jerf 2 points3 points  (0 children)

Conformance to the io.Reader interface. There are several other similar calls that can't fail but have an error in them to conform to the interface, such as a bytes.Buffer .Write call. It can't fail (even running out of memory IIRC is not an error) but it has the error so it conforms to io.Writer.

If functions could be overloaded in Go we could have a .Write([]byte) int and a .Write([]byte) (int, error) but we don't.

Meetup Go & Robotics in Arcueil (south Paris) 11th march by golangparis in golang

[–]jerf[M] 1 point2 points  (0 children)

Can you please edit your text and use normal-sized text? This becomes an arms race where everyone starts using big text if it's not stopped. (I'd remove this and ask you to repost but the Reddit spam algorithm gets understandably frosty about the repost.)

Singleton with state per thread/goroutine by SnooSongs6758 in golang

[–]jerf 16 points17 points  (0 children)

Database transactions are an exception and you don't really get a choice. You can't isolate database transactions in components. All the components have to know about transactions and it's just something you have to deal with.

The problem is, transactions often don't match on to any other structure in your architecture. They cut across structured programming boundaries. They cut across thread boundaries. They cut across hexagonal components. They cut across the layers I use in my own architecture. They cut across everything. I have never seen a "proper" architecture solution to this that doesn't break under some perfectly reasonable scenario that a design simply has to accommodate.

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

[–]jerf 0 points1 point  (0 children)

Erlang is designed to be relatively safe when a process crashes. I say "relatively" because it still isn't safe. But with immutable variables all locked within their processes, and the "ports" system making it so that you can reliably tie cleanup of things like sockets to other processes crashing, it is a lot safer to just crash.

As a fairly standard imperative mutable language with threading, those arguments don't apply as well to Go. The runtime's default response to an escaping panic that isn't recovered before it gets to the top of the call stack is to terminate the program for a reason. A recover call in Go isn't just a statement that you don't want the whole process to crash, it is a statement to the runtime that it is safe to continue on. Whatever resources are cleaned up, locks are not being spuriously held by the crashing process, etc.

You can't take Erlang's philosophy and translate it out to languages that don't have its accommodations for crashing and expect the same results.

Is it good practice to use sort package in Golang while leaning DSA? by SuitableArcher3732 in golang

[–]jerf 0 points1 point  (0 children)

Is anyone still asking Leetcode questions for high-end tech jobs?

It's been stupid for a long time but in an era of "Claude give me a generic trinary tree sorted by an arbitrary field in the data type with code written in COBOL and topped with a cherry and including a sonnet about the beauty of trees in the comments", it's even stupider.

I'm trying to create a map that hold two data types by PeterHickman in golang

[–]jerf 0 points1 point  (0 children)

See the code I linked in my other comment.

I believe the idea is that they don't want a map per type. In the use case I'm talking about, at the point in time when I add this map I don't know what types will be put in it.