this post was submitted on 02 May 2024
399 points (92.7% liked)

Programmer Humor

19623 readers
2719 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] tatterdemalion@programming.dev 24 points 6 months ago (1 children)

Say what you want about DI frameworks, but if I have to remove another fucking global variable so I can write a test, I'm going to cut a bitch.

[–] cadekat@pawb.social 7 points 6 months ago (1 children)

Dependency injection is so much worse. Oh, hey, where'd this value come from? Giant blob of opaque reflection code.

[–] Zagorath@aussie.zone 4 points 6 months ago (2 children)

It can be used in bad ways, but if it's used in the right way you should never have the situation you just described.

[–] cadekat@pawb.social 1 points 6 months ago (1 children)

I'm not exactly sure what you mean. Doesn't all dependency injection work the way I described?

Without being familiar with the framework, you can't trace your way from the class getting injected into to the configuration, even if you're experienced with the language.

[–] Zagorath@aussie.zone 2 points 6 months ago (1 children)

I don't think so. When I've seen it done it's usually not been random values injected (except when those values are secret keys which should absolutely not be stored in code to begin with), it's usually injecting a service. Another class, usually with a name that makes it easy to trace down. Like if you're building an OrderService, that might take as a dependency an IProductService, which would have injected into it the class ProductService (personally, I don't like the Hungarian notation that C# uses, but it's a convention and my preference for sticking to strong conventions for the sake of consistency outweighs my distaste for Hungarian notation). That's easy to find, and in fact your IDE can probably take you straight to it from the OrderService's constructor.

[–] cadekat@pawb.social 1 points 6 months ago (1 children)

I'm using value in the loosest sense, like how all objects are values.

So now if you have three implementations of IProductService, how do you know which one is configured?

[–] Zagorath@aussie.zone 1 points 6 months ago

It's easy to imagine a hypothetical way that could lead to problems. But in all the code I've worked with, either that scenario is avoided entirely, or other context makes it absolutely clear which IProductService is being used.

[–] grrgyle@slrpnk.net 1 points 6 months ago

Same could be said of a global. There's a time and a place for each.

One thing I'll say is I don't remember us needing a team of senior+ devs to handle web app back in the day...