text
stringlengths
0
2.35k
**Jerod Santo:** Okay. That was an easy one.
**Break:** \[24:01\]
**Jerod Santo:** So I've said "idiomatic Go" a couple of times. I know that's a term that perhaps is falling in or out of favor -- or the term "idiomatic", I've heard either unpopular opinions, or maybe just conversations about "Let's not use that term." So whatever term you wanna put in front of Go that means kind of ...
Aside from using the formatter, which seems like obviously would normalize a bunch of code into some sort of idiomatic fashion that everybody thinks is good, what are some examples of common Go idioms, or things that you should be doing, that most Gophers do... I don't know if you guys have a PEP or something like they...
I think with looping, I kind of like the fact that there's really just one way. It's cool. But surely, there's other ways of doing things. Do you guys have some examples of "This is kind of a Go way of coding"? Or I've heard like writing Java in your Go, or writing Ruby in your Go. What are some things that are "idioma...
**Kris Brandow:** I think a lot of the way that we name things, especially around capitalizations... Like, one of the big, big differences between Go and other languages is how ID is capitalized. So if you have something that's like an identifier, it's capital I, capital D, and that is a very solid Go idiom. And I thin...
**Jerod Santo:** Oh, really?
**Kris Brandow:** But yeah, how you capitalize initialisms, and also constants in Go aren't supposed to be all caps. They're supposed to just look like regular variables. So I guess the idioms that always come to mind for me are those sorts of things, like how does Go look from that kind of perspective. Obviously, thin...
**Jerod Santo:** Sure. What about globals? Do Gophers like globals?
**Ian Lopshire:** I think globals are discouraged. We do have the init function, so they're supported. I think they're discouraged in the community.
**Jerod Santo:** \[laughs\] You're discouraging me from using them, Ian...
**Ian Lopshire:** I would discourage you from using globals, yes. I mean, of course there are times when you want to use globals, and it makes sense... But outside the main package, I would almost say "Don't use them."
**Kris Brandow:** Yeah. That's what I was gonna say. You can use them in main and you're alright, but certainly, if you have your own library -- if you're providing a library, you shouldn't use them. And certainly not use them if they're public. There's some cases for private globals, but public globals just get you in...
**Jerod Santo:** \[28:07\] Okay. So one thing Mat Ryer has told me, a pattern that he observes is like his main function doesn't do very much. It's basically like calling the rest of his program. Is that Mat Ryerism, or is that like a Gopher good idea? The programs I wrote, main - everything's in there, except for like...
**Ian Lopshire:** I think that is... There's different forms of this you see in the community. Sometimes you see, like, it's literally one line in the main, and then the rest in a different package. But I think the idea of keeping any kind of business logic, any of that out of main is pretty ubiquitous in the community...
**Kris Brandow:** I feel like it's maybe not an idiom. I feel like it's still somewhat contentious, because... I hate this pattern. I really don't like this pattern much at all.
**Jerod Santo:** \[laughs\] Here comes Kris now with the honesty. See how he eased into it, he's like, "Nah I'm done. I hate this pattern."
**Kris Brandow:** I get the intention of it. We wanna make everything testable, but I feel like that kind of ignores a lot of the other things that make it testable at the end of the day. Ripping all of the guts out of the main function, so you could put in another function you can run and go test... It doesn't fix a p...
And I also think it discourages people from kind of running the whole binary and putting that under test, and figuring out how to test the application as a whole maybe outside of the Go testing library. It's kind of like a way of escaping around and saying "Well, I don't have to do this anymore, because I can run all o...
**Jerod Santo:** Hm. Ian, your response.
**Ian Lopshire:** So the practice that I generally use is I do end up with pretty big main files, but all it does is set up dependencies. I understand what Kris is saying; you probably should be doing some testing outside of, like, as a whole, but I think just keeping the main small probably does encourage better testa...
**Jerod Santo:** Right.
**Kris Brandow:** I'm gonna counterpoint that for a second...
**Jerod Santo:** Please do... Now we're having fun!
**Kris Brandow:** I mean, I see this argument all the time, of like "It gets us a step in the right direction." But I really do -- like, a lot of the codebases I've seen that enact this skinny main thing do really just forget about setting up proper configuration, having configuration be sane, having the bootstrapping ...
It's one of those sneaky things that's like "Well, this feels like progress", but it's actually progress leading you to like a dead end in the maze, unless we're gonna try and scale the walls of the labyrinth we've gotta turn around and figure out a different path forward.
**Jerod Santo:** I love the analogy.
**Ian Lopshire:** I'll give you that, that it does provide kind of a way out, and can let us not do things we should be doing... So I'll give you that one.
**Jerod Santo:** \[31:59\] Right. Some of that's like -- you know that old saying about laws, like they keep the honest people honest. Some of this is like these idioms or these patterns will keep the people who are gonna do good tests doing good tests. But the one who wasn't going to anyway, whether they shove it all ...
So I can see that, where it's like "This is a good pattern. It helps you do this thing that..." The problem is we're not doing that thing anyways. So it doesn't fix that particular problem.
**Kris Brandow:** I would actually say there too that's kind of what differentiates what I would consider an idiom in Go from just like a practice that people are trying to make, or a best practice. I feel like most of the idioms - really all of the idioms we have are these deeply-nuanced things. Sometimes we can give ...
**Jerod Santo:** Hm. So if I wanted to learn a bunch of Go idioms, would you suggest reading Go Proverbs? Would that be the suggestion?
**Kris Brandow:** Yeah, yeah. I think Go Proverbs still apply. I think some people think that they're dated, but I think that they are pretty good. I think also code review comments, which is this thing that's in the Go GitHub wiki, is actually pretty good. Those are also pretty much like idioms, ish... There's some id...
**Jerod Santo:** Nice.
**Ian Lopshire:** The Go Proverbs were actually something that kind of drew me into Go. The first time I read all of those, I was like, "Wow. These all make a lot of sense." I don't think they're dated.
**Jerod Santo:** They resonated with you.
**Ian Lopshire:** Yeah, definitely.
**Jerod Santo:** Okay, so there's a good litmus test perhaps for the Go-curious. If you're wondering if Go would speak your language, or speak to you, is go read the Go Proverbs and see if you agree, or if they're saying things that you think make sense; or maybe it's unpalatable for you, then maybe look elsewhere. So ...
Let's talk about web apps. This question actually came in from Twitter. "Is Go and the ecosystem in place where it can compete with Rails/Laravel/Django for dynamic websites?"
**Ian Lopshire:** I don't think so.
**Jerod Santo:** Okay... Honesty.
**Ian Lopshire:** I mean, that's a style of development that I don't think Go is particularly suited for; those big, monolithic, server-side-rendered apps. I'm just not sure it makes sense in the frame of Go.
**Jerod Santo:** What is it about the language or the ecosystem that makes you say that? Is it the strong typing, or the fact they're dealing with dynamic, user-generated content, or what is it?
**Ian Lopshire:** I think it's a lot like the distrust of magic. If you think about Rails or something like that, or Wire... Is that the new Rails? Like, dynamic frontend bit...
**Jerod Santo:** Hotwire?
**Ian Lopshire:** Yeah, Hotwire. All of that just does things, and you have no idea what it's doing. And I think that's not tolerated well in the Go community.
**Jerod Santo:** So let me translate that and see if I'm picking up what you're saying here... Because dynamic web apps, that have a lot of user-generated content or input, building those at scale - I don't mean scale of users, but breadth of surface area; lots of forms, lots of pages, lots of what-have-yous - requires...
**Ian Lopshire:** \[36:06\] No, that is what I'm saying.
**Jerod Santo:** Okay.
**Ian Lopshire:** As you say it back, I'm not totally sure I agree with what I'm saying... \[laughter\]