Solemarc ,

At work we have a lot of old monolithic OOP PHP code. Dependency injection has been the new way to do things since before I started and it's basically never used anywhere.

I assume most people just find it easier to create a new class instance where it's needed.

I've never really seen a case where I think, "dependency injection would be amazing here" I assume there is a case otherwise it wouldn't exist.

lorty ,
@lorty@lemmygrad.ml avatar

Isn't the point of injecting classes so that you don't have tens of instances of the same class in memory?

epyon22 ,

When we implemented it significantly improved our ability to write unit tests. It also allowed us to make more modular code due to the default of every class having an interface. So I'm all for it.

MajorHavoc ,

Yeah. Injection has a place in test patterns. Thankfully, it's usually possible to hide injection from strongly affecting anything else that matters, as long as the team hates injection deeply enough.

porgamrer ,

In my opinion dependency injection solves a problem that doesn't need to exist, and does it by adding even more obfuscation and complexity.

The problem is that the original gang of four design patterns had very little to say about managing effects. In old java code things like network and file IO often happen deep inside the object graph, hidden behind multiple impenetrable abstractions such that it's impossible to run the logic without triggering the effect.

The wrong solution is to add even more obfuscation and abstraction, so that you can inject replacement classes deep inside the object graph where the effects happen. it solves the immediate problem of implementing tests, but makes everything else worse and more confusing.

The right solution is to surface all your effects at the top level of the call graph. The logic only generates data, and passes it back up to the top level of the program. The top level code then decides whether to feed this data into an effectful operation. Now all your code is easier to reason about, and in you can easily test the logic without triggering unwanted effects.

MajorHavoc ,

Could be. There's easier ways to minimize instances in memory. That's what GLOBAL variables are for.

P.S. I have now gone: 0 days without trying to wind up other senior developers.

xmunk ,

As a fellow PHP dev (working in laminas specifically) DI actually is fucking awful, there's a distinction between a service factory pattern and this thing called DI which is similar to a service factory pattern but uses reflection based type sniffing to guess at which service you want where. I'd considered making a reference to it but PHP developers are few and far between these days.

VantaBrandon ,

There are dozens of us

steventhedev ,

XML is the second worst programming language ever created by humans

nxdefiant ,

I'm gonna need a bell curve hooded figure meme template of this comment, this is comedy gold.

marcos ,

Good luck deciding where each opinion goes.

SpaceNoodle ,

It's a markup language, not a programming language.

towerful ,

Like yaml/toml

marcos ,

The one benefit of toml is that nobody creates a programing language over it.

nxdefiant ,

so far

MajorHavoc ,

The one benefit of toml is that nobody creates a programing language over it.

Heh. Any day though, right? I can't wait to see an excited presentation on code-free coding in YAML...

frezik ,

Github Actions have entered the chat.

MajorHavoc ,

Thanks. I hate that you're right.

steventhedev ,

Whoosh

Seriously though, spring configurations are written in XML and you create variables, call functions, and have control flow. Effectively turning XML into a horrible twisted shadow of a programming language.

All in the name of "configurability" through dependency injection.

lars ,
@lars@programming.dev avatar

Spring moved away from XML ages ago. I work on a 6 year old Spring project and it has never had a single line of XML in it.

MajorHavoc ,

I'm fond of saying that all great code earns it's right to become good code by starting as trash...

But I still think we should all quietly and politely let Spring die a simple dignified death, as soon as possible.

Out of wildly morbid curiosity, do Maven and Ant still shit all over each other to make sure no one has any real idea what the build inputs and outputs are?

I shouldn't ask things I don't really want to know, though. My inbox is gonna be full of Java apologists.

lars ,
@lars@programming.dev avatar

No idea, I've never used either of those tools.

I think some people still use Maven, but I use Gradle in all of mine. Gradle build files are written in Kotlin instead of XML like Maven.

MajorHavoc ,

No idea, I've never used either of those tools.

That's a relief to hear. They were quite bad. Or rather, the way most teams used them was quite bad.

I've heard nice things about Gradle. Of course that was mainly from people with deep psychological scars after working with Ant and Maven...

JustBrian7872 ,

Thanks, my companies' codebase feels old now.

AMDIsOurLord ,

So if you take XML, pervert it beyond recognition, cut off it's balls and one hand, then it's somehow it's fault that it sucks?

steventhedev ,

They started from XML. There's nowhere to go but up but spring managed to fuck even that up.

FactoryStrategyFactoryFactoryObserverInterface

Friends don't let friends use Java 😜

dohpaz42 ,
@dohpaz42@lemmy.world avatar

Tell that to SOAP.

deadbeef79000 ,

Yo dawg, I heard you like XML over HTTP so I put XML over HTTP in your XML over HTTP.

frezik ,

It was a markup language until someone decided to parse and execute it as a programming language. This person should be watched for other deranged behavior.

ZILtoid1991 ,

I use XML as markup language, what kind of deranged person thought to turn it into a programming language? My problems with the Lua API led me down the rabbit hole of making my own VM and implementation, not looking at a markup languge, then go "what if I used this for scripting?".

frezik ,

When they make XML do these things (or the way Github Actions does it with YAML), they're essentially creating a representation of the AST that the compiler would make internally from a mini language. So there's a few possibilities:

  • They don't know how compilers work and reach for a tool they do know
  • They know, but figure the problem at hand doesn't need the complexity of a mini language and start the project the quick and dirty way, and it gets out of hand as they add features
  • They may or may not know, but they do get caught up in the hype of some other tool (likely what happened with XSLT)
cAUzapNEAGLb ,

I fucking hate Spring.

The quickest way to get a team of 10 contractors to turn 100 lines of basic code from a decent engineer into 2k, with 50 janky vulnerable dependencies, that needs to be babied with customized ide's and multi-minute+ build times and 60m long recorded meetings.

Fuck Spring.

passepartout ,

Wouldn't want to write a webserver / database connection / scheduler / etc. from scratch. Spring Boot plus lombok turns 2k lines of code into 100.

MajorHavoc ,

... Looks both ways...

Python does the same in 10 lines of code.

... Ducks under a table to avoid the ensuring flames ...

SpaceNoodle ,

I replaced the P in my LAMP stand with Python and I've never been happier.

MajorHavoc ,

Same here.

VantaBrandon ,

They say he's still ducking to this day

MajorHavoc ,

Yep. That's why we call it "duck typing" in Python.

expr ,

Sure... That"s what libraries are for. No one hand-rolls that stuff. You can do all of that just fine (and, actually, in a lot less code, mostly because Java is so fucking verbose) without using the nightmare that is Spring.

SpaceNoodle ,

They can do that in any season

dohpaz42 ,
@dohpaz42@lemmy.world avatar

Ok, you win! 😁 😂

MajorHavoc ,

Fuck Spring.

Actually, there's a lot to be said for being able to configure your spleamtomoter without needing to reverse the polarity on the stack cache rotator arm.

I'm kidding.

Fuck Spring.

xmunk ,

We're struggling to deal with climate change and these selfish developers can think of nothing except building more factories. This is a global issue, we need a global solution: eschew factories and services for defining everything globally.

Pyro ,

Hello inject me with beans please

not again

Klear ,

Yeah, I'd rather get injeancted with beans.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • kbinchat
  • All magazines