Attached: 1547661062542.png (280x135, 7K)
Do you use dependency injection frameworks?
Colton Smith
Other urls found in this thread:
martinfowler.com
twitter.com
Cooper Harris
what is dependency injection
Jayden James
yeah but only because i'm lazy as fuck and don't want to think about stuff like that
Nathan Kelly
>javaids
wow, it's fucking nothing
Owen Torres
passing already constructed objects to other objects that need them instead of having them construct the needed object themselves.
Mason Moore
Seems simple enough, why do you need a framework for that
Liam Gonzalez
Like mixins in js?
Aiden Richardson
It's incredibly simple and you absolutely don't need a framework for it.
No
Henry Williams
It's supposed to be magical. You say you want a car object, so the framework analyzes the class, sees that it requires an engine object so it constructs it following the same rules recursively and then injects it into the car object before returning it to you. Engine is just an interface so it will fulfill it with whatever instance is appropriate (eg. based on configs).
t. made one for php as a school project, was fun seeing it do everything automatically
Jaxson Long
I use Spring. Guice just looks like cancer.
Brody Young
That is literally a reimplementation of normal construction, proxied through injection for no good reason.
Bentley Anderson
guice pays really well though
Evan Murphy
It's automated so you have to program less. Realistic example is injecting db connection object into very instance that needs it. Easier than doing it yourself and better than having globals since injection makes testing easy.
Robert Brooks
yeah but sometimes it's really annoying to build an instance of an object that needs an instance of an object that needs an instance of another object ad infinitum
Mason Gonzalez
Program less and configure more.
I prefer to program.
James Nguyen
Each object can construct the objects it immediately needs. If X depends on Y and Z and constructs them as needed, and A depends on X, A only needs to construct X, which will automatically construct Y and Z. You never have to manually construct the entire dependency chain every time you want to instantiate something unless you're doing something horribly wrong.
Nathaniel James
There's different ways like auto but like a configurable registry that can create instances. Assuming the letters are types, its like registering a(b,c), b(d), c(), and d=1 then saying gimme "a" and it returns a instance created like a(b(d),c())
Levi Perez
In my experience what you call "programming" is just an abstraction for configuration given a set of requirements.
It's not as if the projects you write are appreciably different. Always using the same databases, servers, etc.
How many of you guys actually do something other than CRUD/ETL?
I do. Tooling for automation of ops.
Benjamin Ward
All I'm saying is it's a pain in the ass to construct the entire fucking chain for a series of tests when it can be done in one fucking line.
Aiden Sanders
And all I'm saying is that you don't need to do any of that construction yourself if you just don't use dependency injection where it doesn't belong.
Kevin Edwards
you are supposed to mock away all dependencies in unit tests user
Liam Allen
Yeah, that's what the dependency injector does for me. I only tell it which component is under test and it fakes out the rest.
Jordan Morales
>It's incredibly simple and you absolutely don't need a framework for it.
You clearly have never had to construct a dozen different Factories and Builders passed into each other.
Kevin Carter
I use it, but I don't really understand how it works
Jonathan Rogers
just use the reader monad lmao
Christian Sullivan
This makes it sound like dependency injection is a kludge, and that the real problem is just Java in general.
Daniel Powell
Yes. If you don't know why you'd want to, read the first few chapters of this.
Jacob Jackson
>You clearly have never had to construct a dozen different Factories and Builders passed into each other.
You're right, and I'm proud of that. I don't usually shit on popular paradigms because I figure there has to be good use for them, even if I never run into them. But the shit you're describing just seems like absolute garbage, and a good indication that you just don't know the best way to structure your programs, so you're falling back to generic one-size-fits-all OOP patterns
Bentley Fisher
Of course. I don't want to litter my code with singletons that may or may not be threadsafe. As well as minimizing allocation overhead by instantiating everything at boot time.
Do you niggers even code
Adrian Perez
Microsoft.Extensions.DependencyInjection is all you'll ever need from a service locator in .NET.
Zachary Morris
yes we use guice at work
Levi Brooks
>brought to you by google
nty
Leo Morris
dependency injection is code smell
Jaxon Bell
I bet that library calls back home
Easton Lee
>Guice (pronounced 'juice')
Get fucked.
Jaxon Perry
sounds like security hazard
Hunter Lopez
This is fucking retarded and so bloated that I no longer wonder why modern software is shit.
Owen Morgan
ever heard of static singleton
Jacob Evans
guava is the shit though
Isaac Rivera
This
Henry Gomez
that's funny because i work in a guice shop and people say the exact same thing about spring
Isaac Bennett
Dunno about Guice but every IoC container I've used allowed for both singletons and to construct objects per class
Andrew Reed
The only thing that is retarded here is you.
William Phillips
found the googler
Isaiah Ward
Instead of developing Guice, Google should have just rewritten their entire codebase in Haskell, which actually has meaningful abstractions, as opposed to the non-abstract indirection crap that is "dependency injection".
Fuck Guice.
Adrian Harris
I don't see how this is different from constructing other objects in a constructor.
I don't see how this is different from passing parameters into a constructor.
Jaxon Richardson
>Haskell
>meaningful abstractions
ohoho
spotted the CS101 brainlet
Sebastian Rodriguez
>I don't see how this is different from constructing other objects in a constructor.
you never worked on large code bases
Justin Green
I don't use dependencies
Bentley Smith
DI frameworks can be nice for reducing the boilerplate that you would have if using constructors as you describe
suppose you have a system with a bunch of domain objects, foo, bar, etc. so more than likely you'll end up with a FooDao class, a FooService, a FooValidator, a FooSanitizer, and more than likely you'll have similar classes for each of your domain objects. rather than needing to pass each of these classes for each of your domain objects into a constructor, you instead declare in your DI module the existence of your FooValidator, Sanitizer, etc. and in your e.g. FooService class, you say "DI, give me an appropriate Sanitizer", and the DI framework handles the lookup of what the appropriate class to provide is.
Jonathan Wright
not just that, all your dependencies might be difficult to construct, and so are their dependencies, and so on, so on, it's nice to never worry about it and just do a single
@Inject
Christopher Adams
what do you mean by difficult to construct?
Robert Kelly
Eg: I want the validated security context of the current user, I could either inject it, or figure out how to construct all 50 classes in the dependency chain
Owen Carter
>pronounced 'juice'
Colton Thompson
The point of injection, as I understand it, is that you might want X to depend on an abstract interface that can be satisfied by either A, B or C, depending on runtime configuration.
(I wish someone would be able to offer a real-world example that isn't blatantly retarded, though.)
Tyler Phillips
we just gave one
Luke Martin
What, do you mean ? Maybe I'm just a dumb Python guy, but I cannot for the life of me understand why you would need to have multiple language objects to represent your domain object. What the fuck is a FooValidator, anyway? Is there a compelling reason in Java to not just write a .validate() method?
James Perry
>(I wish someone would be able to offer a real-world example that isn't blatantly retarded, though.)
Deploying stubs for external services on development machines, while the production build queries the actual services.
Nolan Flores
>Is there a compelling reason in Java to not just write a .validate() method?
sure, you could have all your domain objects implement the interface Validatable, or some such. although if to validate you need to provide some context, or make cache lookups, now you're introducing this stuff into your domain object class and writing messy spaghetti code
Ethan Martin
In java it's a way to make your code harder to read the flow of by constructing member variables of an instance by reading xml files at runtime that are embedded in the .jar file and different xml files are used depending on your config.
The same thing can be done by calling a static function to construct your member variables, but then it's less magical and confusing.
Zachary Hughes
It's easier to understand the flow of code if you write code instead of using external libraries that construct your data by using runtime magic using reflection and sometimes even xml files.
Also your IDE can't help you as much when you have config files.
Austin Taylor
guice doesn't use xml
Aiden Bailey
most based post in this thread
Brody Cooper
In reality it's most useful when doing unit tests on code that's calling database or some http stuff, because you can just mock those two things and inject them instead of the real implementations with little effort.
Gabriel Hall
found someone who either doesn't have dev job or writes untestable code.
This user knows his shit.
William Hernandez
>unit testing
I have yet to be convinced that it is not a waste of dev time and money.
Ryder Martin
>either doesn't have dev job or writes untestable code
Wrong on both counts.
I write microservices whenever possible. Every time I commit to any of them, our CI/CD tooling automatically redeploys the application and runs a full suite of integration and and E2E tests on an entire reproduction of our pipelines in a dev environment. I have the shortest average dev time and some of the most stable code in the company because of that setup, and a few other devs have recently started picking up my preferred methods.
I do not usually write unit tests. I have almost never found them necessary in properly architected code bases.
Blake Powell
Every non-trivial professional software project is at some point going to expand to the point where it's impossible for any single programmer to have a complete and full understanding of the ins and outs of every procedure in the code, which means that after that point, any time you are tasked with changing some core piece of functionality you're going to have to spend 5 to 20 minutes crawling through the dependencies of the code you are trying to change to ensure your proposed change isn't going to cause anything unexpected to happen during runtime.
Properly written unit tests allows you to be a lot more reckless with your changes, since if you break something, the test will let you know exactly what part about the method you just changed and it's larger role in the system you misunderstood.
Unit tests also allow you to get new programmers up and contributing quicker since they won't have to be afraid of making breaking changes.
The problem is that 95% of all enterprise programmers are absolutely fucking trash when it comes to testing.
Julian Cruz
sometimes, unit tests are good
sometimes, they are more trouble than they're worth
whether to use them or not needs to be the decision driven by an experienced developer
not e.g. 100% code coverage mandated topdown by management removed from the actual code base
Elijah Morgan
>instead of writing a tool to solve a problem, Google should have shut down and spent billions of dollars and a decade rewriting all of their working code.
This is why you aren't successful.
John Mitchell
No, it would be the opposite. It means that if you were to change the class constructor signatures, you'd only need to do it in one place which prevents potential issues that arise when refactoring.
Angel Ward
there is a Scala feature that sounds similar but not that retarded, dont remember the name but it basically selected parameters for construction automatically based on what is needed and already in scope, basically just removing the need to hand over everything to constructors
Luke Hernandez
i wish i could understand dependency injection
Leo Campbell
Underrated point. If you're going to automate real-ish E2E testing then yeah you wouldn't need to DI + mock unit tests. We DI at my job but almost only do E2E so it's kind of pointless. This thread is a reminder that I should do more mocked unit tests. Thanks neets.
Your future self will forget what makes some block of code work vs. break and you'll be glad there are tests as proof that your changes don't fuck everything up. But yes, your fizzbuzz doesn't need test coverage.
Bentley Thomas
It's a good example of dogshit CS pedagogy because of how nobody seems to bother splitting the concept up into its parts.
Suppose you have some class that takes an instance of another class as part of its construction. Rather than being responsible for spinning up both at once DI just means some over-arching container either already has the dependency instance waiting or can go get it on your behalf. In either case you the developer just consume the interface rather than the instantiation.
Kayden Gonzalez
Not really underrated, any testing book will tell you you're supposed to use both unit tests and E2E tests, not one or the other.
If you write a new function that builds a URI from a bunch of strings and you want to make sure you didn't forget a separator or that it handles optional values correctly, going through a full deployment/integration tests cycle when you can just assertEquals(buildURI(), "/a/b/c/d") is extremely inefficient at best.
That guy was just bragging about his perfect workflow all his colleagues are jealous of but it's probably not as good as he makes it sound like.
Christian Perez
Why yes, a static stringbuilder utility would be a good candidate for unit test coverage. We were talking about E2E as a substitute for mocked integration calls e.g. DB, HTTP.
Thomas Rivera
Imagine ClassA needs to set ClassB string property value. Inside ClassA, you can make an instance of ClassB. Then, set ClassB string property like so.
ClassA {
var classB = ClassB();
classB.string = "foo"
}
There are different types of dependency injection.
For example, using constructors or initializers
ClassA {
ClassB classB = new ClassB(string:"foo");
}
With dependency injection, an object (classB in the example) doesn't configure its own components (string property in the example).
Ethan Foster
This is the correct answer
Daniel Richardson
Object oriented programming is completely retarded, yes.
Carter Campbell
>I don't see how this is different from passing parameters into a constructor.
Creating them manually like a(b(d),c()) is what dependency injection literally is, any required dependencies are passed to the object instead of the object creating them internally. That's completely manually, there completely automatically using reflection but there's issues. I like a really simple all configuration based where you have value, instance, shared-instance items that ask the parent container for its dependencies it needs. Its preference, I like that nothing can happen that isn't set and replacing a class involves 1 config file change.
Liam Murphy
Yeah, I wouldn't use Java without something Spring or Vertex anymore. Doin't use Guice though, that shit is dead.
Jace Campbell
Just read from the horse's mouth:
martinfowler.com
Christopher Reyes
i'm not taking programming advice from a horse
Oliver Brooks
What the fuck is wrong with horses? Horses are kind and empathetic creatures. I bet you like dogs you fucking double nigger, fuck dogs. They're flea ridden stupid animals that would eat your stupid fat dead corpse as soon as they see an opportunity. Horses are man's true best friend, they don't complain and they're happy to pull heavy loads for us. Fuck you you fucking double nigger faggot dog lover, if you keep talking shit about horses I will fucking stomp you out with my hooves. And don't think I won't, have you ever seen a horse? They're creatures of pure mass and muscle, you think your tiny human harms can do shit to horses? WRONG, horses could fucking end your life within a second kiddo, do you know that we measure power of cars using a metric based on the POWER of HORSES (horsepower). I'm not a horse or anything but I'm not a fucking retard who would badmouth a horse, go fucking neck yourself. Horses are wonder and intelligent creature who just wanna eat grass and be friends.
David Peterson
I love java and the technology behind it
but god you fucking oop factory making dumb faggots with 20 interface with "dependency injection" and dumb fucking oop shit ruin the language
fuck you fuck you fFUCKCKXJA
Robert Wright
Jason Hughes
Why do OOP brainlets need buzzwords for common sense? Convince me that OOP is anything more than codifying freshman-tier design principles for consumption subhuman enterpriseAdapterPattern.SingletonIQ.faggots().
Jace Watson
That is so fucking beyond retarded and unsanitary. Dennis Ritchie just killed himself in the grave.
Adrian Hill
[spoiler] [/spoiler] [spoiler] [/spoiler] [spoiler] [/spoiler]
Tyler Lopez
>Program less
>Java
It's like enterprise fags are trained to not think.
Angel Bailey
nigger
Matthew Johnson
We wouldn't need any of this is everyone was smart and mindful. It's an attempt to gate bad behaviors on a scale. Even if you are intelligent mistakes will happen or you'll slip up at some point, this is especially true as your organization becomes larger and development becomes more decentralized.
Tyler Campbell
I don't do drugs, thanks.
Christopher Roberts
suck my pee pee
Jaxon Brooks
doublenigger
Juan Barnes
triple nigger
Blake Lopez
Jonathan Hughes
you're the one keeping this reply chain going
Asher Thomas
Show me how you can scan for an annotation in a package without a reflection framework
You cant