What is it? Dependency Injection is a design pattern whereby an object/module’s dependencies are provided to it. It is one of several techniques for implementing Inversion of Control.
So rather than:
func NewClient() *Client { return &Client{ Service: service.NewService(), } } You would have:
func NewClient(service *service.Service) *Client { return &Client{ Service: service, } } Why tho?? If you wanted to write a test for the Client first example above, you wouldn’t be able to mock it’s Service.
I often have need to build layout’s that vary depending on the content put in them. I can’t always count on that content being the same (cough CMSs cough). It’s just one of those things you have to do.
One thing I’m having to do a lot though, is making the body of a page take up a certain amount of space so that the footer doesn’t look weird. In the past I’ve used JavaScript to make the footer take up the remaining space on the page if the content didn’t take up enough.
Call Calls a function, with the specified arguments passed in
The first argument becomes this, the rest are passed in as regular arguments. Using call allows you to maintain the scope of this accross methods. It works like this:
Here we’re using prototypical inheritance to allow us to inheirit properties from Animal in Dog and Cat. Using call allows us to invoke Animal to initialize it’s properties while maintaining the correct scope.
1. Subject Line The Subject Line is the first line of your commit message. Often the subject alone is enough, but if it’s not and you need a body be sure to separate the subject and body with a blank line.
First line of a commit message Often the only part you’ll need Separated from the body by a blank line Soft limit of 50 characters, hard limit of 69 Github’s interface truncates the subject line at 69 characters Capitalize!
Adding named properties to arrays in JavaScript can be handy in a few different cases. For instance:
You need a nice formatted title / description for a data set. Rather than having multiple objects you can use named properties and get away with only using one. You want to add some functions to an array for whatever reason Lots of other reasons that I can’t think of right now! Basically, this just buys you a nice way to encapsulate all the data you might need, without having to use an object with a nested array, or multiple objects.
I’m at Angle Brackets. I’ve decided that I wanted to try taking all my notes in vim. I LOVE using vim. It’s a really awesome, powerful, and extendable command-line editor. I enjoy that it’s really distraction free. Being distracted is something that I struggle with so I really look for ways to stay focused.
I write in Markdown as well. It’s a great way to get a simple, clean, well formatted plain text document that can be processed and produce HTML.