DEV Community

Clean Code Studio
Clean Code Studio

Posted on • Updated on

Dependency Injection (Simplified)

Twitter Follow

Your palms are sweaty
Knees weak, arms are heavy
There's vomit on your sweater already, Dev's spaghetti

Your nervous, but on the surface you stay calm and ready,
To Drop coms.

But you're forgettin' what you coded wow. The team knows it now. Overnight architects studying no doubt, come in clutch with competent "Know How" that's balanced by curious "No, how?"


Curious "No, how?" checks competent "Know How" and vice versa. This balance is "How" good teams balance and build into great teams. Without "No, how?" and "Know how" all you're left with is "How?".


It's broken, plow, nobody's talkin' now
The clocks run out, times up, over, blaow,

Snap back to reality, ope another impracticality, dependent on irrationality, rabbiting towards dependency on hellish mentality.

Your so mad, but you won't give up that easily? No you won't have it, you know the app's not that out of it. At one point at least it hadn't been.

Your back's to the ropes, entangled code, the team starts losing hope. It don't matter, your dope, you know that, but this code's a joke. Is something fixable if truly incapable?

You feel so stagnant, you continue to grind, ope, you code another line - HOLY F

--
(Deep breaths...)

(Deep breaths...)

You ran into another dependency...

Okay...Alright. It's fine.
Let's focus up and do it right this one time.

That's when it's back to the lab again, ope you better capture that moment and capture it you only got one sh....

"HOLY MOTHER OF F, AGAIN!?!?!?!?!"

You run into ANOTHER dependency. Your about to lose it again. Your best option is to simply let emotions take over and give in.

But you got this. Let's check back into that work grind rhythm...

This opportunity comes once in a !!DEPENDENCY POPS UP!!! life
time, !!DEPENDENCY POPS UP!!! dependencies are tragically stealing hope, !!DEPENDENCY POPS UP!!! you know that, but there's code you know's crap, but that's where its at.

Your back's against the ropes, just don't react - eroded code, try to decode - won't say can't or impossible but...can't do it, won't do it, shoooouullldddnnn'ttt do it with this kinda mental mode of over load.

Try decoding the dependency ridden code anyways. You've got this. Go with the rhythm. Feel the beat? There's that vibe...

Snap back to reality ope there goes dependencies, retreat to child hood contingencies. Losing hope, you childishly start to cope, feeling like you'd rather be jobless and go broke - this app's broke. Is your time a joke?


DEPENDENCIES ARE THE DEVIL INCARNATE (BELIEVE IT, FIX IT)


Months in this environment and all but a shell of you has withered away. You're not the only one either. Your team's going through the same thing. Good ol' competent "Know how" turns into eye rolling "No......how's our environment going to use a five minute task to steal my time for the entire damn day.....again?".

"Know how" is what you want on an engineering team. Genuine "No, how?" is also what you want. Competent "Know How" and genuine "No, How?" are the foundation that builds great teams.

Annoyance when being asked to learn something new because the environment that broken kills the genuine curiosity of "No, how?" while simultaneously killing any desire to be the one in the room with competent "know how".

Day in day out annoyances drive teams into frustration.

Quality suffers.
Upper management gets involved.

Now there's too much pressure to fix an application ridden deep within dependency hell.

Great companies slowly lose engineers due to lack of interest and thus an over all lack of passion. Lack of passion combined with external pressure prevents a team's ability to build things the right way and thus make everyone's lack luster. This effects the entire company and lower's the quality of life for each team member invested into the organization as a whole.

Upper management leaves and executives begin to bail noticing this pattern far before most other individuals due simply to their experience in the industry.

Team members who have been loyal to the company for years are promoted. They may deserve the position as far as loyalty is concerned but ultimately they don't have the training nor outside experience to handle these new middle management positions. New engineers coming in notice these signs very quickly where as engineers who have been on the team for years don't necessarily see all of these warning signs.

Given new newly hired engineers in non-leadership roles aren't going to typically come in and start bossing around the team that just hired them to avoid stepping on toes, external stake holders looking in will begin to see the over all lack of competence for the entire organization.

This doesn't necessarily mean there is actually a lack of competence. Many times, newly hired engineers have the competence to implement industry best practices simply due to the fact they've worked throughout the industry and often times have moved around frequently.

When a process that should be quick and simple yet causes daily annoyance isn't addressed, we are now wasting time.

Time is the most valuable commodity we have on this planet.

Whether we realize it or not, I believe that if our time is being wasted - that we as humans intrinsically understand how soul sucking and passionless the task must really be.

The fact that our time is being invested into something that we can make more efficient but decided it isn't worth our time to do so is detrimental.

We're telling ourselves "I'm okay wasting my life source and energy on this pointlessness."

We are telling ourselves it's okay expect this limited contribution of value from ourselves. Once we give in and accept this limited amount of contributions for ourselves we unconsciously give the go ahead for everyone around us to have this same expectation of our value.

We're telling ourselves and world that this is the level of value I'm okay contributing to the world. We're telling the world that my limited amount of time and energy available in this life time is trivial and it's okay for both myself as well as you to invest my very being into trivial tasks with limited responsibility.

Taking on responsibility is what gives our lives passion and reason. I believe we have a responsibility to live life to the fullest, to become a valuable resource to ourselves as well as the world, and ultimately to remove this barrier preventing us from simplifying processes.

Simplifying processes allows us invent solutions. This investment into simplification is the only hope we have to re-claim our time, energy, and freedom.

Our time, energy, and freedom is worth everything. It should be devoted towards passion, creation, and improving lives.

Don't tell the world that our time, the only resource we'll never be able to take back, is an acceptable commodity to be wasted on trivial monotony.

By not speaking up, making a move, or taking the action to implement the change within ourselves or our physical world, we are sub-consciously externalizing the value we see within ourselves and showing the world that price tag we just put on ourselves. We, as individuals, are an invaluable resource of this planet we call earth - that resource is life itself.

Our lives are valuable. Implementing the optimal operations for a team of engineers is not only important to the success of the organization but contributes towards a better world.

We improve the lives of our immediate team members and ultimately effect the world through each one of them and their families.

Success and quality contributions to the world breed an unspoken sense of respect across a team. By removing bottle necks, investing in removing the trivial, obliterating tedious, and maliciously murdering annoyances we are conscientiously taking accountability for the lives of people who have families, dreams, and aspirations worth that investment of resources to free up their time --- then you not only become a more successful team, you also become a more invigorated, loving, respected, and respectful team.

When you see annoyance within the trivial tasks from your team members, I believe it is the responsibility of the leaders and the team members to work together and quite literally earn their freedom back from triviality as well as any repetitive task that down right dis-respects what value they as a human being are capable of bringing to the table.

Within a year, your team will add these bits of freedom up and will reallocate them towards what really matters. They feel valued. They want to make others feel valued. Everyone respects time and understands that commitment towards not wasting time on non-enjoyable, time-wasters is detrimental to success, happiness, and freedom.

Dependency Hell ruins lives, dims out previously fired up team mates, and will whither away desire & passion for life.


Back to the dependency grind work grind rhythm...

To drop .coms, but your forgettin' what you coded now,
the team learned design patterns somehow, but the code won't work out but you keep on forgettin' what you coded down, its just all broken now, but on the surface your calm and steady, to drop. You just did wow, your coding' now. No chokin' allowed.

On the surface you look calm and ready to drop .coms, but you keep on forgettin' what you depend on there, it's a dependency scare, this s***, what hell is this, everyone's starting to not care. Truth is we're losing hope, act like you dont care to cope, its a defensive mechanism kicking in, your skins feeling thin,

Pretend like you just don't care, you're not reacting, ten seconds later your pulling out your hair, truth is your dope, you have that passion, your just losing hope, it's time to get back that life fire that fills you up with satisfaction, with this bullshit it's time that we said nope.

Dependency hell, drove you towards that lack of respect for yourself, wasn't good for your health, started not to care, had that thousand mile stare. Pulled out your hair and now your bald. Family members hit you up, too sad - you never called. Your skills have declined, your sitting at the dinner table and your social skills have flat-lined, it's a night mirror, thanks to dependency hell you're reflection has that soul killing stare.

Your family life, social life, professional life, and most likely even that sex life of your suffer. You're spirit is slowing walking down the road towards a non-glorious death...and you know it. Your jokes are less funny, daily interactions are less enthusiastic, and you may even make the mistake of turning towards unhealthy coping mechanisms like the absolutely outrageous idea that you don't have value to bring or thoughts telling you you're not able to change that life you control.

You are valuable, you can change your life, and you should always remember to carry out living your life remembering both of those two facts. People will treat you the way you allow them to treat you - many times we have to show, teach, and coach people up on what is and isn't an okay way to treat us.

Don't be that person who doesn't value themselves or their time because it does matter. Live a good life. Enjoy your work.

ESCAPE DEPENDENCY HELL.

We are learning how to escape hell and set you back on the track towards happiness in your life. We are pulling you out of hell, pulling those bootstraps up, and putting some healthy responsibility and genuine passion back into your life.

The truth is, hell is empty - and all of the devils are living here. We know these devils as dependencies.

Today we take the road of holy righteousness and commit our very essence to the act of maliciously murdering these dependency devils.

We will fight for light, goodness, and harness our warrior spirit to attack these devils with unrelenting resolve.Today we make the world a better place.

We'll start with the only individual we are able to impact to the highest regard in positive and powerful ways. Ourselves.

You as an individual and myself as an individual will focus on bettering the world around us by being the individual in our own worlds who makes our world a better place.

Period.


Discovering Who We Are As Individuals


Understanding a team is much like discovering who you are yourself as an individual. In my experience, understanding human's is more about eliminating what is not meant to be than it is to understand what is meant to be. elimination of what isn't than it is about understanding what is. Life advice and team building advice go hand in hand - at the end of the day any team, business, organization, government, or country is made up of people. Truly understanding yourself or any other individual or group of individuals is hard. It's much easier to focus on who you are not and leave space for what is to naturally fall into place


Knowing who we are is hard. It's hard. We're always changing, in motion, in constant approach to our destination, perpetually in motion, and almost never intending to head towards where we end up anyhow.

Instead of asking WHO AM I why not simply ask WHO AM I NOT. What is it that I don't do. What are those things that aren't good for you, those things that...you know you just really shouldn't do. That bar where you always wake up with the worst hang over the day after. Those friends that are fun...but you know they really aren't the kinda people you should be hanging out with. Or those salty and sugary snacks that taste so goood going down but make you feel like trash later on.

By focusing on WHO WE ARE NOT we leave space to naturally, organically, and almost even innocently fall into who we are. We leave space for those things, people, places, and choices that fill us up, light your own fire, turn you on in this experience of life we all share and inevitably begin to find out what truly brings us joy and fulfillment in this life.

Knowing who we are is hard. Focus on who you are not. Through process of elimination, naturally, we create space in our lives for those things, people, places, and passions that are truly the make up of what we want this life to be. Process of elimination.


Alright, let's take part in some self-improvement via learning and simplify some dependency injection and dependency inversion design patterns!


Dependency Injection, now that's something. I mean hell, what's a dependency anyways?

Or...do we know what a dependency is already and the better question is to ask what a dependency is NOT?

Isn't a dependency a class? Or maybe that classes methods? What about the variables we pass into that method for that class?

What if our class needs two dependencies to be created? What if those two dependencies are classes themselves?

What if the dependencies of our class have dependencies of their own that need dependencies injected which just so happen to also may or may not be self-dependent and require additional dependencies for those dependencies....

WHEN DOES THE DEPENDENCY MADNESS END!?!?

The truth is, as engineers we can define just about everything as a dependency. A variable, a conditional, an instance, function, and even the runtime. Most things in and outside of software are non-pure entities that depend on those things while being depended on by those other things.

So how do we manage the fact that things rely on other things? That to create something, we may need to pass dependencies into it's constructor for it to work properly.

The answer?

Dependency Injection
We wire up some a design that injects the dependencies for us. More over, we implement dependency inversion, one of the only design principles that inverts a software application's dependency tree from infinitely branching dependencies out throughout the life cycle of a request.

Confused yet?

No worries, in this Clean Code Studio screen cast we visually simplify what a dependency is, how we inject dependencies, what differentiates dependency injection from dependency inversion, and finally go out into the wild to tinker with Laravel's service container - a component that utilizes the dependency inversion principle to implement dependency injection and save us from dependency hell.

Let's dive in!

Dependency Injection
Zak Horton of Clean Code Studio looking up at Floating Dependency Injection Words with interest as they fly on to the screen.

PHP Design Patterns

Top comments (3)

Collapse
 
johnt_f807e8f581 profile image
JohnT

Bro, you’re a hell of a writer. Mixing some life advice into software tutorials is a new one but a lot of it hit home. Mad Respect.

Collapse
 
cleancodestudio profile image
Clean Code Studio

Thanks John! Appreciate you

Collapse
 
cleancodestudio profile image
Clean Code Studio