Live data from Hacker News

Ask HN: What is the most enlightening concept that changed how you program?

news.ycombinator.com

31–33 of 33 posts

Re: Ask HN: What is the most enlightening concept that changed how you program?

#31

Earlier quoted context omitted.

Not op, but let me rephrase it: leaky abstractions create more trouble than is worth it. If your abstraction does not fit the problem neatly do not abstract it.

Leaky abstractions are bad abstractions. So what you are basically saying is “don’t implement bad abstractions”. Ehhhh right. I think we can all agree to not implement bad things. There is no insight or enlightenment there IMHO.

As I was writing my comment I was picturing this answer, and Socrates strategy for discussion, making others define and define ad infinitum. Fair enough. Quoting you:

> Having said that, a lack of architectural abstractions leads to badly designed code with a WTF count reaching the heavens.

> a lack of architectural abstractions leads to spaghetti code.

> domain logic directly relying on a specific UI framework?

If we are pedantic: lack of architectural abstractions, spaghetti code, and domain logic tied to an UI can also be interpreted as simply bad, so no information in either of our posts :)

Of course, I am joking. Saying that I think leaky abstractions are bad, or you saying that no abstractions are bad is new information (it reduces uncertainty). It tells us that we think that x is bad.

We can agree that bad abstractions are bad. In this thread, abstracting to early, or having leaky abstractions or not having any abstractions are just 3 positions on the topic of what a bad abstraction is.

I bet we could much easier agree with a specific example. In my experience all "big principle" discussions improve when we focus on a specific example. Otherwise people are thinking of different scenarios.

In any case, I can think of scenarios where each of those 3 positions is right, so I do not really disagree with any of them.

Re: Ask HN: What is the most enlightening concept that changed how you program?

#32

Avoid deep nesting by testing error case first and exiting/returning immediately. Instead of : If foo then bar Else baz Endif Now I write: If foo then bar return Endif baz Exit early makes the code easier to read and understand

IMO the example you provided is an anti-pattern. There are better ways to avoid deeply nested code, but it depends on the programming language. I try to make each method/function to have a single entry and a single exit. Cond, case, pattern maching in function heads, decision tables, and syntactic sugar in some PLs, allow you to flatten the nested code / branchinbg / conditionals.

Maybe. Or maybe it is not obvious with a small example. Not sure about the anti-pattern, but I'm sure an anti-conventional coder ;-)

Re: Ask HN: What is the most enlightening concept that changed how you program?

#33

Earlier quoted context omitted.

Leaky abstractions are bad abstractions. So what you are basically saying is “don’t implement bad abstractions”. Ehhhh right. I think we can all agree to not implement bad things. There is no insight or enlightenment there IMHO.

As I was writing my comment I was picturing this answer, and Socrates strategy for discussion, making others define and define ad infinitum. Fair enough. Quoting you: > Having said that, a lack of architectural abstractions leads to badly designed code with a WTF count reaching the heavens. > a lack of architectural abstractions leads to spaghetti code. > domain logic directly relying on a specific UI framework? If w…

Yeah I think we pretty much agree.

An example where a lack of abstractions is always bad IMHO is when the UI is directly depending on a specific database implementation. For example, dialog callbacks directly using the Oracle dialect of SQL to do business logic. I see that all the time in the wild and it makes the code super hard to improve, test, and maintain.

Another example is the domain logic directly depending on an external framework or database. A simple abstraction that reverts the dependency would make the code so much more maintainable and flexible.

Those examples are but two of the many I see in the wild all the time. Which makes me believe that often, in practice, the lack of architectural abstractions is a big problem.

Post reply on HN