I've started to work with golang and I came from PHP(a good language to work with OO). But i've some questions about the world of golang. We've some good practices that are available for reading in some articles, blog posts and the official page. But, what is the guideline/good practices to build maintainable applications as we have in the OOP world like DDD, CQRS, Event-Sourcing, SOLID and other concepts. I know that we don't need to forget all these things, but how we can change it to be adapted to golang paradigm and structs.
I've found some repos, but i'm not fully satisfacted:
https://github.com/roblaszczak/go-cleanarch
https://github.com/CaptainCodeman/clean-go
Top comments (5)
Many OOP languages have a concept of classes. Go and other compiled-to-assembly languages have not done this to this day but Go is actually the closes OOP language that I've seen that is natively compiled.
As you've already seen, Go instead has
struct
s. These are a special data type so that the compiler can right the assembly to be as memory efficient as possible since withstruct
s, the compiler is going to be able to figure out exactly how many bytes an object will occupy.On to functions. As you probably already know when you call a function the parameters to that function can either be passed-by-value or passed-by-reference. In native languages, pass-by-reference are called pointers. Pointers are a new data type type that most higher level languages are able to abstract away from but require a basic understanding to understand why Go, Rust, and C functions are defined the way they are. In a high level language, you can make a
class
with object methods that can usethis
. In Go, all functions are defined in the top level and "this
" has to be defined as a pointer parameter. Kinda anyways. Let's see.vs.
See gobyexample.com/ for more!
Hi, Sean.
Thanks for your response.
You has tell me about the structure and how golang works when compared to OOP languages. But my main doubt is about the good practices when we are building applications, as the links that I put ahead.
Thank you again!
Hi, for SOLID, Go interfaces are actually really cool and I think this site would help a lot: gobyexample.com/interfaces
I also think this would be a good read, if you haven't read it already :D
The tragedy of 100% code coverage
Dan Lebrero
I would definitely recommend checking out this article - medium.com/@benbjohnson/standard-p...
While it won't answer all of your questions, it should help you get an idea of where to start. Another thing you can do is just experiment; write code and see what does/doesn't work for you. Its okay to realize later that what you wrote originally wasn't the best way and to refactor your code. That's part of the learning process :)
Thank you, Jon. That's what i was talking about.