A Gopher Meets a Crab

(miren.dev)

42 points | by radimm 2 days ago

7 comments

  • joshka 4 hours ago
    The weird-looking Rust isn’t really Rust being weird, it’s the type telling the truth.

       Result<Option<Result<Message, WsError>>, Elapsed>
    
    That’s three independent “not the happy path” channels: timeout, stream closed, and websocket error.

    The nicer version is not a cleverer match. It’s choosing a domain error shape and converting into it one layer at a time:

        let timed = tokio::time::timeout(duration, receiver.next()).await;
        let next = timed.map_err(|_| ReceiveError::Timeout)?;
        let item = next.ok_or(ReceiveError::Closed)?;
        let msg = item.map_err(ReceiveError::WebSocket)?; 
    
    The ugly line is what happens when you have not decided where to normalize the shape yet.
    • loeg 3 hours ago

        Result<(), ()>
      
      Is pretty weird, though, no? Why would you want a unit value / error type?
      • MrJohz 3 hours ago
        It's basically doing the same thing that, say, `return true` might do to indicate a function succeeded, but with more explicit types. However, because it uses `Result`, it can be used with the `try`/question mark operator which can be convenient in some situations.

        That said, a couple of the examples here feel a bit strange - they're clever things you can do, but they're not necessarily things you often have to do, particularly for a relatively simple task like this. I think the problem with the author's approach is that they can't distinguish between "weird because Rust is weird" and "weird because the LLM generated bad code", because they (understandably) don't have enough experience in what good Rust code looks like.

        • nasso_dev 1 hour ago
          it is indeed pretty weird. clippy has a lint against this iirc. it's recommended to just create a custom error type, even if its just an empty struct or a single-variant enum

          this lets you implement `std::error::Error`, which you really should to make it less painful when you want to erase the type (`std::error::Error` is `dyn`-compatible)

          • It's not like people regularly decide this is a good return type. Just because Claude isn't good at designing code or what have you doesn't mean rust is bad/weird.

            Sure this is something someone can do but it's suggesting the caller doesn't care about why it failed and doesn't need anything from it's success. It's a choice but it's not a typical one. Maybe the fact that it looks weird and there is no comment is a clue that this isn't high quality code.

            People really should be more skeptical of LLM coding. Claude is not as amazing as marketing makes it sound. It is amazing in that it can write code and follow specs sometimes, but a lot of quality gets lost along the way without close supervision by someone who knows better

            • tux3 3 hours ago
              Sometimes you just want a fancy boolean. The advantage is that Result has all the Result APIs and you can compose it with other Results, but otherwise this is just a success bool.
              • stingraycharles 3 hours ago
                It’s the equivalent of Haskell’s Either, with Option being the equivalent of Maybe. They’re fairly well-defined idioms.
                • loeg 2 hours ago
                  I know what Result<> is.
              • simianwords 1 hour ago
                Off topic but using “shape” like this is LLM coded
                • joshka 51 minutes ago
                  Probably on topic here - I talk like an LLM sometimes, and parse my points through them sometimes. I’d reasonably use that terminology and think nothing of it as it’s precise and correct. That said, this was partially LLM and my thinking here.
                  • simianwords 26 minutes ago
                    It’s good, I found your comment relevant and insightful
                  • asibahi 20 minutes ago
                    No it is not. If you were introduced to the term via LLMs doesnt mean everyone was.
                    • bobnamob 1 hour ago
                      I guess I'm an LLM then. I've been referring to the structure of types as "shape" for more than a decade and so have plenty of others
                    • tancop 3 hours ago
                      [dead]
                    • JKCalhoun 13 minutes ago
                      From vibe coding we now seem to have… tray-table coding?
                      • saagarjha 2 hours ago
                        I feel like having an LLM write code in a language you aren't familiar with and then inspecting the results is kind of like hiring someone to speak Spanish for you and then being confused at the weird words they are using. Like, what would make you want to do this?
                        • hnlmorg 32 minutes ago
                          Not the author but this seems a good approach to me because you learn more about a language from implementing a project in it. This is especially true when you already have experience in a language from the same paradigm (like Go and Rust are).

                          So getting an LLM to write an example project then dissecting the code and interrogating those choices, seems like a very good way to learn the idioms of another language.

                          • 2ndorderthought 26 minutes ago
                            Go and rust share very few similarities when you consider the syntax.
                            • hnlmorg 23 minutes ago
                              If you believe that then you haven’t spent much time working in different paradigms of programming languages.

                              Syntax is the easy stuff to learn. It’s any shifts in paradigms (eg pure functional vs imperative vs logic… etc) that takes time to learn.

                              And I say this as someone who’s written professional software in well over a dozen different languages. So I understand well the challenges learning something new.

                              • 2ndorderthought 7 minutes ago
                                I have written production code in about a dozen languages as well believe it or not.

                                I have also trained people who were good to decent software engineers in other languages to write rust. The syntax is nontrivial for a lot of people. There are a lot of people who gave up trying to learn rust, especially before the rust book became what it is today.

                                People typically fight the borrowchecker until it clicks. Learning from an LLM and reading only means you have to be as good as the rust compiler without any experience writing the language. It's got to be way harder that way.

                            • saagarjha 23 minutes ago
                              I would not say that Go and Rust have similar paradigms
                              • hnlmorg 15 minutes ago
                                You’re conflating paradigms with idioms.

                                Go and Rust have different idioms and syntax. But they occupy broadly similar paradigms.

                                For example, you don’t need to relearn how to do iteration like you would with a logic or pure functional language. You wouldn’t need to concepts like methods, like you would if you were coming from a stack based language. Etc

                            • commandersaki 29 minutes ago
                              Have you tried? Give it a shot and see for yourself.
                              • saagarjha 22 minutes ago
                                Yeah I have had LLMs write scripts and changes in languages I can't really read for throwaway uses but I have not really found it useful to go and inspect the code because I don't feel I would learn much
                              • atorodius 20 minutes ago
                                That's a terrible analogy:)

                                It is more like you wanting to build a bed out of wood so you hire a carpenter and watch them and ask questions about every step and maybe help a bit at the end.

                                I find it amazing to learn new programming things

                                • saagarjha 1 minute ago
                                  Well it's an LLM so it's more like you ask your uncle Vinny who is pretty good at a bunch of stuff but sawed off their arm the other day
                                • If you already speak French or another Romance language it isn’t a bad idea to just have a conversation in Spanish directly and then ask for clarifications anytime you don’t understand.
                                  • Which would be all the time? At which point you might be better served by learning from a source that has any guarantees of being correct and doesn't hallucinate. Like text books that have had several editions and are free on the Internet.
                                    • hnlmorg 28 minutes ago
                                      I would be very surprised if you couldn’t figure out what was happening in one C-derivative language when you’re already competent in another C-derivative language.

                                      This isn’t like learning JavaScript and then expecting to be an expert in Prolog.

                                      • 2ndorderthought 17 minutes ago
                                        The first time I looked at rust code that wasn't in tutorial I was pretty confused. Things I thought I understood I really didn't. I knew maybe 6 programming languages including some c. A lot of people struggle to learn rust because it's an ML as in OCAML and really isn't much like C at all.

                                        Some people adapt to it more easily, especially coming from languages like scala but it has a lot of unique characteristics that aren't in C or are even related. Like lifetimes, dynamic dispatch through enums, the borrowchecker, pattern matching, the ? Operator, etc.

                                        Maybe you all are way smarter than me, super possible, but I wouldn't expect much to translate between go and rust. I think some evidence for that is the blog post here...

                                        • hnlmorg 3 minutes ago
                                          Scala is a great language. And Rust definitely has noticeable influences from ML. But I’d say Rust is closer to C++ than it is to ML.

                                          But, to be fair to you, I’ve not touched Rust in a couple of years so maybe my memory is fallible here?

                                  • cpursley 2 hours ago
                                    I’ve learned a ton of new things this way, even in a stack that I know really well. Ditto on all sorts of new little command line tricks that I was unaware of before.
                                    • MrJohz 1 hour ago
                                      I mean, it's not that surprising that you'll learn better in a stack you already know well - you know enough there to know what you don't know and need to learn. But if you don't know anything about a language, it will be very difficult for you to sort fact from fiction.
                                  • huqedato 5 minutes ago
                                    Learning Go after five years of professional struggle with Rust was a relief; Go feels designed for humans to just get the job done. (not a Google fan!) I'll get a ton of downvote for this but it's ok.
                                    • RobotToaster 3 hours ago
                                      Was anyone else expecting OpenClaw over gopher protocol?
                                      • coqadoodle 3 hours ago
                                        I was looking forward to retro deep-dive back into the 90s. I just couldn't figure out where the crab fit in.
                                        • SyneRyder 1 hour ago
                                          Yep, I did. While I don't use OpenClaw, I built a small MCP tool for my AI to use Gopher in a minimal harness, and it's been useful. Gopher is almost an ideal protocol for AI, none of the token verbosity of HTML. But I admit in my case, it's mostly being used to access weather data on Floodgap's Groundhog, because the format published on Gopher is much easier to parse & access than the paywalled government APIs in Australia. Claude occasionally uses Veronica to do a search instead of a web search as well.
                                        • wiseowise 1 hour ago
                                          Still better than deciphering C++ soup of characters.
                                          • cenamus 1 hour ago
                                            std::expected and the utility functions for it (and_then(), or_else()) are pretty much the same, though? Or am I completely misunderstanding something?
                                            • tialaramex 18 minutes ago
                                              It's true that `std::expected` is like if a C++ programmer saw a type like Result in a shop window and copied the parts they understood from that and so certainly if you're a C++ programmer this is superficially satisfying.

                                              The blog post uses, among other things, the Try operator ? and pattern matching, neither of which are available in C++ and both of which make the Result type much nicer to use than std::expected. There have been similar "I saw it in a shop window" proposals for both these in C++, and I expect that pattern matching in particular will be attempted again targeting C++ 29.

                                              • irishcoffee 50 minutes ago
                                                No, you’re not, the person you replied to is failing to look at their own criticism objectively.
                                            • nothinkjustai 2 hours ago
                                              Um? Person vibe codes Rust. Output is stupid. The conclusion is either

                                              a) Vibe coding produces bad code

                                              b) Rust is weird

                                              Somehow we’re supposed to accept b as the answer? Give me a break….

                                              • People really are forgetting how to think. While reading this blog post I almost immediately flipped into teaching confused freshmen taking the course that wasn't their major mode.