Is abstraction overrated in programming? Chess, interviews and OOP
1–10 of 149 posts
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#2All 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
#3Programming IS abstraction.
In fact, that's pretty much ALL programming is: using, defining, and implementing abstractions.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#4Re: Is abstraction overrated in programming? Chess, interviews and OOP
#5Oh Dear Lord. Programming IS abstraction. In fact, that's pretty much ALL programming is: using, defining, and implementing abstractions.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#6A 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
#7Re: Is abstraction overrated in programming? Chess, interviews and OOP
#8So 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
#9Oh Dear Lord. Programming IS abstraction. In fact, that's pretty much ALL programming is: using, defining, and implementing abstractions.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#10I 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…
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.