496
you are viewing a single comment's thread
view the rest of the comments
[-] firelizzard@programming.dev 7 points 1 year ago

I've been working primarily in Go for the past five years, including some extremely complex projects, and I have never once wished I had dependency injection. It has been wonderful. I have used dependency injection - previously I worked on a C# project for years, and that used DI - but I adore Go's simplicity and I never want to use anything else (except for JS for UI, via Electron or Wails for desktop).

[-] CodeBlooded@programming.dev 9 points 1 year ago

Go programmer here: What does Go’s simplicity have to do with dependency injection? What does a language itself have to do with dependency injection?

Reading your post and not being personally familiar with your work, I do wonder, perhaps your “extremely complex projects” wouldn’t be so extremely complex if you practiced dependency injection?

How do you unit test your extremely complex projects if your business logic carries the additional responsibility of creating objects?

[-] fuck_u_spez@lemmy.fmhy.ml 2 points 1 year ago

I say it's all about data flow and composability, if it's pretty much always in one direction (modular tree structure/architecture) then you just don't need all these "patterns"...

[-] firelizzard@programming.dev 1 points 1 year ago

What does Go’s simplicity have to do with dependency injection?

In my experience, following Go's philosophy of simple solutions eliminates the need for complex solutions such as dependency injection.

How do you unit test your extremely complex projects if your business logic carries the additional responsibility of creating objects?

I write modular code that accepts interfaces so I can test the components I want to test. The vast majority of object creation happens at initialization time, not in the business logic. For the projects I've worked on, that would be true with or without DI - I don't see how that's relevant.

perhaps your “extremely complex projects” wouldn’t be so extremely complex if you practiced dependency injection?

When the CTO says, "Make it distributed and sharded," I do what I'm told, but that is an intrinsically complex problem. The complexity is in the overall behavior of the system. If you zoom in to the individual execution units, the business logic is relatively simple. But the behavior of the system as a whole is rather complex, and DI isn't going to change that.

[-] occams_chainsaw@programming.dev 1 points 1 year ago

I write modular code that accepts interfaces so I can test the components I want to test.

basically dependency injection

[-] firelizzard@programming.dev 2 points 1 year ago

How does dependency injection have anything to do with writing tests? I write tests by writing a test function that executes the code I want to test...

I mean unit tests. I work on Spring Boot apps where there are distinct layers (controller -> service -> persistence), and you generally inject mocks into your object to isolate tests to the specific code you want under test. One benefit of this approach is that it's pretty easy to get 90% coverage.

[-] fuck_u_spez@lemmy.fmhy.ml 4 points 1 year ago

... until you've heard of Rust :)

(I think Go takes all mediocre language features together and makes an even more mediocre language TBH, take error handling for example, or generic programming (which I agree should be used sparingly, but is super useful if you need it))

[-] interolivary@beehaw.org 5 points 1 year ago* (last edited 1 year ago)

Go does have generics nowadays, although they have some limitations (like pointer types being inefficient because reasons).

But yeah I'd tend to agree. Go's strength and explicit design goal is that it's relatively easy to learn and get started with, meaning it's fast to onboard new devs. It's very much a "get shit done" language.

Its weakness is – to paraphrase someone's criticism of Go – the core dev team's extreme unwillingness to adopt any programming language and tool chain designs and patterns invented after the 70's. Pike's rationale against generics was that in cases where you'd normally reach for generics you can either use interfaces (and especially interface{} which is like Go's void* and throws all type information out the window and is slower than proper types because reasons), or just copy and paste code. Because what you as a developer want to do is reimplement something like Find(needle SomeType, haystack []SomeType) for the Nth time in every project, or take a performance hit and lose all type information by using interface{}.

And don't even get me started on how long it took for Go to get proper dependency management and what the arguments against it were, Jesus fuck.

Go is currently the language I'm most fluent in after having written mostly Go for something like 8 years or even more (I remember when error was Error, pre 1.0 I think) and the one I'd be the most productive in, which is sort of unfortunate since I really don't like it as a language 😁 Learning Julia at the moment though, since I'm going back to the university to study some more computer science and maybe get into evolutionary algorithm research, and Julia is a neat language for lots of different number crunch-y tasks (no I won't touch Python, significant whitespace is a crime against common sense and fully dynamic typing gives me the heebie jeebies)

[-] firelizzard@programming.dev 2 points 1 year ago

I've heard of Rust. It sounds noisy and even more verbose than Go, which is already a fairly verbose language. I haven't had any reason to learn Rust, so I haven't done so. The error handling is annoying but at this point I don't really notice it any more. And as interolivary said, Go has generics now.

[-] tatterdemalion@programming.dev 2 points 1 year ago

Do you write unit tests with objects mocked via interfaces? Or polymorphism via interfaces? Those are the main reasons to use DI.

[-] firelizzard@programming.dev 1 points 1 year ago

I use various strategies depending on what seems appropriate, including the two you mention. I've never felt the lack of DI.

[-] fuck_u_spez@lemmy.fmhy.ml 1 points 1 year ago

I guess I have to start calling function invocation with generic parameters, fancy names (like "dependency injection" ^^)

this post was submitted on 08 Jul 2023
496 points (97.3% liked)

Programmer Humor

19503 readers
1241 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS