Hacker News new | past | comments | ask | show | jobs | submit | abhis3798's comments login

This is a good rule of thumb, but what would be a good response to have interfaces because, "what if a new scenario comes up in the future"?

The scenario NEVER comes up in the future as it was originally expected. You'll end up having to remove and refactor a lot of code. Abstractions are useful only used sparingly and when they don't account for handling something that doesn't even exist yet.

When doing the initial design start in the middle of the complexity to abstraction budget. If you have 100 “units of complexity” (lines of code, conditions, states, classes, use cases, whatever) try to find 10 subdivisions of 10 units each. Rarely, you’ll have a one-off. Sometimes, you’ll end up with more than 20 in a group. Mostly, you should have 5-20 groups of 5-20 units.

If you start there, you have room for your abstraction to bend before it becomes too brittle and you need to refactor.

Almost never is an interface worth it for 1 implementation, sometimes for 3, often for 5-20, sometimes for >20.

The trick is recognizing both a “unit of complexity” and how many “units” a given abstraction covers. And, of course, different units might be in tension and you have to make a judgement call. It’s not a silver bullet. Just a useful (for me at least) framing for thinking about how to manage complexity.


Even one use case may be enough e.g., if one class accepts another then a protocol (using Python parlance) SupportsSomething could be used to decouple two classes, to carve out the exact boundary. The protocol may be used for creating a test double (a fake) too.

If you own the code base, refactor. It's true that, if you're offering a stable interface to users whose code you can't edit, you need to plan carefully for backward compatibility.

"We'll extract interfaces as and when we need them - and when we know what the requirements are we'll be more able to design interfaces that fit them. Extracting them now is premature, unless we really don't have any other feature work to be doing?"

Extend this and you get benefits of capitalism vs downsides of unchecked capitalism.


Really happy to see this as a history buff and someone who hails from the backyard of the erstwhile Vijayanagara empire.


Oh ho! Hello hello. Where are you from? I come from Kamalapura, near the Lotus Mahal.


So the general belief is that "black money" is always stashed as hard cash. Specifically in higher denominations of 500 and 1000 ruppees. To uphold the poll promise of putting an end to black money, Modi came up with this plan to ban these denominations.

It was utter chaos when this happened. People literally queued up at ATMs for hours and most ATMs would be out of cash. PayTM, now an household name in India for online wallet, turned out to be the biggest beneficiary from the whole fiasco. Black money however lives on.


Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: