Live data from Hacker News

Is abstraction overrated in programming? Chess, interviews and OOP

quora.com

1–10 of 149 posts

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#2
Reminds me of an old contest - the 8 Queens problem, posed by Byte Magazine in the '80s as a programming contest.

All the solutions presented started by declaring an 8X8 board, with a 1 or 0 in each cell to represent a queen. Then there was some two-dimensional iteration over the board, testing if any queen was on the same row, column or diagonal as any other.

I'd dismissed that solution as inefficient from the start. Since only one queen can be in each column, I represented the board as an 8-element array with each element containing the row number of the queen in that column.

My 2nd insight was, only one queen can be in each row, so the elements of the board array were simply the numbers 1..8. The search consisted of permuting the digits, then testing for diagonals e.g. test pairs to verify abs(difference) != abs(i1-i2). That is, their row numbers were not the same as the difference between their column indexes.

Finally, when permuting, you could test the elements as you went and trim the permutation tree drastically if you found a failure. No sense permuting the right-most elements of the array if there's already a diagonal conflict in the digits placed so far.

The whole thing ran in trivial time. The contest winners ran in hours or days (this was all in BASIC on <1Mhz processors back then). Made me wish I'd actually entered the contest. But I didn't bother, I guessed many people would have found the same solution.

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#4
Understanding the problem > any abstraction you pick without understanding the problem first. In this case chess was a terrible choice for an interview. In chess the biggest issue is tree size. If you don't start there then no abstraction will ever save you.

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#6
I have no idea what abstraction actually is. It seems to me it's never abstraction unless it leads to complicated designs for the simplest problems. I've been accused of hating abstraction because I wrote in C instead and programmed out my own concepts -- instead of just using a ready-made framework with ill-fitting ones (Qt in that case).

A much better term than abstraction to me is "semantic compression" (got that from Casey Muratori of Handmade Hero). This basically means factoring out common bits with the goal to express the solution with the least amount of repetition (while of course taking care not to factor out parts which are only coincidentally common. I figure that's the "semantic" part).

To do semantic compression you need abstraction, but not pointless abstraction -- just the right amount.

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#7
As an example of a good abstraction regarding chess, a deep learning algorithm that wasn't hand tuned specifically to chess just beat the best computer chess player that had a hand tuned algorithm (in which case the neural network representation of the board performed better than bit representation)

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#8
The Bitboard is very abstract. The interface it instantiates will likely not let leak it’s concise internal representation and will discuss the operations on the game state at a domain level. This is abstraction.

So this is a failure of OO abstraction. Why? OO abstraction is really complex and makes many forced moves that provide little value here. Inheritance and a focus on “nouns” makes idiomatic code highly specialized to certain domain models. Unfortunately, these are rarely useful.

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#9
post #3

Oh Dear Lord. Programming IS abstraction. In fact, that's pretty much ALL programming is: using, defining, and implementing abstractions.

A definition which doesn't differentiate is a definition which provides no information. If your terminology is broad enough to encompass everything, it's also too broad to tell you anything.

Re: Is abstraction overrated in programming? Chess, interviews and OOP

#10

I have no idea what abstraction actually is. It seems to me it's never abstraction unless it leads to complicated designs for the simplest problems. I've been accused of hating abstraction because I wrote in C instead and programmed out my own concepts -- instead of just using a ready-made framework with ill-fitting ones (Qt in that case). A much better term than abstraction to me is "semantic compression" (got that…

Abstraction, to me, is not about reducing lines of code but reducing cognitive load by hiding complexity. I don't need to know what kind of list, or how the list is implemented, I just need to know it's a list of some sort and has the usual list interface.

For example, I recently needed to randomly reorder a collection of objects, weighting some of them more heavily than others such that 'heavier' objects are more likely to come first. My first implementation was a mess, and was hard to test. So I created an abstract data structure that allowed inserts with weights and polls for a random value, applying the weighting. My business logic could use that abstract thing presuming it worked. The tricky part was hidden, and the code was cleaner.

In the case of the article, the abstraction the interviewer wants doesn't actually make the code clearer. It's just looking for checking off check boxes that the candidate wrote the word 'class' and jumped through the hoops the way the interviewer expected.

Post reply on HN