Live data from Hacker News

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

news.ycombinator.com

81–90 of 946 posts

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

#81
post #33

Earlier quoted context omitted.

> 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.

What I find troubling about that page is that it does not qualify up front whether the dependencies are:

A. Also depended upon by other, coequal unrelated classes, possibly maintained by others, OR

B. Depended upon only by a single class (of higher functionality)

Situation A is sometimes called a portability interface; B might be called an internal structuring interface.

The difference has crucial implications for social power relationships between the human developers and users involved.

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

#82
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…

Another solution is to eliminate classes and only use structs or similar plain objects. Makes mocking and testing functions much easier. At this point I see no reason for OOP whatsoever and consider it a big mistake.

This seems totally orthogonal to me.

Using a totally non-OOP functional style, you can either instantiate state within a function or pass it in from the calling context, which is the same trade-off that dependency injection targets.

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

#83
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…

Another solution is to eliminate classes and only use structs or similar plain objects. Makes mocking and testing functions much easier. At this point I see no reason for OOP whatsoever and consider it a big mistake.

Getting rid of data abstraction and encapsulation is throwing the baby with the bath water.

The abstract concept of OOP (messages between complex objects, as defined by Alan Kay) is an attempt at mimicking biological systems. Most modern languages implement data abstraction, but call it OOP, where they encapsulate some functionality with the data it operates on. Really helped with varying data formats in the AirForce in the 60s, apparently. There isn't anything wrong with this abstract concept either - it's a way of structuring a solution, with trade-offs.

Support for unit testing and mocking has little to do with OOP, and everything to do with the underling platform. Both C++ and Java, for example, do not have a special runtime mode where arbitrary replacement of code or data could occur. This is necessary for mocking functionality that is considered implementation detail and hidden by design. The hidden part is great for production code, not great for testing.

For example, if an object in java has a field like 'private final HttpClient client = new CurlBasedHttpClient();' this code is essentially untestable because there is no way in Java to tell the JVM "during testing, when this class instantiates an HttpClient, use my MockHttpClient".

Kotlin fixed some of that with MockK, which can mock the constructor of a Kotlin object, and you can return your mock implementation when the constructor is invoked.

Clearly, it's a platform issue. There could be a world where you could replace any object in the stdlib or any method or field with a mock version. JavaScript is much more flexible in that regard, which is why unit testing js code is much easier.

The root of it all stems from the fact that unit tests need to change some implementation details of the world around the object, but production code should not be able to, in order to get all the benefits of encapsulation.

If you get rid of modern OOP, you are swinging the pendulum in the opposite direction, where your tests are easy to write on any platform, because everything is open and easily accessible, but your code will suffer from issues that creep up when structures are open and easily accessible, such as increased coupling and reduced cohesion.

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

#84
post #75

blockchains as a single source of truth always seemed like a shitty expensive database for 7+ years

What made you believe that they are not a "shitty expensive database" after all?

in the ecosystem of a single blockchain, they are the single source of truth that is an open api-like thing that no company can control

therefore it’s safer to build then on twitter, facebook, apple, etc.

the entire ecosystem may be a fraud, but if it is not then it’s incredibly enduring. i have more faith that i can get what the balance of an account is in 10 years from ethereum than i do from my banks api staying stable or open.

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

#85
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…

Seven years into my career I'm increasingly convinced that the emperor has no clothes with respect to unit tests that are just transcripts of the code under test with "mock.EXPECT()" prepended to everything - 95% by volume of the unit test code I've ever read, written, or maintained.

Yep, I think mocks are mostly a smell. The "functional core" of a module should be entirely or almost entirely unit testable with (possibly fake) dependencies passed in. The glue code ("imperative shell") should be tested at a higher level - "integration" or "end to end" or whatever you want to call it - which looks at the externally observable effects of running the code (database changes or API responses or whatever) rather than the details of its execution.

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

#86

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 imp…

This summer I read "On Writing Well" by William Zissner which was an eye opener for me. I'm far from an expert in writing clear texts, but I am definitely noticing more text which are just... big balls of blurb that don't actually say anything. All because of that book.

It sounds dumb, but this year it clicked for me how big of a difference a poorly written text compares to a well written text.

Hope your training pays off, itsmemattchung!

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

#87
post #22

Earlier quoted context omitted.

Very intriguing! Any links you can share on this theory? A quick Google search gave me an overview, but I don’t see how this is particularly useful for second language acquisition.

The big take-away is that explicit study of grammar rules, and even vocabulary to some extent, is kind of a waste of time. They encode information in a format and region of the brain that generally isn't accessible to the areas that are used in fluent communication. The way our brains have evolved to build up a functional language model is by observing lots and lots (and lots) of examples of the language being used f…

Given you eureka moment, besides what you didn't do (as you outlined), what did you do to increase your second language real world examples with feedback? Did you try immersion?

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

#89
post #8

The autonomic nervous system and the adrenal cortex. Homeostasis is taught as a textbook fact, the body reverting to a baseline over time. What’s not taught is how much the impacts of daily life events drive a continuous stress response. Fight or flight is not just a reaction to deadly threats. It’s active every moment of every day to ensure survival. The adrenal cortex is always active, to traffic, your boss and col…

Any books you could recommend? I presume you already know of this book: The Body Keeps the Score: Brain, Mind, and Body in the Healing of Trauma by Bessel van der Kolk.

That’s a great one. I’ve been looking for something that links the physiology with knowledge work and life demands, but I haven’t found it yet.

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

#90
One of the big aha moments which clicked for me only fairly recently was staring at some physics equations my own internalized realization that light doesn't experience time and then I had to tell everyone haha - but that one eureka moment unlocked a whole lot of understanding and certainly a lot more questions. This of course was after all the schooling and physics where it somehow sailed over my head the whole time.
Post reply on HN