1. 13

    Love the corrections, and I agree that it is weird that this tutorial uses Gin of all libraries to show of writing APIs with Go - Gin doesn’t even conform to the standard library’s net/http interfaces, you have to wrap any middleware that does conform.

    One small nit-pick around the IDs, and it’s not even your improvements, but when you’re writing an API you should never (seriously can’t think of one reason why you should) let the user set record IDs. Ideally that should all be in the database (which is why using an in-memory database is an…odd choice).

    Overall, Russ’s comments about the tutorial irk me a bit - if you want something narrow in scope, don’t choose to do something like a full-on RESTful API. Sure, it’s basic and common like spaghetti and meatballs, but like spaghetti and meatballs it takes a lot of work and a surprising amount of complexity to make it truly good. Like, auth is integral to how APIs work, interacting with a database is a key part of the API. Either give a disclaimer that those parts are going to be glossed over, or change the tutorial title to reflect that you’re focusing on RESTful endpoints or something.

    I’m probably coming off overly grumpy about this, but I really love Go and I think we can do better when it comes to teaching aspects of the language. The rest of the documentation and (official) tutorials are incredibly good, no reason this can’t be as well.

    1. 6

      These comments resonate with me – thanks.

      I agree about the caller not having to generate the ID: I should have made that change too. :-) I’ve added a comment pointing this out and linking here at the bottom of the Unique album IDs section.

      1. 2

        I’ve been quite happy with using chi.

        1. 2

          Me too. All new Go work I’ve done that justifies using something beyond the standard library has used Chi.

      1. 1

        I’m of the mind a mix of both is good. The first programming class I took used Python, which made it easy to translate my thoughts into a working program. Then, pretty early on in my CS track one of my classes had several assignments where we had to interpret assembly (I forget the instruction set). That got me to “think like a computer” and understand how my programs worked more than any other class I’ve taken.

        1. 3

          Scany adds some quality-of-life improvement on top of pgx by eliminating the need to scan into every field of a struct. However, the desired field names must still be listed out in a SELECT … statement, so it only reduces boilerplate by half.

          I personally don’t feel like that counts as boilerplate. But maybe someone with more expertise in SQL queries can tell me why using a SELECT * would be better than listing the fields. Or maybe I just don’t mind taking a little extra time to be explicit because I prefer it.

          And I don’t see the difference between writing the SQL statements in my Go code as strings and writing them in a SQL file and using code generation to generate Go code with the queries in…a string. I dunno, maybe I’m more allergic to code generation than the author.

          1. 3

            SELECT * means you’re getting an unbounded mess of all the columns, while listing them individually means you’ll both only get what you need, and your query will break if the table structure changes. It’s generally better according to the SQL book I read recently.

          1. 0

            In other words, use common sense. Who would have thought?

            1. 37

              Appeals to common sense only work for intuitive and empirical phenomena. Nothing about programming is intuitive, though, and most programming methodology is non-scientific.

              In this particular example, I have heard people use “common sense” as a justification for YAGNI, a polar opposite position, which suggests that there’s nothing common or sensed about the opinion.

              1. 9

                Considering how dogmatic some developers can be, stuff like this needs to be said more often than you’d think.

                1. 7

                  Saying “use common sense” isn’t useful or informative to most people.

                  1. 4

                    Common sense is not as common as you’d think.

                  1. 6

                    I wish this included some explanation of why these are useful or explanations of why they are. Like, why use zerolog over logrus/zap/whatever? Why use gorilla/mux over gin or go-chi or the standard library? Why have that overly-complex unique code thing to determine where a logged error is thrown instead of making sure your errors have stack traces?

                    1. 4

                      I’m not the author of the post, but I can try to answer some questions:

                      Like, why use zerolog over logrus/zap/whatever?

                      zerolog and zap is what the author of logrus admit he would write if he wrote logrus/v2. zerolog claims to be a “better” version of zap (there are claims of performance improvement on other people’s computers)

                      Why use gorilla/mux over gin or go-chi or the standard library?

                      gorilla/mux is much lightweight as opposed to gin which has renderers, etc… Also, there are claims of very high performance on other people’s computers. With gorlla/mux you can plug your own json de-/serialization library which is faster than gin’s.

                      Why have that overly-complex unique code thing to determine where a logged error is thrown instead of making sure your errors have stack traces?

                      ¯\(ツ)/¯ No idea… The unique code approach feels very hacky and brittle to me.

                      1. 3

                        I would even suggest “httprouter” as a more lightweight alternative to gorilla/mux.

                        1. 2

                          Most “higher level” Go routers are probably based on it anyways.

                        2. 1

                          We use unique logging codes for our logs, and it makes it easier to locate a particular statement in either the logs, or the source code. Now, we generate the unique code by hand, but it’s not a horrendous issue for us (we have a separate document that records each logging statement).

                        3. 1

                          I’d be curious to know the best practices for annotating errors with stack traces. Any good library suggestions?

                          1. 3

                            github.com/pkg/errors has some nice helpers, as described in its documentation. The issue is that it requires changing your code to using errors.Errorf() instead of fmt.Errorf().

                            Go2 will do it differently, but natively

                            1. 3

                              Also, errors.Wrapf is very useful when handling errors from packages which don’t use errors.

                              1. 2

                                You can wrap errors using fmt.Errorf() and the %w verb, and then later deal with them using errors.Is() or errors.As() and friends.

                                1. 1

                                  That doesn’t give you stack traces though, correct?

                              2. 2

                                YES. This is probably my biggest issue with supporting production Go code. Errors are still too hard to locate.

                                1. 1

                                  I personally use this to manage all that. If you use the errors.Wrap() function to wrap errors, it’ll add stack traces. And if you want to make a new error, the errors.New() function will also add a stack track where it was called. Then when you’re logging the error make sure it’s being logged in a way that will not just print the message. Most loggers should have a way to do that (I know zerolog and logrus do).

                                  1. 1

                                    Shameless plug for my errors library: https://pkg.go.dev/github.com/zeebo/errs/v2

                                    • captures stack traces, but only once even if wrapped multiple times
                                    • plays nicely with standard library errors package with errors.Is and errors.As
                                    • has a “tag” feature to let you associate and query tags with errors
                                    • helper to keep track of groups of errors
                                1. 2

                                  I mainly use Mail.app, and it’s…okay. Not bad, not great. No external editor integration (unless copy/paste counts), threads are pretty good, HTML is good but some load slowly (Patreon emails, mostly), and filtering is responsive and relatively easy to do (you can even set up “smart mailboxes” which are really just saved searches).

                                  I’ve been trying out aerc as well, but I’m kind of meh on it right now. I want to move to a more emacs-y setup, but I don’t want to take the time right now. It’s kind of a “good enough gets in the way of better” thing - Mail.app covers my use-cases well enough without enough pain to motivate me to explore other options.

                                  1. 1

                                    This is a neat way to do this, but I’m not personally a fan. I don’t want to keep the overhead of remembering what’s where, I’d rather have one big rc-file for my shell. I haven’t ever had a need to disable these things either. But things like this are why I love scripting with Bash, and I always learn something.

                                    1. 2

                                      I bet you’d like zsh scripting even more than bash. I read the zsh docs in detail and it offers dozens, if not more, of conveniences that improve my sanity.

                                      1. 1

                                        I’m sure you’re right, and I really want learn zsh scripting more thoroughly. It’s my shell, but I haven’t really taken the time to do more than its bash interop.

                                    1. 2

                                      I’ve been wanting to explore writing web services in Rust, but I don’t really want to do it on nightly (mostly because I want to potentially present it to higher-ups as a viable option for development at my employer, and I feel that using the “stable” branch will be more appealing to them). This is definitely a big plus for me, and I’m excited to try it out.

                                      1. 1

                                        I am going to be modding one of my guitar pedals! It’s not my first dive into soldering and electronics, but I’m excited because I’ve been growing more and more interested in audio circuitry, especially tube amplification and effects pedals. I’m hoping it all goes well and leads to a new hobby.

                                        1. 11

                                          This is a helpful article for me, thank you for posting!

                                          Does Lobsters allow posts like these, though? It’s a great article, but includes an ad for a service as the last section.

                                          1. 9

                                            It’s a useful article until then so it’s worth letting the votes govern its relevance, imo.

                                            1. 6

                                              I’d say there’s a difference between “here’s some useful Rust stuff, btw use our logging SaaS at the end” and “here’s why you should use our logging SaaS”

                                              1. 5

                                                Author here, glad you like it.

                                                I will add a conclusive sentence to make the distinction between the article and the advertisement clearer.

                                                1. 1

                                                  Thanks for the article, I didn’t mind the ad. Do you inspect the stack frames non-intrusively via sampling?

                                                2. 4

                                                  if it’s not too intrusive its okay, for example when you can read the article without the ad and you don’t miss big parts of the post

                                                  1. 3

                                                    Personally, I don’t mind it. There’s a lot of great and interesting content out there published by companies that usually includes some sort of “ad” for their service. I don’t want to cut that out just because they say, “hey, use our stuff” at the end. Especially because I can just ignore the ad bit and still learn something.

                                                  1. 5

                                                    Looks really nice, clicks the right buttons… But sadly I need a split keyboard for health reasons ;-(

                                                    1. 11

                                                      May be someone could make a fork :D

                                                      1. 3

                                                        I highly recommend gboards.ca for split keyboards, but I’ve also heard people say good things about the Moonlander (from the ErgoDox EZ folks).

                                                        1. 3

                                                          I’m one of those Moonlander boosters. Using it right now!

                                                          But I do have a caveat: I had to relearn how to type on the ortholinear layout. My typing speed plummeted at first. I had never learned touch typing and was apparently “crossing over” for a bunch of keys like “y” and “6”. Now I’m faster than I was before and back into to realm of “think about the words” rather than “think about the fingers”.

                                                          1. 1

                                                            The moonlander is easily my favorite keyboard. I just bought a second one for my work desk.

                                                            1. 1

                                                              Would love to see a direct comparison between the moonlander and Ergodox EZ. I have a (self built) Ergodox and I’m a big fan. But I wish I could have one that is just a tad smaller with keys being a bit closer to each other.

                                                              1. 2

                                                                I saw this comparison video on YouTube (15 minutes, but indexed so you can skip to parts you are interested in) a few days ago and found it helpful. A friend of mine got the Moonlander and I have an Ergodox, so I hope to compare them for myself in the near future. I have loved my Ergodox and actually don’t find that the thumb clusters cause any trouble for me, so I doubt I will get a Moonlander anytime soon. I do envy the foldable wrist rests though. The ones for the Ergodox could pull double-duty as wheel chocks for a passenger plane and tend to wander away through a day of use.

                                                          1. 7

                                                            Doom has an active and helpful Discord. It’s actually the best place to talk about Emacs in general that I’ve found.

                                                            This is kind of sad to read. Is it related to Discord or the specific community?

                                                            1. 14

                                                              Hi I’m a moderator in the doom discord community. If it’s any consolation I have been trying to steer people toward using other resources available, particularly the mailing list.

                                                              I think we’ve grown the way we have because we’re not very strict about what the topic at hand is and understand that most users coming to doom emacs (and I expect spacemacs as well) are coming not from emacs but from vim or vim-likes and like to talk about lots of things besides emacs. This includes other text editors, games, operating systems, and more. Being off-topic is on topic in a lot of cases. Our community is also younger (at 33 I’m probably one of the oldest in the server) with lots of college and high school kids who’s online social life has been won by discord. We’re simply more approachable to them than most other emacs communities.

                                                              A lot of credit for the helpfulness can also go to Henrik who is both patient and gracious with new users and eager to help wherever he can. He sets a very friendly tone and I don’t think I’ve ever seen him troll, lighthearted or otherwise (thinking back I don’t think I’ve ever registered a swear word from him).

                                                              1. 5

                                                                If it’s any consolation I have been trying to steer people toward using other resources available, particularly the mailing list. […] Our community is also younger […] with lots of college and high school kids who’s online social life has been won by discord. We’re simply more approachable to them than most other emacs communities.

                                                                That is nice to know. As someone who is just around the “Discord generation” (22), I fear that I would have got caught up in that development. Emacs in particular was essential to my appreciation of Free Software, which is why I care about this. The other reason is that the dominance of Discord is something I often resent, as I get excluded from communities I could be interested in participating because of my own principles.

                                                                1. 2

                                                                  The other reason is that the dominance of Discord is something I often resent, as I get excluded from communities I could be interested in participating because of my own principles.

                                                                  In the linked comment you mentioned your hesitation to use an Electron application. Have you considered trying the Discord-Matrix bridge?

                                                                  1. 2

                                                                    I could use it (even if Matrix is a bit too slow for my taste), but my there point was not the specific server, as I don’t use Doom, but the general culture of organizing communities around Discord, a platform I would like to have nothing to do with in itself.

                                                                    1. 2

                                                                      The discord-matrix bridge allows you to communicate with a community using Discord while giving you the option of using a matrix client, which is better than being forced to use the discord client. But this requires cooperation from the moderators of the discord guild, and still doesn’t solve the problem of Discord interfering with communications on what is fundamentally their platform.

                                                                      1. 1

                                                                        I read that using a third party client can get your account banned for life since it is against the terms of service.

                                                                    2. 2

                                                                      That matches my experience. Henrik is amazingly patient for someone whose project blew up into this huge thing. I wish I could match that.

                                                                    3. 2

                                                                      As someone who uses customize almost exclusively to configure my Emacs environment, I’m curious why none of the popular Emacs enhancement frameworks use it. I found this comment in the Doom repo—does anyone have insight into what they mean here?

                                                                      ;; Doom doesn't support `customize' and it never will. It's a clumsy interface
                                                                      ;; that sets variables at a time where it can be easily and unpredictably
                                                                      ;; overwritten. Configure things from your $DOOMDIR instead.
                                                                      
                                                                      1. 1

                                                                        AFAIK a lot of people do not like that customize writes code, that makes code (slightly) harder to version. Doom is opinionated, so I guess they decided to not be interested in preserving that mode of configuring.

                                                                      2. 1

                                                                        Not sure - but I will say that the community on the Doom Emacs Discord is very friendly and very helpful, and also active. So if you ask a question you’ll probably get an answer fairly quickly.

                                                                        1. 7

                                                                          That might be the case, my issue is mainly that it is organized on Discord, which IMO shouldn’t be used for free software projects.

                                                                          1. 4

                                                                            I honestly actively do not care about that criteria.

                                                                            1. 1

                                                                              What do you mean? The usage of Discord per se or the usage of Discord by Free Software communities?

                                                                              1. 1

                                                                                I’m not going to derail this thread with my opinion on that.

                                                                                1. 1

                                                                                  Ok :/

                                                                        2. 1

                                                                          I don’t know, but I have yet to find as friendly a group to ask dumb newbie questions, as that one. And some of my questions are, sadly, still dumb newbie questions :)

                                                                          1. 2

                                                                            Out of curiosity, have you ever tried the help-gnu-emacs mailing list? There are all kinds of questions posted there all the time, from total beginners to Elisp developers.

                                                                        1. 3

                                                                          This is pretty cool. I do wish it weren’t so tied to GitHub, but that’s a minor quibble I can patch if I really wanted to.

                                                                          I personally see a lot of value in this because my team has a large number of repositories (in a self-hosted GitLab, hence my previous comment) that have similar structure - atlases for Kubernetes clusters. We have other tools in place to manage those in an automated fashion, but it could be nice to have a tool for manual intervention as well.

                                                                          1. 2

                                                                            I’ve developed a vaguely similar tool, gitall, that’s much more bare-bones than git-xargs. It works on locally cloned Git repos, so there’s no dependence on a particular forge. Right now, it only runs Git commands, but I have been thinking about adding functionality to run arbitrary shell commands/scripts.

                                                                          1. 14

                                                                            …this goes a lot deeper than I expected. You don’t often see a post that starts with “why do we have to say Box<dyn Error> instead of just dyn Error” and at the halfway point is in gdb looking at heap layouts.

                                                                            1. 3

                                                                              One of the many reasons I enjoy this blog. They go super deep on pretty much every post, and I always learn something. There was one a few months back about adding hot-reloading of symbols to a Rust binary, I learned a ton about ELF.

                                                                            1. 27

                                                                              I always suggest Go. If this is a project that will be “complete” soon, then you have good chances to release your code after years, compiled with newer versions of Go, without the need to rewrite it. (If you used standard library packages.)

                                                                              Unfortunately, writing CRUD in Go can be tedious because there are no generics, but this is fine. Later, when you realize that your abstractions where wrong, you will thank Go for the lack of generics anyway.

                                                                              1. 5

                                                                                If this is a project that will be “complete” soon, then you have good chances to release your code after years, compiled with newer versions of Go, without the need to rewrite it. (If you used standard library packages.)

                                                                                I’m sure this is more true today, but when I wrote a few Go projects several years ago, it sucked trying to compile them again on a new machine because the dependencies were all screwed up. I can’t believe Go went so long without good dependency management. Well, I guess I shouldn’t be surprised because there’s Python…

                                                                                In any case, Go-the-language was pleasant to work with. I hope the recent work on dependency management has made it much smoother to actually compile an older project.

                                                                                1. 2

                                                                                  Funny, I haven’t felt the pain of no generics when writing Go CRUD apps, but rather I’ve felt the pain of writing out a bunch of SQL queries and getting a nice “get all” endpoint for each object with filtering. I know ORMs are a thing, but I feel like they’re (almost) an anti-pattern in Go - at the very least I never see them recommended.

                                                                                  1. 2

                                                                                    sqlc is pretty great https://github.com/kyleconroy/sqlc

                                                                                  2. 2

                                                                                    JVM backwards compatibility is great too.

                                                                                  1. 2

                                                                                    I’ve not played Factorio yet but how long does a full run take on average? Or is it just time boxed regardless? Lol.

                                                                                    1. 3

                                                                                      There’s an achievement for doing it in under 8 hours (there are several finish-time achievements but the 8-hour achieve “there is no spoon” is the hardest), but realistically a noon will take a LOT longer than that for their first time. I’d guess 100+ hours, although that’s just playing the game for fun and without specifically rushing to rocket-launch.

                                                                                      1. 2

                                                                                        My first run was 100+ hours; speedrunners finish it in a little over 2.5 hours on default settings.

                                                                                        1. 2

                                                                                          It really depends on how hard you rush towards launching the rocket - the “game over” condition (quotes there because you can play beyond launching a rocket).

                                                                                          You could do it in a few hours if you rush and have an idea what you need to do. First time with no guides will probably be longer. Speedrunners can do it in about an hour - edit: hour and a half.

                                                                                          1. 5

                                                                                            A reasonably knowledgable pair of players, going in with a good premade plan, can launch a rocket in 3 hours. Default settings.

                                                                                          2. 1

                                                                                            My first play through was 40+ hours

                                                                                            1. 1

                                                                                              Personally I have played maybe 3 or 4 times and I always gave up before launching the rocket, after quite a few hours. I’m definitely not good at Factorio but this game is both quite difficult and truly great.

                                                                                              1. 1

                                                                                                I’ve dabbled in it for years, when 1.0 came out I finally did a full play through and it took around 30 hours.

                                                                                              1. 10

                                                                                                As someone who’s been thinking of trying out Plan 9, this seems to indicate there has never been a better time to do it.

                                                                                                1. 1

                                                                                                  I wasn’t able to gather if the source release is usable or not, seeing that it is 20 years old.

                                                                                                  1. 5

                                                                                                    It appears that there’s a raspberry pi image available, as well as others. Take a look under Download on the webpage http://p9f.org/

                                                                                                    Edit: there are more images here: http://9legacy.org/download.html

                                                                                                1. 1

                                                                                                  I get wanting to play around with k8s and containerization at home. I do that, and it’s neat. I’ve made stupid little operators for k8s that I run on kind on my laptop, I’ve put things like CLIs in containers as part of a build process to see how that works.

                                                                                                  I can even see why you’d want something facing the public internet, so you can really try out the networking/ingress stuff in k8s. But…a static site? I feel like that’s akin to building a cannery in your backyard because you want a tuna melt. But that’s my opinion, and kudos to this guy for doing something.

                                                                                                  1. 2

                                                                                                    I swear, I’m getting closer and closer to giving up on macOS as my operating system of choice. It’s been great, but things like this get under my skin a little. Now granted, this is low-impact for me currently - I don’t have remote login enabled on either of my laptops because if I want to access stuff on one of them I have physical access, and if I’m not near my personal laptop I’m probably at work and won’t need it or otherwise occupied and won’t need it.

                                                                                                    But if I had a desktop Mac? I could see allowing remote login. And I’d hate having to go through this every point release. It’s odd that they wrote the installer to just overwrite (what seems like) every file in the system folders when they could just overwrite the non-config files. But I suppose a blanket overwrite is easier for them to implement.

                                                                                                    1. 1

                                                                                                      Nothing will save you from shoddy engineering - whether its your own or someone else’s.

                                                                                                      It’s really easy to assume the happy path is the only one that things will follow and leave it at that, but that’s not a good assumption to make. I’m honestly more surprised when my test suites pass and builds succeed than when they fail - it keeps me prepared to fix things and from making hard promises of deployment times (talking down-to-the-hour times - I can be more broad without giving up wiggle room).