Live data from Hacker News

Prefer duplication over the wrong abstraction (2016)

sandimetz.com

341–350 of 375 posts

Re: Prefer duplication over the wrong abstraction (2016)

#341
post #42

Nobody wants to listen. Nobody. In 90% of the companies there are some so called senior devs that get ecstatic when they create a new abstraction. Overengineering, abstractions and premature optimisation are the 3 worst plagues of engineering. At the same time I’m happy they exist because it means we’ll always have a job.

Remember, everyone else's job is simple and pointless, only your job is difficult and important. Therefore only your job could possibly need abstractions. Everyone else is just over engineering.

Only MY code is allowed to be clever.

Re: Prefer duplication over the wrong abstraction (2016)

#342
post #55

I believe that "single source of truth" is a principle that should always be followed. If there's duplicated code where it'd be a bug if they diverge, then you should refactor. It creates a long-distance coupling in your code that may be invisible to future developers until a bug emerges. But with that in mind, I mostly agree with the article: if it's not a violation of "single source of truth", then abstractions are…

I have always believed what the article more or less states. But you have to remember, the primary and maybe only source of duplication in software is situational dependency (the other word escapes me for this). If there was a universal tree of software functions that could be accessed over a network no function would ever be duplicated and every function would be reused from a central tree. When you put 2+2 inside a…

> universal network invocable function tree

https://www.wikifunctions.org/ btw

Re: Prefer duplication over the wrong abstraction (2016)

#343
post #76

Two talks come to mind here: Mike Acton's Data-Oriented Design and C++ [1] and Brian Cantrill's The Complexity of Simplicity [2]. Mike's talk argues that code solutions need not be modelled on the real world, and that different data creates different problems, which need different solutions. I can't do the talk justice, but it's had a big impact on me. Brian's talk is about abstraction generally, and how it's difficu…

> Mike's talk argues that code solutions need not be modelled on the real world, and that different data creates different problems, which need different solutions. I've always found it odd when even fairly smart engineers sometimes prioritize real-world metaphors over the actual needs of the codebase. Years ago when I was only a few years out of school, I was implementing a connection pool in Rust, and the most reas…

Didn't we all spend years and years learning that OOP is about writing "class Car extends Vehicle"?

Re: Prefer duplication over the wrong abstraction (2016)

#344
post #202

Earlier quoted context omitted.

Of course, in theory this is true. In practice people tend to avoid ANY duplication no matter what. Especially junior developers, as if duplication would be the root of all evil.

This is something I've seen repeated time and time again as a criticism of (misused) abstraction and DRY, yet I've never seen ONCE -- and this is not hyperbole, I mean it literally -- a junior making an abstraction with any thought to reuse, generalizing anything, or caring about not repeating code. Most juniors I've worked with are content to just churn new code without paying attention to the codebase at all. This…

Win32 checkboxes, radiobuttons and groupboxes are buttons with extra bitflags. What's the common denominator? They all have text and do something when you click on them. Except groupboxes, which don't do something when you click on them.

Re: Prefer duplication over the wrong abstraction (2016)

#345
post #225

Similarly, I've seen some developers who seem to think that any inline string or numeric constant is evil. In one PR, I saw: HTTPS_SCHEME = 'https' DOMAIN = 'www.example.com' url = HTTPS_SCHEME + '://' + DOMAIN I don't understand what they think this is buying, other than just cargo culting "don't embed constants." And of course, the constant definitions were at the top of the file and the url building code was hundr…

That particular example doesn't quite fit, but I've certainly seen cases where otherwise perfectly ordinary fixed strings needed to be broken up to meet linting rules.

If your linter is making you do something stupid fire your linter or learn how to exempt a certain line from a certain rule.

Re: Prefer duplication over the wrong abstraction (2016)

#346

Earlier quoted context omitted.

This is somewhat related: I mention this a lot, but in researching Data-Oriented Design (what Mike was talking about), I came across Richard Fabian's DoD book [1] which talks a lot about database normalization and the like. I found that odd, because the low-level high-performance game code he was talking about certainly wasn't going to marshal data into a DB to run SQL queries on it. It turns out the relational model…

> My big issue is that doing DB-like operations is hellish in most programming languages, and if you really want to try and marshal your data into a real DB (say, SQLite or DuckDB via a library), then you have a big messy translation layer where you're trying to match things to SQL types and you have giant SQL strings everywhere. Have heard of the JOOQ library for Java? It is a godsend because you can write guarantee…

I read about it just a few days ago! I don't use Java, either, but it looked awesome. Right now I'm using Rust, which feels limited in this capacity outside of ORMs.

Re: Prefer duplication over the wrong abstraction (2016)

#347
post #76

Earlier quoted context omitted.

> Mike's talk argues that code solutions need not be modelled on the real world, and that different data creates different problems, which need different solutions. I've always found it odd when even fairly smart engineers sometimes prioritize real-world metaphors over the actual needs of the codebase. Years ago when I was only a few years out of school, I was implementing a connection pool in Rust, and the most reas…

Didn't we all spend years and years learning that OOP is about writing "class Car extends Vehicle"?

Honestly since college I've mostly learned that inheritance is more trouble than it's worth

Re: Prefer duplication over the wrong abstraction (2016)

#348
post #76

Earlier quoted context omitted.

> Mike's talk argues that code solutions need not be modelled on the real world, and that different data creates different problems, which need different solutions. I've always found it odd when even fairly smart engineers sometimes prioritize real-world metaphors over the actual needs of the codebase. Years ago when I was only a few years out of school, I was implementing a connection pool in Rust, and the most reas…

Didn't we all spend years and years learning that OOP is about writing "class Car extends Vehicle"?

That's one of the things Mike was pushing back on (in the context of C++ / game dev; there's a good example ~20 min in). In case you haven't seen it, Casey Muratori's The Big OOPs: Anatomy of a Thirty-five-year Mistake digs into the different ideas and viewpoints surrounding OOP and how it coalesced into a dogma:

https://www.youtube.com/watch?v=wo84LFzx5nI

Re: Prefer duplication over the wrong abstraction (2016)

#349

Two talks come to mind here: Mike Acton's Data-Oriented Design and C++ [1] and Brian Cantrill's The Complexity of Simplicity [2]. Mike's talk argues that code solutions need not be modelled on the real world, and that different data creates different problems, which need different solutions. I can't do the talk justice, but it's had a big impact on me. Brian's talk is about abstraction generally, and how it's difficu…

See also:

Data-Oriented Programming: Reduce software complexity

by Yehonathan Sharvit

https://www.manning.com/books/data-oriented-programming

and from SICP:

2.4.3 Data-Directed Programming and Additivity

https://sarabander.github.io/sicp/html/2_002e4.xhtml#g_t2_00...

Post reply on HN