Live data from Hacker News

Ask HN: Concepts that clicked only years after you first encountered them?

news.ycombinator.com

31–40 of 946 posts

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#31
The power of an outline when writing.

Over the past few years, I've been teaching myself how to write better. I'm not talking about elementary syntax or grammar. I'm not talking about writing the traditional, American English five paragraph essay. I'm talking about writing longer pieces of prose, articles or blog posts or short chapters with word counts ranging anywhere between 1500-3000 words. On this journey of improving the craft, I realized that one of my biggest struggles was writing cohesively. Although I've been able to get lots of words on (digital) paper, eventually I'd get lost in my own web of thoughts, the article itself totally incoherent, no structure, no organization.

Constructing outlines and reverse outlines[0] has helped me tremendously. It's not easy ... but the concept itself is finally — years later — starting to click.

[0] - https://explorationsofstyle.com/2011/02/09/reverse-outlines/

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#32
post #2

Unit testing and using dependency injection to write test-able code. I'm not sure if it was years, but it wasn't immediate. I just didn't understand why dependency injection was good at first, and not just someone's weird personal code style choice. I thought it was just people being "Enterprisey" which I'd encountered many times over the years. Once I committed to unit testing, I realized how necessary it is. Unfort…

> dependency injection The term is unfamiliar to me -- is it related to "fault injection"?

No it is a design pattern to structure code. It is also known as the hollywood principle (don't call us, we call you). Meaning that dependencies of a class are provided from the outside, the class itself doesn't know how to create instances of dependencies, just relys on the dependency container (also named inversion of control)...

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#33
post #2

Unit testing and using dependency injection to write test-able code. I'm not sure if it was years, but it wasn't immediate. I just didn't understand why dependency injection was good at first, and not just someone's weird personal code style choice. I thought it was just people being "Enterprisey" which I'd encountered many times over the years. Once I committed to unit testing, I realized how necessary it is. Unfort…

> dependency injection The term is unfamiliar to me -- is it related to "fault injection"?

It is a pattern where you inject the dependencies of a class into it rather than create the instances of the dependencies within the class. for more info --> https://en.wikipedia.org/wiki/Dependency_injection

it makes the code cleaner and testable.

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#34
post #2

Unit testing and using dependency injection to write test-able code. I'm not sure if it was years, but it wasn't immediate. I just didn't understand why dependency injection was good at first, and not just someone's weird personal code style choice. I thought it was just people being "Enterprisey" which I'd encountered many times over the years. Once I committed to unit testing, I realized how necessary it is. Unfort…

> dependency injection The term is unfamiliar to me -- is it related to "fault injection"?

Let's say Class A depends on Class B. A lot of people have the instincts to have A construct B so that the callers of A don't have to worry about it.

But this makes testing A in isolation difficult. When testing A, you want to mock out B with an instance the test can manipulate.

So we want A to not create B, instead we want B to be "injected" into A. The general strategy of having B passed into A is called dependcy injection.

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#35
post #2

Unit testing and using dependency injection to write test-able code. I'm not sure if it was years, but it wasn't immediate. I just didn't understand why dependency injection was good at first, and not just someone's weird personal code style choice. I thought it was just people being "Enterprisey" which I'd encountered many times over the years. Once I committed to unit testing, I realized how necessary it is. Unfort…

> dependency injection The term is unfamiliar to me -- is it related to "fault injection"?

The idea of DI is that you creat resources indirectly, and don't call the named constructor in your code. You then use interface types to interact with the resource.

This way, your code isn't bound to a specific implementation.

Some DI frameworks even go so far and define all resources in a config file. This way you can switch out the implementation without a recompilation.

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#36
post #2

Unit testing and using dependency injection to write test-able code. I'm not sure if it was years, but it wasn't immediate. I just didn't understand why dependency injection was good at first, and not just someone's weird personal code style choice. I thought it was just people being "Enterprisey" which I'd encountered many times over the years. Once I committed to unit testing, I realized how necessary it is. Unfort…

> dependency injection The term is unfamiliar to me -- is it related to "fault injection"?

[deleted]

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#38
One of the biggest realizations recently for me was realizing that a nearly all of software development is basically about turning a slow, manual process into a faster, automated process. Modern CI/CD stems from a bunch of shell commands that somebody wrote and manually executed to test an app and upload it to a server. Modern automated software testing stems from humans writing small test apps and running them to confirm correct behavior. Many modern development practices stem from allowing small test apps to be written easier and faster. It's all just a giant manual process-to-automated process time-saving machine.

Re: Ask HN: Concepts that clicked only years after you first encountered them?

#39
post #18
post #2

Unit testing and using dependency injection to write test-able code. I'm not sure if it was years, but it wasn't immediate. I just didn't understand why dependency injection was good at first, and not just someone's weird personal code style choice. I thought it was just people being "Enterprisey" which I'd encountered many times over the years. Once I committed to unit testing, I realized how necessary it is. Unfort…

Can you explain the concept? I feel I didn't grok it fully

I found this explanation very helpful: https://hakibenita.com/python-dependency-injection (if you program in Python)
Post reply on HN